diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-09-21 16:43:22 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-09-21 16:43:22 +0200 |
commit | 79ce6f862285f355455119d64d8aa1753cff0470 (patch) | |
tree | 238b2f309d2f90cb9c3d722b15748b45a6e5d6d1 /module | |
parent | yourfiles.biz fix (diff) | |
download | pyload-79ce6f862285f355455119d64d8aa1753cff0470.tar.xz |
royflos GUI patches, prefix option for webinterface (
Diffstat (limited to 'module')
-rw-r--r-- | module/Api.py | 1 | ||||
-rw-r--r-- | module/Utils.py | 4 | ||||
-rw-r--r-- | module/config/default.conf | 1 | ||||
-rw-r--r-- | module/gui/Collector.py | 22 | ||||
-rw-r--r-- | module/gui/ConnectionManager.py | 7 | ||||
-rw-r--r-- | module/gui/MainWindow.py | 68 | ||||
-rw-r--r-- | module/gui/Overview.py | 10 | ||||
-rw-r--r-- | module/gui/Queue.py | 47 | ||||
-rw-r--r-- | module/gui/SettingsWidget.py | 3 | ||||
-rw-r--r-- | module/gui/connector.py | 2 | ||||
-rw-r--r-- | module/plugins/hoster/FileserveCom.py | 1 | ||||
-rw-r--r-- | module/remote/thriftbackend/ThriftClient.py | 3 | ||||
-rw-r--r-- | module/web/middlewares.py | 2 | ||||
-rw-r--r-- | module/web/webinterface.py | 19 |
14 files changed, 70 insertions, 120 deletions
diff --git a/module/Api.py b/module/Api.py index 5583bb603..37336e568 100644 --- a/module/Api.py +++ b/module/Api.py @@ -34,7 +34,6 @@ from network.RequestFactory import getURL urlmatcher = re.compile(r"((https?|ftps?|xdcc|sftp):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)", re.IGNORECASE) - class Api(Iface): """ **pyLoads API** diff --git a/module/Utils.py b/module/Utils.py index 0ba3fb035..1fdf2cbc6 100644 --- a/module/Utils.py +++ b/module/Utils.py @@ -93,6 +93,10 @@ def formatSize(size): return "%.2f %s" % (size, sizes[steps]) +def formatSpeed(speed): + return formatSize(speed) + "/s" + + def freeSpace(folder): if os.name == "nt": import ctypes diff --git a/module/config/default.conf b/module/config/default.conf index eef8f6347..065c2f932 100644 --- a/module/config/default.conf +++ b/module/config/default.conf @@ -15,6 +15,7 @@ webinterface - "Webinterface": ip host : "IP" = 0.0.0.0
int port : "Port" = 8001
str template : "Template" = default
+ str prefix: "Path Prefix" =
log - "Log":
bool file_log : "File Log" = True
folder log_folder : "Folder" = Logs
diff --git a/module/gui/Collector.py b/module/gui/Collector.py index 6b0a54d2f..c569785e2 100644 --- a/module/gui/Collector.py +++ b/module/gui/Collector.py @@ -19,25 +19,15 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * -from module.remote.thriftbackend.thriftgen.pyload.ttypes import * from module.PyFile import statusMap +from module.utils import formatSize + +from module.remote.thriftbackend.ThriftClient import Destination, FileDoesNotExists, ElementType statusMapReverse = dict((v,k) for k, v in statusMap.iteritems()) translatedStatusMap = {} # -> CollectorModel.__init__ -def formatSize(size): - """formats size of bytes""" - size = int(size) - steps = 0 - sizes = ["B", "KiB", "MiB", "GiB", "TiB"] - - while size > 1000: - size /= 1024.0 - steps += 1 - - return "%.2f %s" % (size, sizes[steps]) - class CollectorModel(QAbstractItemModel): """ model for the collector view @@ -80,7 +70,7 @@ class CollectorModel(QAbstractItemModel): """ called from main loop, pass events to the correct methods """ - locker = QMutexLocker(self.mutex) + QMutexLocker(self.mutex) if event.event == "reload": self.fullReload() elif event.event == "remove": @@ -339,7 +329,6 @@ class Package(object): "site": pack.site, "password": pack.password, "order": pack.order, - "priority": pack.priority, } self.data.update(data) @@ -392,13 +381,12 @@ class Link(object): "name": f.name, "plugin": f.plugin, "size": f.size, - "forrmat_size": f.format_size, + "format_size": f.format_size, "status": f.status, "statusmsg": f.statusmsg, "package": f.packageID, "error": f.error, "order": f.order, - "progress": f.progress } self.data.update(data) diff --git a/module/gui/ConnectionManager.py b/module/gui/ConnectionManager.py index 8e355bfe1..930cbd889 100644 --- a/module/gui/ConnectionManager.py +++ b/module/gui/ConnectionManager.py @@ -28,10 +28,7 @@ class ConnectionManager(QWidget): QWidget.__init__(self) QMessageBox.warning(self, 'Warning', - "We are sorry but the GUI is not usable anymore. Please use the webinterface for much better experience. \n", QMessageBox.Ok) - - return - + "We are sorry but the GUI is not stable yet. Please use the webinterface for much better experience. \n", QMessageBox.Ok) mainLayout = QHBoxLayout() buttonLayout = QVBoxLayout() @@ -155,7 +152,7 @@ class ConnectionManager(QWidget): data = defaultItem.data(Qt.UserRole).toPyObject() self.setDefault(data, True) did = self.cleanDict(data)["id"] - allItems = self.connList.findItems("*", Qt.MatchWildcard) + #allItems = self.connList.findItems("*", Qt.MatchWildcard) count = self.connList.count() for i in range(count): item = self.connList.item(i) diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index a9ede10c5..9aea50b33 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -32,7 +32,7 @@ from module.gui.Overview import OverviewView from module.gui.Accounts import AccountView from module.gui.AccountEdit import AccountEdit -from module.remote.thriftbackend.thriftgen.pyload.ttypes import * +from module.remote.thriftbackend.ThriftClient import AccountInfo class MainWindow(QMainWindow): def __init__(self, connector): @@ -163,8 +163,6 @@ class MainWindow(QMainWindow): #init tabs self.init_tabs(connector) - self.setPriority = Priority(self) - #context menus self.init_context() @@ -189,9 +187,10 @@ class MainWindow(QMainWindow): """ create toolbar """ - self.toolbar = self.addToolBar(_("Main Toolbar")) + self.toolbar = self.addToolBar(_("Hide Toolbar")) self.toolbar.setObjectName("Main Toolbar") - self.toolbar.setIconSize(QSize(40,40)) + self.toolbar.setIconSize(QSize(30,30)) + self.toolbar.setMovable(False) self.actions["toggle_status"] = self.toolbar.addAction(_("Toggle Pause/Resume")) pricon = QIcon() pricon.addFile(join(pypath, "icons","toolbar_start.png"), QSize(), QIcon.Normal, QIcon.Off) @@ -278,36 +277,17 @@ class MainWindow(QMainWindow): self.queueContext.buttons["pull"] = QAction(QIcon(join(pypath, "icons","pull_small.png")), _("Pull out"), self.queueContext) self.queueContext.buttons["abort"] = QAction(QIcon(join(pypath, "icons","abort.png")), _("Abort"), self.queueContext) self.queueContext.buttons["edit"] = QAction(QIcon(join(pypath, "icons","edit_small.png")), _("Edit Name"), self.queueContext) - self.queuePriorityMenu = QMenu(_("Priority")) - self.queuePriorityMenu.actions = {} - self.queuePriorityMenu.actions["veryhigh"] = QAction(_("very high"), self.queuePriorityMenu) - self.queuePriorityMenu.addAction(self.queuePriorityMenu.actions["veryhigh"]) - self.queuePriorityMenu.actions["high"] = QAction(_("high"), self.queuePriorityMenu) - self.queuePriorityMenu.addAction(self.queuePriorityMenu.actions["high"]) - self.queuePriorityMenu.actions["normal"] = QAction(_("normal"), self.queuePriorityMenu) - self.queuePriorityMenu.addAction(self.queuePriorityMenu.actions["normal"]) - self.queuePriorityMenu.actions["low"] = QAction(_("low"), self.queuePriorityMenu) - self.queuePriorityMenu.addAction(self.queuePriorityMenu.actions["low"]) - self.queuePriorityMenu.actions["verylow"] = QAction(_("very low"), self.queuePriorityMenu) - self.queuePriorityMenu.addAction(self.queuePriorityMenu.actions["verylow"]) self.queueContext.addAction(self.queueContext.buttons["pull"]) self.queueContext.addAction(self.queueContext.buttons["edit"]) self.queueContext.addAction(self.queueContext.buttons["remove"]) self.queueContext.addAction(self.queueContext.buttons["restart"]) self.queueContext.addAction(self.queueContext.buttons["abort"]) - self.queueContext.addMenu(self.queuePriorityMenu) self.connect(self.queueContext.buttons["remove"], SIGNAL("triggered()"), self.slotRemoveDownload) self.connect(self.queueContext.buttons["restart"], SIGNAL("triggered()"), self.slotRestartDownload) self.connect(self.queueContext.buttons["pull"], SIGNAL("triggered()"), self.slotPullOutPackage) self.connect(self.queueContext.buttons["abort"], SIGNAL("triggered()"), self.slotAbortDownload) self.connect(self.queueContext.buttons["edit"], SIGNAL("triggered()"), self.slotEditPackage) - self.connect(self.queuePriorityMenu.actions["veryhigh"], SIGNAL("triggered()"), self.setPriority.veryHigh) - self.connect(self.queuePriorityMenu.actions["high"], SIGNAL("triggered()"), self.setPriority.high) - self.connect(self.queuePriorityMenu.actions["normal"], SIGNAL("triggered()"), self.setPriority.normal) - self.connect(self.queuePriorityMenu.actions["low"], SIGNAL("triggered()"), self.setPriority.low) - self.connect(self.queuePriorityMenu.actions["verylow"], SIGNAL("triggered()"), self.setPriority.veryLow) - #collector self.collectorContext = QMenu() self.collectorContext.buttons = {} @@ -509,7 +489,6 @@ class MainWindow(QMainWindow): #self.queueContext.buttons["restart"].setEnabled(True) self.queueContext.buttons["pull"].setEnabled(True) self.queueContext.buttons["edit"].setEnabled(True) - self.queuePriorityMenu.setEnabled(True) elif isinstance(item, Link): self.collectorContext.index = i self.collectorContext.buttons["edit"].setEnabled(False) @@ -522,7 +501,6 @@ class MainWindow(QMainWindow): #self.queueContext.buttons["restart"].setEnabled(False) self.queueContext.buttons["pull"].setEnabled(False) self.queueContext.buttons["edit"].setEnabled(False) - self.queuePriorityMenu.setEnabled(False) self.queueContext.exec_(menuPos) def slotCollectorContextMenu(self, pos): @@ -621,13 +599,14 @@ class MainWindow(QMainWindow): item = index.internalPointer() self.emit(SIGNAL("abortDownload"), item.id, isinstance(item, Package)) - def changeEvent(self, e): - if e.type() == QEvent.WindowStateChange and self.isMinimized(): - e.ignore() - self.hide() - self.emit(SIGNAL("hidden")) - else: - super(MainWindow, self).changeEvent(e) + # TODO disabled because changing desktop on linux, main window disappears + #def changeEvent(self, e): + # if e.type() == QEvent.WindowStateChange and self.isMinimized(): + # e.ignore() + # self.hide() + # self.emit(SIGNAL("hidden")) + # else: + # super(MainWindow, self).changeEvent(e) def slotTabChanged(self, index): if index == 2: @@ -710,26 +689,3 @@ class MainWindow(QMainWindow): menuPos = QCursor.pos() menuPos.setX(menuPos.x()+2) self.accountContext.exec_(menuPos) - -class Priority(): - def __init__(self, win): - self.w = win - - def setPriority(self, level): - if self.w.activeMenu == self.w.queueContext: - smodel = self.w.tabs["queue"]["view"].selectionModel() - else: - smodel = self.w.tabs["collector"]["package_view"].selectionModel() - for index in smodel.selectedRows(0): - item = index.internalPointer() - pid = item.id if isinstance(item, Package) else item.package.id - self.w.emit(SIGNAL("setPriority"), pid, level) - - def veryHigh(self): self.setPriority(2) - def high(self): self.setPriority(1) - def normal(self): self.setPriority(0) - def low(self): self.setPriority(-1) - def veryLow(self): self.setPriority(-2) - - - diff --git a/module/gui/Overview.py b/module/gui/Overview.py index 50e9dd618..ee05d92e9 100644 --- a/module/gui/Overview.py +++ b/module/gui/Overview.py @@ -19,16 +19,8 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * -from time import sleep, time -def formatSpeed(speed): - speed = int(speed) - steps = 0 - sizes = ["B/s", "KiB/s", "MiB/s", "GiB/s"] - while speed > 1000: - speed /= 1024.0 - steps += 1 - return "%.2f %s" % (speed, sizes[steps]) +from module.utils import formatSpeed class OverviewModel(QAbstractListModel): PackageName = 10 diff --git a/module/gui/Queue.py b/module/gui/Queue.py index a4c0cf389..10ff9d84f 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -19,20 +19,11 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * -from module.remote.thriftbackend.thriftgen.pyload.ttypes import * +from time import time -from time import sleep, time - -from module.gui.Collector import CollectorModel, Package, Link, CollectorView, statusMap, statusMapReverse, formatSize - -def formatSpeed(speed): - speed = int(speed) - steps = 0 - sizes = ["B/s", "KiB/s", "MiB/s", "GiB/s"] - while speed > 1000: - speed /= 1024.0 - steps += 1 - return "%.2f %s" % (speed, sizes[steps]) +from module.remote.thriftbackend.ThriftClient import Destination +from module.gui.Collector import CollectorModel, Package, Link, CollectorView, statusMapReverse +from module.utils import formatSize, formatSpeed class QueueModel(CollectorModel): """ @@ -163,8 +154,8 @@ class QueueModel(CollectorModel): return QVariant(_("Status")) elif section == 1: return QVariant(_("Plugin")) - elif section == 3: - return QVariant(_("Priority")) + #elif section == 3: + # return QVariant(_("Priority")) elif section == 4: return QVariant(_("Size")) elif section == 5: @@ -204,11 +195,14 @@ class QueueModel(CollectorModel): since it's used in already locked calls, it provides an option to not lock """ + # TODO when 1 link complete wrong progress state if locked: locker = QMutexLocker(self.mutex) if isinstance(item, Link): try: - return int(item.data["progress"]) + if item.data["status"] == 0: + return 100 + return int(item.data["downloading"]["percent"]) except: return 0 elif isinstance(item, Package): @@ -216,9 +210,9 @@ class QueueModel(CollectorModel): perc_sum = 0 for child in item.children: try: - if child.data["status"] == 13: #processing - return int(child.data["progress"]) - perc_sum += int(child.data["progress"]) + #if child.data["status"] == 13: #processing + # return int(child.data["progress"]) + perc_sum += int(child.data["downloading"]["percent"]) except: pass if count == 0: @@ -285,16 +279,17 @@ class QueueModel(CollectorModel): return QVariant(self.translateStatus(statusMapReverse[status])) else: return QVariant("%s (%s)" % (self.translateStatus(statusMapReverse[status]), formatSpeed(speed))) - elif index.column() == 3: - item = index.internalPointer() - if isinstance(item, Package): - return QVariant(item.data["priority"]) - else: - return QVariant(item.package.data["priority"]) + #elif index.column() == 3: + # item = index.internalPointer() + # if isinstance(item, Package): + # return QVariant(item.data["priority"]) + # else: + # return QVariant(item.package.data["priority"]) elif index.column() == 4: item = index.internalPointer() if isinstance(item, Link): - if self.getProgress(item, False) == 100: + if item.data["status"] == 0: #TODO needs change?? + #self.getProgress(item, False) == 100: return QVariant(formatSize(item.data["size"])) elif self.getProgress(item, False) == 0: try: diff --git a/module/gui/SettingsWidget.py b/module/gui/SettingsWidget.py index c50130b5c..cd22a7b9e 100644 --- a/module/gui/SettingsWidget.py +++ b/module/gui/SettingsWidget.py @@ -20,7 +20,6 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * from sip import delete -from module.remote.thriftbackend.thriftgen.pyload.ttypes import * class SettingsWidget(QWidget): def __init__(self): @@ -142,6 +141,8 @@ class SettingsWidget(QWidget): if item.name in widget.inputs: i = widget.inputs[item.name] + #TODO : unresolved reference: option + if item.type == "int": if i.value() != int(item.value): self.connector.setConfigValue(k, option, i.value(), sec) diff --git a/module/gui/connector.py b/module/gui/connector.py index 8d2292aa3..91f23dafb 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -16,7 +16,7 @@ @author: mkaay """ -SERVER_VERSION = "0.4.6-dev" +SERVER_VERSION = "0.4.7" from time import sleep from uuid import uuid4 as uuid diff --git a/module/plugins/hoster/FileserveCom.py b/module/plugins/hoster/FileserveCom.py index 50470c3aa..ba76f0e39 100644 --- a/module/plugins/hoster/FileserveCom.py +++ b/module/plugins/hoster/FileserveCom.py @@ -86,6 +86,7 @@ class FileserveCom(Hoster): check = self.checkDownload({"login" : '<form action="/login.php" method="POST">'})
if check == "login":
+ self.account.relogin(self.user)
self.retry(reason=_("Not logged in."))
diff --git a/module/remote/thriftbackend/ThriftClient.py b/module/remote/thriftbackend/ThriftClient.py index 27cb89b0d..7e60d9fdc 100644 --- a/module/remote/thriftbackend/ThriftClient.py +++ b/module/remote/thriftbackend/ThriftClient.py @@ -15,9 +15,10 @@ from thrift.transport import TTransport from Socket import Socket from Protocol import Protocol +# modules should import ttypes from here, when want to avoid importing API + from thriftgen.pyload import Pyload from thriftgen.pyload.ttypes import * -from thriftgen.pyload.Pyload import PackageDoesNotExists, FileDoesNotExists ConnectionClosed = TTransport.TTransportException diff --git a/module/web/middlewares.py b/module/web/middlewares.py index a4b962988..e0e6c3102 100644 --- a/module/web/middlewares.py +++ b/module/web/middlewares.py @@ -25,7 +25,7 @@ class PrefixMiddleware(object): def __call__(self, e, h): path = e["PATH_INFO"] if path.startswith(self.prefix): - e['PATH_INFO'] = path.relace(self.prefix, "", 1) + e['PATH_INFO'] = path.replace(self.prefix, "", 1) return self.app(e, h) # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) diff --git a/module/web/webinterface.py b/module/web/webinterface.py index d2b96b03c..d6b7f8438 100644 --- a/module/web/webinterface.py +++ b/module/web/webinterface.py @@ -35,7 +35,7 @@ import bottle from bottle import run, app from jinja2 import Environment, FileSystemLoader, PrefixLoader, FileSystemBytecodeCache -from middlewares import StripPathMiddleware, GZipMiddleWare +from middlewares import StripPathMiddleware, GZipMiddleWare, PrefixMiddleware SETUP = None PYLOAD = None @@ -59,6 +59,14 @@ JS = JsEngine() TEMPLATE = config.get('webinterface', 'template') DL_ROOT = config.get('general', 'download_folder') LOG_ROOT = config.get('log', 'log_folder') +PREFIX = config.get('webinterface', 'prefix') + +if PREFIX: + if PREFIX.endswith("/"): + PREFIX = PREFIX[:1] + if not PREFIX.startswith("/"): + PREFIX = "/" + PREFIX + DEBUG = config.get("general","debug_mode") or "-d" in sys.argv or "--debug" in sys.argv bottle.debug(DEBUG) @@ -82,7 +90,10 @@ env.filters["path_make_absolute"] = path_make_absolute env.filters["decode"] = decode env.filters["type"] = lambda x: str(type(x)) env.filters["formatsize"] = formatSize - +if PREFIX: + env.filters["url"] = lambda x: x +else: + env.filters["url"] = lambda x: PREFIX + x if x.startswith("/") else x translation = gettext.translation("django", join(PYLOAD_DIR, "locale"), languages=["en", config.get("general","language")]) @@ -100,6 +111,10 @@ session_opts = { web = StripPathMiddleware(SessionMiddleware(app(), session_opts)) web = GZipMiddleWare(web) + +if PREFIX: + web = PrefixMiddleware(web, prefix=PREFIX) + #TODO: compress plugin, install(otfcompress) import pyload_app |