diff options
-rw-r--r-- | module/Api.py | 13 | ||||
-rw-r--r-- | module/PluginThread.py | 1 | ||||
-rw-r--r-- | module/database/DatabaseBackend.py | 2 | ||||
-rw-r--r-- | module/database/FileDatabase.py | 61 | ||||
-rwxr-xr-x | pyLoadCli.py | 12 |
5 files changed, 53 insertions, 36 deletions
diff --git a/module/Api.py b/module/Api.py index 832122ac5..15052e83a 100644 --- a/module/Api.py +++ b/module/Api.py @@ -141,17 +141,14 @@ class Api(Iface): :return: `ServerStatus` """ - serverStatus = ServerStatus() - serverStatus.pause = self.core.threadManager.pause - serverStatus.active = len(self.core.threadManager.processingIds()) - serverStatus.queue = self.core.files.getFileCount() #TODO: real amount of queued files - serverStatus.total = self.core.files.getFileCount() - serverStatus.speed = 0 + 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(), + self.core.config['reconnect']['activated'] and self.isTimeReconnect()) + for pyfile in [x.active for x in self.core.threadManager.threads if x.active and isinstance(x, PyFile)]: serverStatus.speed += pyfile.getSpeed() #bytes/s - serverStatus.download = not self.core.threadManager.pause and self.isTimeDownload() - serverStatus.reconnect = self.core.config['reconnect']['activated'] and self.isTimeReconnect() return serverStatus def freeSpace(self): diff --git a/module/PluginThread.py b/module/PluginThread.py index 5f311aa07..d1c139062 100644 --- a/module/PluginThread.py +++ b/module/PluginThread.py @@ -276,6 +276,7 @@ class DownloadThread(PluginThread): finally: self.m.core.files.save() + self.m.core.files.resetCount() exc_clear() diff --git a/module/database/DatabaseBackend.py b/module/database/DatabaseBackend.py index c147aa018..534b5a53c 100644 --- a/module/database/DatabaseBackend.py +++ b/module/database/DatabaseBackend.py @@ -247,7 +247,7 @@ class DatabaseBackend(Thread): self.c.execute('SELECT max(id) FROM packages') pid = self.c.fetchone()[0] if pid: - pid = int(fid) + pid = int(pid) else: pid = 0 self.c.execute('UPDATE SQLITE_SEQUENCE SET seq=? WHERE name=?', (pid, "packages")) diff --git a/module/database/FileDatabase.py b/module/database/FileDatabase.py index c77bf5e95..916a53b76 100644 --- a/module/database/FileDatabase.py +++ b/module/database/FileDatabase.py @@ -55,7 +55,8 @@ class FileHandler: self.lock = RLock() #@TODO should be a Lock w/o R #self.lock._Verbose__verbose = True - self.filecount = -1 # if an invalid value is set get current value from db + self.filecount = -1 # if an invalid value is set get current value from db + self.queuecount = -1 #number of package to be loaded self.unchanged = False #determines if any changes was made since last call self.db = self.core.db @@ -64,6 +65,7 @@ class FileHandler: def new(*args): args[0].unchanged = False args[0].filecount = -1 + args[0].queuecount = -1 args[0].jobCache = {} return func(*args) return new @@ -337,13 +339,17 @@ class FileHandler: self.filecount = self.db.filecount(1) return self.filecount - - #---------------------------------------------------------------------- - def getQueueCount(self): + + def getQueueCount(self, force=False): """number of files that have to be processed""" - pass - - #---------------------------------------------------------------------- + if self.queuecount == -1 or force: + self.queuecount = self.db.queuecount(1) + + return self.queuecount + + def resetCount(self): + self.queuecount = -1 + @lock @change def restartPackage(self, id): @@ -519,25 +525,38 @@ class FileMethods(): @style.queue def filecount(self, queue): """returns number of files in queue""" - self.c.execute("SELECT l.id FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? ORDER BY l.id", (queue, )) - r = self.c.fetchall() - return len(r) - + self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=?", (queue, )) + return self.c.fetchone()[0] + + @style.queue + def queuecount(self, queue): + """ number of files in queue not finished yet""" + self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status NOT IN (0,4)", (queue, )) + return self.c.fetchone()[0] + + @style.queue + def processcount(self, queue): + """ number of files which have to be proccessed """ + self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status IN (2,3,5,7,12)", (queue, )) + return self.c.fetchone()[0] + @style.inner def _nextPackageOrder(self, queue=0): - self.c.execute('SELECT packageorder FROM packages WHERE queue=?', (queue,)) - o = -1 - for r in self.c: - if r[0] > o: o = r[0] - return o + 1 + self.c.execute('SELECT MAX(packageorder) FROM packages WHERE queue=?', (queue,)) + max = self.c.fetchone()[0] + if max is not None: + return max + 1 + else: + return 0 @style.inner def _nextFileOrder(self, package): - self.c.execute('SELECT linkorder FROM links WHERE package=?', (package,)) - o = -1 - for r in self.c: - if r[0] > o: o = r[0] - return o + 1 + self.c.execute('SELECT MAX(linkorder) FROM links WHERE package=?', (package,)) + max = self.c.fetchone()[0] + if max is not None: + return max + 1 + else: + return 0 @style.queue def addLink(self, url, name, plugin, package): diff --git a/pyLoadCli.py b/pyLoadCli.py index 438be61aa..db5952104 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -188,13 +188,13 @@ class Cli: line += 1 status = self.client.statusServer() if status.pause: - println(line, - _("Status: ") + red("paused") + _(" total Speed: ") + red(formatSize(speed) + "/s") + _( - " Files in queue: ") + red(status.queue)) + paused = _("Status: ") + red("paused") else: - println(line, - _("Status: ") + red("running") + _(" total Speed: ") + red(formatSize(speed) + "/s") + _( - " Files in queue: ") + red(status.queue)) + paused = _("Status: ") + red("running") + + println(line, + paused + _(" total Speed: ") + red(formatSize(speed) + "/s") + _( + " Files in queue: ") + red(status.queue) + _(" Total: ") + red(status.total)) return line + 1 |