diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-12-20 15:33:01 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-12-20 15:33:01 +0100 |
commit | ceb59ee0739546368135b0d86a69b17c92bfbccf (patch) | |
tree | 863b70e281f8aa833d2a4a72a61f25113dd9b8e3 | |
parent | separated handlebars init (diff) | |
download | pyload-ceb59ee0739546368135b0d86a69b17c92bfbccf.tar.xz |
added models and collections for progress
-rw-r--r-- | module/Api.py | 25 | ||||
-rw-r--r-- | module/FileManager.py | 9 | ||||
-rw-r--r-- | module/remote/pyload.thrift | 39 | ||||
-rw-r--r-- | module/remote/ttypes.py | 21 | ||||
-rw-r--r-- | module/remote/ttypes_debug.py | 8 | ||||
-rw-r--r-- | module/web/static/js/collections/ProgressList.js | 17 | ||||
-rw-r--r-- | module/web/static/js/models/Progress.js | 35 | ||||
-rw-r--r-- | module/web/static/js/models/ServerStatus.js | 20 |
8 files changed, 122 insertions, 52 deletions
diff --git a/module/Api.py b/module/Api.py index 8422a10a0..d1ccf43c0 100644 --- a/module/Api.py +++ b/module/Api.py @@ -177,14 +177,13 @@ class Api(Iface): # TODO @RequirePerm(Permission.All) - def statusServer(self): + def getServerStatus(self): """Some general information about the current status of pyLoad. :return: `ServerStatus` """ - serverStatus = ServerStatus(self.core.threadManager.pause, len(self.core.threadManager.processingIds()), - self.core.files.getQueueCount(), self.core.files.getFileCount(), 0, - not self.core.threadManager.pause and self.isTimeDownload(), + serverStatus = ServerStatus(self.core.files.getQueueCount(), self.core.files.getFileCount(), 0, + not self.core.threadManager.pause and self.isTimeDownload(), self.core.threadManager.pause, self.core.config['reconnect']['activated'] and self.isTimeReconnect()) for pyfile in self.core.threadManager.getActiveDownloads(): @@ -192,6 +191,14 @@ class Api(Iface): return serverStatus + @RequirePerm(Permission.All) + def getProgressInfo(self): + """ Status of all currently running tasks + + :return: list of `ProgressInfo` + """ + pass + def pauseServer(self): """Pause server: It won't start any new downloads, but nothing gets aborted.""" self.core.threadManager.pause = True @@ -221,7 +228,7 @@ class Api(Iface): return free_space(self.core.config["general"]["download_folder"]) - def kill(self): + def stop(self): """Clean way to quit pyLoad""" self.core.do_kill = True @@ -266,14 +273,6 @@ class Api(Iface): end = self.core.config['reconnect']['endTime'].split(":") return compare_time(start, end) and self.core.config["reconnect"]["activated"] - @RequirePerm(Permission.All) - def getProgressInfo(self): - """ Status of all currently running tasks - - :return: list of `ProgressInfo` - """ - pass - ########################## # Configuration ########################## diff --git a/module/FileManager.py b/module/FileManager.py index cf4989f99..1d8cdf328 100644 --- a/module/FileManager.py +++ b/module/FileManager.py @@ -29,6 +29,7 @@ from datatypes.PyPackage import PyPackage, RootPackage def invalidate(func): def new(*args): args[0].filecount = -1 + args[0].downloadcount = -1 args[0].queuecount = -1 args[0].jobCache = {} return func(*args) @@ -65,6 +66,7 @@ class FileManager: #self.lock._Verbose__verbose = True self.filecount = -1 # if an invalid value is set get current value from db + self.downloadcount = -1 # number of downloads self.queuecount = -1 # number of package to be loaded self.db = self.core.db @@ -301,6 +303,13 @@ class FileManager: return self.filecount + def getDownloadCount(self): + """ return number of downloads """ + if self.downloadcount == -1: + self.downloadcount = self.db.downloadcount() + + return self.downloadcount + def getQueueCount(self, force=False): """number of files that have to be processed""" if self.queuecount == -1 or force: diff --git a/module/remote/pyload.thrift b/module/remote/pyload.thrift index 0c4eea9c4..50164c292 100644 --- a/module/remote/pyload.thrift +++ b/module/remote/pyload.thrift @@ -114,7 +114,7 @@ enum Role { struct DownloadProgress { 1: FileID fid, 2: PackageID pid, - 3: ByteCount speed, + 3: ByteCount speed, // per second 4: DownloadStatus status, } @@ -123,21 +123,18 @@ struct ProgressInfo { 2: string name, 3: string statusmsg, 4: i32 eta, // in seconds - 5: string format_eta, - 6: ByteCount done, - 7: ByteCount total, // arbitary number, size in case of files - 8: optional DownloadProgress download + 5: ByteCount done, + 6: ByteCount total, // arbitary number, size in case of files + 7: optional DownloadProgress download } -# TODO: Maybe more are needed? Should be simple values struct ServerStatus { - 1: bool pause, - 2: i16 active, - 3: i16 queue, - 4: i16 total, - 5: ByteCount speed, - 6: bool download, - 7: bool reconnect + 1: i16 queuedDownloads, + 2: i16 totalDownloads, + 3: ByteCount speed, + 4: bool pause, + 5: bool download, + 6: bool reconnect } // download info for specific file @@ -333,19 +330,19 @@ service Pyload { string getServerVersion(), string getWSAddress(), - ServerStatus statusServer(), + ServerStatus getServerStatus(), + list<ProgressInfo> getProgressInfo(), + + list<string> getLog(1: i32 offset), + ByteCount freeSpace(), + void pauseServer(), void unpauseServer(), bool togglePause(), - ByteCount freeSpace(), - void kill(), - void restart(), - list<string> getLog(1: i32 offset), - bool isTimeDownload(), - bool isTimeReconnect(), bool toggleReconnect(), - list<ProgressInfo> getProgressInfo(), + void stop(), + void restart(), /////////////////////// // Configuration diff --git a/module/remote/ttypes.py b/module/remote/ttypes.py index 36b56d961..4368479fd 100644 --- a/module/remote/ttypes.py +++ b/module/remote/ttypes.py @@ -284,14 +284,13 @@ class ProgressInfo(BaseObject): self.download = download class ServerStatus(BaseObject): - __slots__ = ['pause', 'active', 'queue', 'total', 'speed', 'download', 'reconnect'] + __slots__ = ['queuedDownloads', 'totalDownloads', 'speed', 'pause', 'download', 'reconnect'] - def __init__(self, pause=None, active=None, queue=None, total=None, speed=None, download=None, reconnect=None): - self.pause = pause - self.active = active - self.queue = queue - self.total = total + def __init__(self, queuedDownloads=None, totalDownloads=None, speed=None, pause=None, download=None, reconnect=None): + self.queuedDownloads = queuedDownloads + self.totalDownloads = totalDownloads self.speed = speed + self.pause = pause self.download = download self.reconnect = reconnect @@ -435,6 +434,8 @@ class Iface(object): pass def getProgressInfo(self): pass + def getServerStatus(self): + pass def getServerVersion(self): pass def getUserData(self): @@ -447,12 +448,6 @@ class Iface(object): pass def isInteractionWaiting(self, mode): pass - def isTimeDownload(self): - pass - def isTimeReconnect(self): - pass - def kill(self): - pass def login(self, username, password): pass def moveFiles(self, fids, pid): @@ -499,7 +494,7 @@ class Iface(object): pass def setPassword(self, username, old_password, new_password): pass - def statusServer(self): + def stop(self): pass def stopAllDownloads(self): pass diff --git a/module/remote/ttypes_debug.py b/module/remote/ttypes_debug.py index 1b7065d9a..6ca9e892a 100644 --- a/module/remote/ttypes_debug.py +++ b/module/remote/ttypes_debug.py @@ -24,7 +24,7 @@ classes = { 'PackageInfo' : [int, basestring, basestring, int, int, basestring, basestring, basestring, int, (list, basestring), int, int, PackageStats, (list, int), (list, int)], 'PackageStats' : [int, int, int, int], 'ProgressInfo' : [basestring, basestring, basestring, int, basestring, int, int, (None, DownloadProgress)], - 'ServerStatus' : [bool, int, int, int, int, bool, bool], + 'ServerStatus' : [int, int, int, bool, bool, bool], 'ServiceDoesNotExists' : [basestring, basestring], 'ServiceException' : [basestring], 'TreeCollection' : [PackageInfo, (dict, int, FileInfo), (dict, int, PackageInfo)], @@ -79,15 +79,13 @@ methods = { 'getPackageContent': TreeCollection, 'getPackageInfo': PackageInfo, 'getProgressInfo': (list, ProgressInfo), + 'getServerStatus': ServerStatus, 'getServerVersion': basestring, 'getUserData': UserData, 'getUserPlugins': (list, ConfigInfo), 'getWSAddress': basestring, 'hasAddonHandler': bool, 'isInteractionWaiting': bool, - 'isTimeDownload': bool, - 'isTimeReconnect': bool, - 'kill': None, 'login': bool, 'moveFiles': bool, 'movePackage': bool, @@ -111,7 +109,7 @@ methods = { 'setPackageFolder': bool, 'setPackagePaused': None, 'setPassword': bool, - 'statusServer': ServerStatus, + 'stop': None, 'stopAllDownloads': None, 'stopDownloads': None, 'togglePause': bool, diff --git a/module/web/static/js/collections/ProgressList.js b/module/web/static/js/collections/ProgressList.js new file mode 100644 index 000000000..1706d5f16 --- /dev/null +++ b/module/web/static/js/collections/ProgressList.js @@ -0,0 +1,17 @@ +define(['jquery', 'backbone', 'underscore', 'models/Progress'], function($, Backbone, _, Progress) { + + return Backbone.Collection.extend({ + + model: Progress, + + comparator: function(progress) { + return progress.get('eta'); + }, + + initialize: function() { + + } + + }); + +});
\ No newline at end of file diff --git a/module/web/static/js/models/Progress.js b/module/web/static/js/models/Progress.js new file mode 100644 index 000000000..ebbe34862 --- /dev/null +++ b/module/web/static/js/models/Progress.js @@ -0,0 +1,35 @@ +define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { + + return Backbone.Model.extend({ + +// TODO +// idAttribute: 'fid', + + defaults: { + plugin: null, + name: null, + statusmsg: -1, + eta: -1, + done: -1, + total: -1, + download: null + }, + + + // Model Constructor + initialize: function() { + + }, + + // Any time a model attribute is set, this method is called + validate: function(attrs) { + + }, + + isDownload : function() { + return this.has('download') + } + + }); + +});
\ No newline at end of file diff --git a/module/web/static/js/models/ServerStatus.js b/module/web/static/js/models/ServerStatus.js new file mode 100644 index 000000000..f89282d8d --- /dev/null +++ b/module/web/static/js/models/ServerStatus.js @@ -0,0 +1,20 @@ +define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { + + return Backbone.Model.extend({ + + defaults: { + queuedDownloads: -1, + totalDownloads: -1, + speed: -1, + pause: false, + download: false, + reconnect: false, + }, + + // Model Constructor + initialize: function() { + + } + + }); +});
\ No newline at end of file |