diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/PullEvents.py | 111 | ||||
-rw-r--r-- | module/download_thread.py | 54 | ||||
-rw-r--r-- | module/file_list.py | 28 | ||||
-rw-r--r-- | module/gui/Collector.py | 237 | ||||
-rw-r--r-- | module/gui/Queue.py | 135 | ||||
-rw-r--r-- | module/gui/connector.py | 22 | ||||
-rw-r--r-- | module/plugins/container/CCF.py | 18 | ||||
-rw-r--r-- | module/plugins/decrypter/SerienjunkiesOrg.py | 1 | ||||
-rw-r--r-- | module/thread_list.py | 57 |
9 files changed, 426 insertions, 237 deletions
diff --git a/module/PullEvents.py b/module/PullEvents.py new file mode 100644 index 000000000..7b23cf8b8 --- /dev/null +++ b/module/PullEvents.py @@ -0,0 +1,111 @@ +# -*- coding: utf-8 -*- + +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: mkaay +""" + +from time import time + +class PullManager(): + def __init__(self, core): + self.core = core + self.clients = [] + + def newClient(self, uuid): + self.clients.append(Client(uuid)) + + def clean(self): + for n, client in enumerate(self.clients): + if client.lastActive + 30 < time(): + del self.clients[n] + + def getEvents(self, uuid): + events = [] + validUuid = False + for client in self.clients: + if client.uuid == uuid: + client.lastActive = time() + validUuid = True + while client.newEvents(): + events.append(client.popEvent().toList()) + break + if not validUuid: + self.newClient(uuid) + events = [ReloadAllEvent("queue").toList(), ReloadAllEvent("packages").toList(), ReloadAllEvent("collector").toList()] + return events + + def addEvent(self, event): + for client in self.clients: + client.addEvent(event) + +class Client(): + def __init__(self, uuid): + self.uuid = uuid + self.lastActive = time() + self.events = [] + + def newEvents(self): + return (len(self.events) > 0) + + def popEvent(self): + if not len(self.events): + return None + return self.events.pop(0) + + def addEvent(self, event): + self.events.append(event) + +class UpdateEvent(): + def __init__(self, itype, iid, destination): + assert itype == "pack" or itype == "file" + assert destination == "queue" or destination == "collector" or destination == "packages" + self.type = itype + self.id = iid + self.destination = destination + + def toList(self): + return ["update", self.destination, self.type, self.id] + +class RemoveEvent(): + def __init__(self, itype, iid, destination): + assert itype == "pack" or itype == "file" + assert destination == "queue" or destination == "collector" or destination == "packages" + self.type = itype + self.id = iid + self.destination = destination + + def toList(self): + return ["remove", self.destination, self.type, self.id] + +class InsertEvent(): + def __init__(self, itype, iid, after, destination): + assert itype == "pack" or itype == "file" + assert destination == "queue" or destination == "collector" or destination == "packages" + self.type = itype + self.id = iid + self.after = after + self.destination = destination + + def toList(self): + return ["insert", self.destination, self.type, self.id, self.after] + +class ReloadAllEvent(): + def __init__(self, destination): + assert destination == "queue" or destination == "collector" or destination == "packages" + self.destination = destination + + def toList(self): + return ["reload", self.destination] diff --git a/module/download_thread.py b/module/download_thread.py index 4a031a04c..7c899b185 100644 --- a/module/download_thread.py +++ b/module/download_thread.py @@ -1,28 +1,33 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# -#Copyright (C) 2009 sp00b, sebnapi -# -#This program is free software; you can redistribute it and/or modify -#it under the terms of the GNU General Public License as published by -#the Free Software Foundation; either version 3 of the License, -#or (at your option) any later version. -# -#This program is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -#See the GNU General Public License for more details. -# -#You should have received a copy of the GNU General Public License -# along with this program; if not, see <http://www.gnu.org/licenses/>. -# -### + +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: mkaay + @author: spoob + @author: sebnapi + @version: v0.3 +""" + import threading import traceback from os.path import join from time import sleep, time from module.network.Request import AbortDownload +from module.PullEvents import UpdateEvent class Status(object): """ Saves all status information @@ -107,15 +112,16 @@ class Download_Thread(threading.Thread): code, msg = e if code == 7: sleep(60) - self.parent.parent.logger.info("Hoster unvailable, wait 60 seconds") + self.parent.parent.logger.info(_("Hoster unvailable, wait 60 seconds")) except Exception, f: - self.parent.parent.logger.debug("Error getting error code: "+ str(f)) + self.parent.parent.logger.debug(_("Error getting error code: %s") % f) if self.parent.parent.config['general']['debug_mode']: traceback.print_exc() self.loadedPyFile.status.type = "failed" self.loadedPyFile.status.error = str(e) finally: self.parent.job_finished(self.loadedPyFile) + self.parent.parent.pullManager.addEvent(UpdateEvent("file", self.loadedPyFile.id, "queue")) else: sleep(3) sleep(0.8) @@ -126,6 +132,7 @@ class Download_Thread(threading.Thread): def download(self, pyfile): status = pyfile.status status.type = "starting" + self.parent.parent.pullManager.addEvent(UpdateEvent("file", pyfile.id, "queue")) pyfile.init_download() @@ -136,6 +143,7 @@ class Download_Thread(threading.Thread): status.type = "decrypting" else: status.type = "downloading" + self.parent.parent.pullManager.addEvent(UpdateEvent("file", pyfile.id, "queue")) location = join(pyfile.folder, status.filename) pyfile.plugin.proceed(status.url, location) @@ -152,13 +160,13 @@ class Download_Thread(threading.Thread): 20 - unknown error """ if code == 0: - self.parent.parent.logger.info("Checksum ok ('%s')" % status.filename) + self.parent.parent.logger.info(_("Checksum ok ('%s')") % status.filename) elif code == 1: - self.parent.parent.logger.info("Checksum not matched! ('%s')" % status.filename) + self.parent.parent.logger.info(_("Checksum not matched! ('%s')") % status.filename) elif code == 5: - self.parent.parent.logger.debug("Can't get checksum for %s" % status.filename) + self.parent.parent.logger.debug(_("Can't get checksum for %s") % status.filename) elif code == 10: - self.parent.parent.logger.debug("Checksum not implemented for %s" % status.filename) + self.parent.parent.logger.debug(_("Checksum not implemented for %s") % status.filename) if not check: raise Checksum(code, location) diff --git a/module/file_list.py b/module/file_list.py index 7c68a7427..d251868b9 100644 --- a/module/file_list.py +++ b/module/file_list.py @@ -33,6 +33,8 @@ from operator import attrgetter from os import sep from time import sleep +from module.PullEvents import UpdateEvent, RemoveEvent, InsertEvent + class NoSuchElementException(Exception): pass @@ -82,11 +84,11 @@ class File_List(object): self.lock.release() if len(self.data["collector"]) > 0: - self.core.logger.info("Found %s links in linkcollector" % len(self.data["collector"])) + self.core.logger.info(_("Found %s links in linkcollector") % len(self.data["collector"])) if len(self.data["packages"]) > 0: - self.core.logger.info("Found %s unqueued packages" % len(self.data["packages"])) + self.core.logger.info(_("Found %s unqueued packages") % len(self.data["packages"])) if len(self.data["queue"]) > 0: - self.core.logger.info("Added %s packages to queue" % len(self.data["queue"])) + self.core.logger.info(_("Added %s packages to queue") % len(self.data["queue"])) def save(self): self.lock.acquire() @@ -148,6 +150,10 @@ class File_List(object): info["size"] = pyfile.status.size() info["active"] = pyfile.active info["plugin"] = pyfile.plugin.props['name'] + try: + info["package"] = pypack.data["id"] + except: + pass return info def continueAborted(self): @@ -194,6 +200,7 @@ class File_List(object): try: n, pyfile = collector._getFileFromID(id) del collector.file_list.data["collector"][n] + collector.file_list.core.pullManager.addEvent(RemoveEvent("file", id, "collector")) except Exception, e: raise Exception, e else: @@ -211,6 +218,7 @@ class File_List(object): collector.file_list.lock.acquire() collector.file_list.data["collector"].append(pyfile) collector.file_list.lock.release() + collector.file_list.core.pullManager.addEvent(InsertEvent("file", pyfile.id, -2, "collector")) return pyfile.id def removeFile(collector, id): @@ -218,6 +226,7 @@ class File_List(object): removes PyLoadFile instance with the given id from collector """ collector.popFile(id) + collector.file_list.core.pullManager.addEvent(RemoveEvent("file", id, "collector")) def replaceFile(collector, newpyfile): """ @@ -227,6 +236,7 @@ class File_List(object): try: n, pyfile = collector._getFileFromID(newpyfile.id) collector.file_list.data["collector"][n] = newpyfile + collector.file_list.core.pullManager.addEvent(UpdateEvent("file", newpyfile.id, "collector")) finally: collector.file_list.lock.release() @@ -277,6 +287,7 @@ class File_List(object): if package_name is not None: pypack.data["package_name"] = package_name packager.file_list.data["packages"].append(pypack) + packager.file_list.core.pullManager.addEvent(InsertEvent("pack", pypack.data["id"], -2, "packages")) return pypack.data["id"] def removePackage(packager, id): @@ -287,6 +298,7 @@ class File_List(object): pyfile.plugin.req.abort = True sleep(0.1) del packager.file_list.data[key][n] + packager.file_list.core.pullManager.addEvent(RemoveEvent("pack", id, key)) finally: packager.file_list.lock.release() @@ -312,6 +324,8 @@ class File_List(object): if key == "packages": del packager.file_list.data["packages"][n] packager.file_list.data["queue"].append(pypack) + packager.file_list.core.pullManager.addEvent(RemoveEvent("pack", id, "packages")) + packager.file_list.core.pullManager.addEvent(InsertEvent("pack", id, -2, "queue")) finally: packager.file_list.lock.release() @@ -322,6 +336,8 @@ class File_List(object): if key == "queue": del packager.file_list.data["queue"][n] packager.file_list.data["packages"].append(pypack) + packager.file_list.core.pullManager.addEvent(RemoveEvent("pack", id, "queue")) + packager.file_list.core.pullManager.addEvent(InsertEvent("pack", id, -2, "packages")) finally: packager.file_list.lock.release() @@ -334,6 +350,7 @@ class File_List(object): if folder is not None: pypack.data["folder"] = folder packager.file_list.data[key][n] = pypack + packager.file_list.core.pullManager.addEvent(UpdateEvent("pack", id, key)) finally: packager.file_list.lock.release() @@ -352,6 +369,7 @@ class File_List(object): pyfile.package = pypack pypack.files.append(pyfile) packager.file_list.data[key][n] = pypack + packager.file_list.core.pullManager.addEvent(InsertEvent("file", pyfile.id, -2, key)) def resetFileStatus(packager, fileid): packager.file_list.lock.acquire() @@ -359,6 +377,7 @@ class File_List(object): key, n, pyfile, pypack, pid = packager._getFileFromID(fileid) pyfile.init() pyfile.status.type = None + packager.file_list.core.pullManager.addEvent(UpdateEvent("file", fileid, key)) finally: packager.file_list.lock.release() @@ -367,15 +386,16 @@ class File_List(object): try: key, n, pyfile, pypack, pid = packager._getFileFromID(fileid) pyfile.plugin.req.abort = True + packager.file_list.core.pullManager.addEvent(UpdateEvent("file", fileid, key)) finally: packager.file_list.lock.release() - #oooops, duplicate? def removeFileFromPackage(packager, id, pid): key, n, pypack = packager._getPackageFromID(pid) for k, pyfile in enumerate(pypack.files): if id == pyfile.id: del pypack.files[k] + packager.file_list.core.pullManager.addEvent(RemoveEvent("file", pyfile.id, key)) if not pypack.files: packager.removePackage(pid) return True diff --git a/module/gui/Collector.py b/module/gui/Collector.py index 0aad5d1ba..ebdbd372d 100644 --- a/module/gui/Collector.py +++ b/module/gui/Collector.py @@ -27,7 +27,6 @@ class PackageCollector(QObject): self.view = view self.connector = connector self.collector = [] - self.interval = 2 self.rootItem = self.view.invisibleRootItem() self.mutex = QMutex() item = self.PackageCollectorPack(self) @@ -36,48 +35,82 @@ class PackageCollector(QObject): item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.rootItem.addChild(item) self.linkCollector = item - self.pauseIDs = [] - self.updater = self.CollectorUpdater(self.interval) - self.connect(self.updater, SIGNAL("update()"), self.update) - class CollectorUpdater(QThread): - def __init__(self, interval): - QThread.__init__(self) - self.interval = interval - self.running = True - - def run(self): - while self.running: - self.emit(SIGNAL("update()")) - self.sleep(self.interval) - - def start(self): - self.updater.start() - - def wait(self): - self.updater.wait() - - def stop(self): - self.updater.running = False - - def update(self): + def fullReload(self): locker = QMutexLocker(self.mutex) + self.clearAll() packs = self.connector.getPackageCollector() - ids = [] for data in packs: - ids.append(data["id"]) - self.clear(ids) - for data in packs: - if data["id"] in self.pauseIDs: - continue - ids.append(data["id"]) - pack = self.getPack(data["id"]) - if not pack: - pack = self.PackageCollectorPack(self) + pack = self.PackageCollectorPack(self) pack.setPackData(data) + files = self.connector.getPackageFiles(data["id"]) + for fid in files: + info = self.connector.getLinkInfo(fid) + child = self.PackageCollectorFile(self, pack) + child.setFileData(info) + pack.addPackChild(fid, child) self.addPack(data["id"], pack) + + def addEvent(self, event): + if event[0] == "reload": + self.fullReload() + elif event[0] == "remove": + self.removeEvent(event) + elif event[0] == "insert": + self.insertEvent(event) + elif event[0] == "update": + self.updateEvent(event) + + def removeEvent(self, event): + if event[2] == "file": + for pack in ItemIterator(self.rootItem): + for k, child in enumerate(pack.getChildren()): + if child.getFileData()["id"] == event[3]: + pack.removeChild(child) + break + else: + for k, pack in enumerate(ItemIterator(self.rootItem)): + if pack.getPackData()["id"] == event[3]: + self.rootItem.removeChild(pack) + break + + def insertEvent(self, event): + if event[2] == "file": + info = self.connector.getLinkInfo(event[3]) + for pack in ItemIterator(self.rootItem): + if pack.getPackData()["id"] == info["package"]: + child = self.PackageCollectorFile(self, pack) + child.setFileData(info) + pack.addPackChild(info["id"], child) + break + else: + data = self.connector.getPackageInfo(event[3]) + pack = self.PackageCollectorPack(self) + pack.setPackData(data) + self.addPack(data["id"], pack) + files = self.connector.getPackageFiles(data["id"]) + for fid in files: + info = self.connector.getLinkInfo(fid) + child = self.PackageCollectorFile(self, pack) + child.setFileData(info) + pack.addPackChild(fid, child) + self.addPack(data["id"], pack) + + def updateEvent(self, event): + if event[2] == "file": + info = self.connector.getLinkInfo(event[3]) + if not info: + return + for pack in ItemIterator(self.rootItem): + if pack.getPackData()["id"] == info["package"]: + child = pack.getChild(event[3]) + child.setFileData(info) + pack.addPackChild(info["id"], child) + else: + data = self.connector.getPackageInfo(event[3]) + pack = self.getPack(event[3]) + pack.setPackData(data) files = self.connector.getPackageFiles(data["id"]) - pack.clear(files) for fid in files: info = self.connector.getLinkInfo(fid) child = pack.getChild(fid) @@ -85,6 +118,7 @@ class PackageCollector(QObject): child = self.PackageCollectorFile(self, pack) child.setFileData(info) pack.addPackChild(fid, child) + self.addPack(data["id"], pack) def addPack(self, pid, newPack): pos = None @@ -110,38 +144,10 @@ class PackageCollector(QObject): return pack return None - def clear(self, ids): - clear = False - remove = [] + def clearAll(self): for k, pack in enumerate(ItemIterator(self.rootItem)): - if not pack.getPackData()["id"] in ids and not pack.getPackData()["id"] == "fixed": - clear = True - remove.append(k) - if not clear: - return - remove.sort() - remove.reverse() - for k in remove: - self.rootItem.takeChild(k) - for pack in ItemIterator(self.rootItem): - if pack.getPackData()["id"] == "fixed": - return - item = self.PackageCollectorPack(self) - item.setPackData({"id":"fixed"}) - item.setData(0, Qt.DisplayRole, QVariant("Single Links")) - item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) - self.rootItem.addChild(item) - self.linkCollector = item - - def pauseItemUpdate(self, pid, pause=True): - locker = QMutexLocker(self.mutex) - if pause and not pid in self.pauseIDs: - self.pauseIDs.append(int(pid)) - else: - try: - self.pauseIDs.remove(int(pid)) - except: - pass + if not pack.getPackData()["id"] == "fixed": + self.rootItem.removeChild(pack) class PackageCollectorPack(QTreeWidgetItem): def __init__(self, collector): @@ -184,25 +190,6 @@ class PackageCollector(QObject): if item.getFileData()["id"] == cid: return item return None - - def clear(self, ids): - clear = False - remove = [] - children = [] - for k, file in enumerate(self.getChildren()): - if not file.getFileData()["id"] in ids: - remove.append(file.getFileData()["id"]) - if file.getFileData()["id"] in children and not file.getFileData()["id"] in remove: - remove.append(file.getFileData()["id"]) - continue - children.append(file.getFileData()["id"]) - if not remove: - return - remove.sort() - remove.reverse() - parent = self - for k in remove: - parent.takeChild(k) class PackageCollectorFile(QTreeWidgetItem): def __init__(self, collector, pack): @@ -226,44 +213,52 @@ class LinkCollector(QObject): QObject.__init__(self) self.view = view self.connector = connector - self.interval = 2 self.rootItem = root self.mutex = QMutex() - self.updater = self.CollectorUpdater(self.interval) - self.connect(self.updater, SIGNAL("update()"), self.update) - class CollectorUpdater(QThread): - def __init__(self, interval): - QThread.__init__(self) - self.interval = interval - self.running = True - - def run(self): - while self.running: - self.emit(SIGNAL("update()")) - self.sleep(self.interval) - - def start(self): - self.updater.start() - - def wait(self): - self.updater.wait() - - def stop(self): - self.updater.running = False - - def update(self): + def fullReload(self): locker = QMutexLocker(self.mutex) + self.clearAll() ids = self.connector.getLinkCollector() - self.clear(ids) for fid in ids: data = self.connector.getLinkInfo(fid) - file = self.getFile(fid) - if not file: - file = self.LinkCollectorFile(self) + file = self.LinkCollectorFile(self) file.setFileData(data) self.addFile(fid, file) + def addEvent(self, event): + if event[0] == "reload": + self.fullReload() + elif event[0] == "remove": + self.removeEvent(event) + elif event[0] == "insert": + self.insertEvent(event) + elif event[0] == "update": + self.updateEvent(event) + + def removeEvent(self, event): + if event[2] == "file": + for k, file in enumerate(ItemIterator(self.rootItem)): + if file.getFileData()["id"] == event[3]: + self.rootItem.removeChild(file) + break + + def insertEvent(self, event): + if event[2] == "file": + data = self.connector.getLinkInfo(event[3]) + file = self.LinkCollectorFile(self) + file.setFileData(data) + self.addFile(event[3], file) + + def updateEvent(self, event): + if event[2] == "file": + data = self.connector.getLinkInfo(event[3]) + if not data: + return + file = getFile(event[3]) + file.setFileData(data) + self.addFile(event[3], file) + def addFile(self, pid, newFile): pos = None try: @@ -289,16 +284,10 @@ class LinkCollector(QObject): return file return None - def clear(self, ids): - clear = False - for file in ItemIterator(self.rootItem): - if not file.getFileData()["id"] in ids: - clear = True - break - if not clear: - return - self.rootItem.takeChildren() - + def clearAll(self): + for k, file in enumerate(ItemIterator(self.rootItem)): + self.rootItem.removeChild(file) + class LinkCollectorFile(QTreeWidgetItem): def __init__(self, collector): QTreeWidgetItem.__init__(self) diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 8681d3bb1..bd45e27dc 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -77,28 +77,103 @@ class Queue(QObject): del d["name"] del d["status"] downloading[did] = d - ids = [] - for data in packs: - ids.append(data["id"]) - self.clear(ids) + for pack in ItemIterator(self.rootItem): + for child in pack.getChildren(): + info = child.getFileData() + try: + info["downloading"] = downloading[info["id"]] + except: + info["downloading"] = None + child.setFileData(info) + pack.addPackChild(info["id"], child) + self.addPack(pack.getPackData()["id"], pack) + + def fullReload(self): + self.clearAll() + packs = self.connector.getPackageQueue() for data in packs: - pack = self.getPack(data["id"]) - if not pack: - pack = self.QueuePack(self) + pack = self.QueuePack(self) pack.setPackData(data) files = self.connector.getPackageFiles(data["id"]) - pack.clear(files) + for fid in files: + info = self.connector.getLinkInfo(fid) + child = self.QueueFile(self, pack) + if not info["status_type"]: + info["status_type"] = "queued" + child.setFileData(info) + pack.addPackChild(fid, child) self.addPack(data["id"], pack) + + def addEvent(self, event): + locker = QMutexLocker(self.mutex) + if event[0] == "reload": + self.fullReload() + elif event[0] == "remove": + self.removeEvent(event) + elif event[0] == "insert": + self.insertEvent(event) + elif event[0] == "update": + self.updateEvent(event) + + def removeEvent(self, event): + if event[2] == "file": + for pack in ItemIterator(self.rootItem): + for k, child in enumerate(pack.getChildren()): + if child.getFileData()["id"] == event[3]: + pack.removeChild(child) + break + else: + for k, pack in enumerate(ItemIterator(self.rootItem)): + if pack.getPackData()["id"] == event[3]: + self.rootItem.removeChild(pack) + break + + def insertEvent(self, event): + if event[2] == "file": + info = self.connector.getLinkInfo(event[3]) + for pack in ItemIterator(self.rootItem): + if pack.getPackData()["id"] == info["package"]: + child = self.QueueFile(self, pack) + child.setFileData(info) + pack.addPackChild(info["id"], child) + break + else: + data = self.connector.getPackageInfo(event[3]) + pack = self.QueuePack(self) + pack.setPackData(data) + self.addPack(data["id"], pack) + files = self.connector.getPackageFiles(data["id"]) + for fid in files: + info = self.connector.getLinkInfo(fid) + child = self.QueueFile(self, pack) + if not info["status_type"]: + info["status_type"] = "queued" + child.setFileData(info) + pack.addPackChild(fid, child) + self.addPack(data["id"], pack) + + def updateEvent(self, event): + if event[2] == "file": + info = self.connector.getLinkInfo(event[3]) + if not info: + return + for pack in ItemIterator(self.rootItem): + if pack.getPackData()["id"] == info["package"]: + child = pack.getChild(event[3]) + if not info["status_type"]: + info["status_type"] = "queued" + child.setFileData(info) + pack.addPackChild(info["id"], child) + else: + data = self.connector.getPackageInfo(event[3]) + pack = self.getPack(event[3]) + pack.setPackData(data) + files = self.connector.getPackageFiles(data["id"]) for fid in files: info = self.connector.getLinkInfo(fid) child = pack.getChild(fid) if not child: child = self.QueueFile(self, pack) - info["downloading"] = None - try: - info["downloading"] = downloading[info["id"]] - except: - pass if not info["status_type"]: info["status_type"] = "queued" child.setFileData(info) @@ -145,19 +220,9 @@ class Queue(QObject): return pack return None - def clear(self, ids): - clear = False - remove = [] - for k, pack in enumerate(ItemIterator(self.rootItem)): - if not pack.getPackData()["id"] in ids: - clear = True - remove.append(k) - if not clear: - return - remove.sort() - remove.reverse() - for k in remove: - self.rootItem.takeChild(k) + def clearAll(self): + for pack in ItemIterator(self.rootItem): + self.rootItem.removeChild(pack) def getWaitingProgress(self, q): locker = QMutexLocker(self.mutex) @@ -282,24 +347,6 @@ class Queue(QObject): if item.getFileData()["id"] == cid: return item return None - - def clear(self, ids): - clear = False - remove = [] - children = [] - for k, file in enumerate(self.getChildren()): - if not file.getFileData()["id"] in ids: - remove.append(file.getFileData()["id"]) - if file.getFileData()["id"] in children and not file.getFileData()["id"] in remove: - remove.append(file.getFileData()["id"]) - continue - children.append(file.getFileData()["id"]) - if not remove: - return - remove.sort() - remove.reverse() - for k in remove: - self.takeChild(k) class QueueFile(QTreeWidgetItem): def __init__(self, queue, pack): diff --git a/module/gui/connector.py b/module/gui/connector.py index 432999161..b6c383956 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -19,6 +19,7 @@ SERVER_VERSION = "0.3" from time import sleep +from uuid import uuid4 as uuid from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -35,6 +36,7 @@ class connector(QThread): self.running = True self.proxy = None self.addr = None + self.connectionID = None self.errorQueue = [] self.connect(self, SIGNAL("proxy_error"), self._proxyError) @@ -72,6 +74,7 @@ class connector(QThread): self.proxy = ServerProxy(addr, allow_none=True) try: server_version = self.proxy.get_server_version() + self.connectionID = uuid().hex except: return False if not server_version == SERVER_VERSION: @@ -124,9 +127,12 @@ class connector(QThread): """ self.mutex.lock() try: - return self.proxy.get_file_info(id) + info = self.proxy.get_file_info(id) + info["downloading"] = None + return info except Exception, e: - self.emit(SIGNAL("proxy_error"), "getLinkInfo", e) + #self.emit(SIGNAL("proxy_error"), "getLinkInfo", e) + return None finally: self.mutex.unlock() @@ -421,4 +427,16 @@ class connector(QThread): self.emit(SIGNAL("proxy_error"), "setCaptchaResult", e) finally: self.mutex.unlock() + + def getEvents(self): + """ + get events + """ + self.mutex.lock() + try: + return self.proxy.get_events(self.connectionID) + except Exception, e: + self.emit(SIGNAL("proxy_error"), "getEvents", e) + finally: + self.mutex.unlock() diff --git a/module/plugins/container/CCF.py b/module/plugins/container/CCF.py index 88b567904..12728d022 100644 --- a/module/plugins/container/CCF.py +++ b/module/plugins/container/CCF.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import os.path -import random import re import tempfile import urllib2 @@ -36,20 +35,11 @@ class CCF(Plugin): "upload": open(infile, "rb")} tempdlc_content = opener.open('http://service.jdownloader.net/dlcrypt/getDLC.php', params).read() - random.seed() - tempdir = tempfile.gettempdir() - if tempdir[0] == '/': - delim = '/' - else: - delim = '\\' - tempdlc_name = tempdir + delim + str(random.randint(0, 100)) + '-tmp.dlc' - while os.path.exists(tempdlc_name): - tempdlc_name = tempfile.gettempdir() + '/' + str(random.randint(0, 100)) + '-tmp.dlc' - - tempdlc = open(tempdlc_name, "w") + tempdlc = tempfile.NamedTemporaryFile(delete=False, suffix='.dlc') tempdlc.write(re.search(r'<dlc>(.*)</dlc>', tempdlc_content, re.DOTALL).group(1)) - tempdlc.close + tempdlc.close() - self.links.append(tempdlc_name) + self.links.append(tempdlc.name) return True + diff --git a/module/plugins/decrypter/SerienjunkiesOrg.py b/module/plugins/decrypter/SerienjunkiesOrg.py index af7dc8169..d8396bd0b 100644 --- a/module/plugins/decrypter/SerienjunkiesOrg.py +++ b/module/plugins/decrypter/SerienjunkiesOrg.py @@ -5,6 +5,7 @@ import re from module.Plugin import Plugin from module.BeautifulSoup import BeautifulSoup from module.unescape import unescape +from module.download_thread import CaptchaError class SerienjunkiesOrg(Plugin): def __init__(self, parent): diff --git a/module/thread_list.py b/module/thread_list.py index 1a66bf6f5..a50d73aaf 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -1,22 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# -#Copyright (C) 2009 sp00b, sebnapi, RaNaN -# -#This program is free software; you can redistribute it and/or modify -#it under the terms of the GNU General Public License as published by -#the Free Software Foundation; either version 3 of the License, -#or (at your option) any later version. -# -#This program is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -#See the GNU General Public License for more details. -# -#You should have received a copy of the GNU General Public License -# along with this program; if not, see <http://www.gnu.org/licenses/>. -# -### + +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: mkaay + @author: spoob + @author: sebnapi + @author: RaNaN + @version: v0.3 +""" + from __future__ import with_statement from os.path import exists import re @@ -80,9 +85,9 @@ class Thread_List(object): self.occ_plugins.append(pyfile.modul.__name__) pyfile.active = True if pyfile.plugin.props['type'] == "container": - self.parent.logger.info('Get links from: ' + pyfile.url) + self.parent.logger.info(_("Get links from: %s") % pyfile.url) else: - self.parent.logger.info('Download starts: ' + pyfile.url) + self.parent.logger.info(_("Download starts: %s") % pyfile.url) self.lock.release() return pyfile @@ -128,27 +133,27 @@ class Thread_List(object): self.list.packager.removeFileFromPackage(pyfile.id, pyfile.package.data["id"]) if newLinks: - self.parent.logger.info("Parsed links from %s: %i" % (pyfile.status.filename, newLinks)) + self.parent.logger.info(_("Parsed links from %s: %i") % (pyfile.status.filename, newLinks)) else: - self.parent.logger.info("No links in %s" % pyfile.status.filename) + self.parent.logger.info(_("No links in %s") % pyfile.status.filename) #~ self.list.packager.removeFileFromPackage(pyfile.id, pyfile.package.id) #~ for link in pyfile.plugin.links: #~ id = self.list.collector.addLink(link) #~ pyfile.packager.pullOutPackage(pyfile.package.id) #~ pyfile.packager.addFileToPackage(pyfile.package.id, pyfile.collector.popFile(id)) else: - self.parent.logger.info("Download finished: %s" % pyfile.url) + self.parent.logger.info(_("Download finished: %s") % pyfile.url) elif pyfile.status.type == "reconnected": pyfile.plugin.req.init_curl() elif pyfile.status.type == "failed": - self.parent.logger.warning("Download failed: " + pyfile.url + " | " + pyfile.status.error) + self.parent.logger.warning(_("Download failed: %s | %s") % (pyfile.url, pyfile.status.error)) with open(self.parent.config['general']['failed_file'], 'a') as f: f.write(pyfile.url + "\n") elif pyfile.status.type == "aborted": - self.parent.logger.info("Download aborted: " + pyfile.url) + self.parent.logger.info(_("Download aborted: %s") % pyfile.url) self.list.save() @@ -198,7 +203,7 @@ class Thread_List(object): return False def reconnect(self): - self.parent.logger.info("Start reconnect") + self.parent.logger.info(_("Starting reconnect")) ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1) self.parent.hookManager.beforeReconnecting(ip) reconn = subprocess.Popen(self.parent.config['reconnect']['method'])#, stdout=subprocess.PIPE) @@ -212,7 +217,7 @@ class Thread_List(object): ip = "" time.sleep(1) self.parent.hookManager.afterReconnecting(ip) - self.parent.logger.info("Reconnected, new IP: " + ip) + self.parent.logger.info(_("Reconnected, new IP: %s") % ip) def stopAllDownloads(self): self.pause = True |