diff options
author | ardi69 <armin@diedering.de> | 2015-04-18 14:08:18 +0200 |
---|---|---|
committer | ardi69 <armin@diedering.de> | 2015-04-18 14:08:18 +0200 |
commit | 6e8f84e1dc06cff6fa9387559992f555182c1774 (patch) | |
tree | 476600f9896fae029880e4049eb4c5e6021b202d | |
parent | fix: config cast (diff) | |
parent | Spare code cosmetics (5) (diff) | |
download | pyload-6e8f84e1dc06cff6fa9387559992f555182c1774.tar.xz |
Merge pull request #3 from vuolter/0.4.10
merge vuolter HEAD
95 files changed, 742 insertions, 579 deletions
diff --git a/docs/build_docs.py b/docs/build_docs.py index 15fc2070d..8a7ab7a18 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -34,7 +34,9 @@ sys.path.append(dir_name) # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode'] +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.doctest', + 'sphinx.ext.intersphinx', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig', + 'sphinx.ext.viewcode'] autosummary_generate = True autodoc_default_flags = ['members'] @@ -201,8 +203,8 @@ htmlhelp_basename = 'pyLoaddoc' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'pyLoad.tex', u'pyLoad Documentation', - u'pyLoad Team', 'manual'), + ('index', 'pyLoad.tex', u'pyLoad Documentation', + u'pyLoad Team', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of diff --git a/docs/docs.conf b/docs/docs.conf index 51bab49fb..61a2c45ee 100644 --- a/docs/docs.conf +++ b/docs/docs.conf @@ -1,5 +1,5 @@ -# usage: epydoc --conf docs.conf , results goes to ~/.pyload/docs +#@NOTE: usage: epydoc --conf docs.conf , results goes to ~/.pyload/docs [epydoc] diff --git a/docs/write_addons.rst b/docs/write_addons.rst index 9f4436cc5..b7f6dfdb8 100644 --- a/docs/write_addons.rst +++ b/docs/write_addons.rst @@ -18,6 +18,7 @@ All addons should start with something like this: :: from pyload.plugin.Addon import Addon + class YourAddon(Addon): __name = "YourAddon" __version = "0.1" @@ -53,6 +54,7 @@ A basic excerpt would look like: :: from pyload.plugin.Addon import Addon + class YourAddon(Addon): """ Your Addon code here. @@ -61,6 +63,7 @@ A basic excerpt would look like: :: def activate(self): print "Yay, the core is ready let's do some work." + def downloadFinished(self, pyfile): print "A Download just finished." @@ -73,20 +76,25 @@ It requires a `dict` that maps event names to function names or a `list` of func from pyload.plugin.Addon import Addon + class YourAddon(Addon): """ Your Addon code here. """ + event_map = {'downloadFinished': "doSomeWork", 'allDownloadsFnished': "someMethod", 'activate': "initialize"} + def initialize(self): print "Initialized." + def doSomeWork(self, pyfile): print "This is equivalent to the above example." + def someMethod(self): print "The underlying event (allDownloadsFinished) for this method is not available through the base class" @@ -109,6 +117,7 @@ Sounds complicated but is very easy to do. Just use the ``Expose`` decorator: :: from pyload.plugin.Addon import Addon, Expose + class YourAddon(Addon): """ Your Addon code here. @@ -134,6 +143,7 @@ Just store everything in ``self.info``. :: from pyload.plugin.Addon import Addon + class YourAddon(Addon): """ Your Addon code here. @@ -142,6 +152,7 @@ Just store everything in ``self.info``. :: def setup(self): self.info = {'running': False} + def activate(self): self.info['running'] = True diff --git a/docs/write_plugins.rst b/docs/write_plugins.rst index 64868d638..af35a8d55 100644 --- a/docs/write_plugins.rst +++ b/docs/write_plugins.rst @@ -21,6 +21,7 @@ How basic hoster plugin header could look like: :: from pyload.plugin.Hoster import Hoster + class MyFileHoster(Hoster): __name = "MyFileHoster" __version = "0.1" @@ -43,6 +44,7 @@ An example ``process`` function could look like this :: from pyload.plugin.Hoster import Hoster + class MyFileHoster(Hoster): """ plugin code @@ -83,6 +85,7 @@ Example: :: from pyload.plugin.Crypter import Crypter + class MyFileCrypter(Crypter): """ plugin code diff --git a/locale/pavement.py b/locale/pavement.py index 5e24ce9f2..06a4f9775 100644 --- a/locale/pavement.py +++ b/locale/pavement.py @@ -101,6 +101,7 @@ xargs = ["--language=Python", "--add-comments=L10N", "--from-code=utf-8", "--copyright-holder=pyLoad Team", "--package-name=pyLoad", "--package-version=%s" % options.version, "--msgid-bugs-address='bugs@pyload.org'"] + @task @needs('cog') def html(): @@ -116,6 +117,8 @@ def html(): ('rev=', 'r', "HG revision"), ("clean", 'c', 'Delete old source folder') ]) + + def get_source(options): """ Downloads pyload source from bitbucket tip or given rev""" if options.rev: options.url = "https://bitbucket.org/spoob/pyload/get/%s.zip" % options.rev @@ -164,6 +167,8 @@ def sdist(): ('path=', 'p', 'Thrift path'), ('gen=', 'g', "Extra --gen option") ]) + + def thrift(options): """ Generate Thrift stubs """ @@ -190,6 +195,7 @@ def thrift(options): from pyload.remote.socketbackend.create_ttypes import main main() + @task def compile_js(): """ Compile .coffee files to javascript""" @@ -224,7 +230,8 @@ def generate_locale(): strings = set() for fi in path("pyload/web").walkfiles(): - if not fi.name.endswith(".js") and not fi.endswith(".coffee"): continue + if not fi.name.endswith(".js") and not fi.endswith(".coffee"): + continue with open(fi, "rb") as c: content = c.read() @@ -250,6 +257,8 @@ def generate_locale(): @cmdopts([ ('key=', 'k', 'api key') ]) + + def upload_translations(options): """ Uploads the locale files to translation server """ tmp = path(mkdtemp()) @@ -278,6 +287,8 @@ def upload_translations(options): @cmdopts([ ('key=', 'k', 'api key') ]) + + def download_translations(options): """ Downloads the translated files from translation server """ tmp = path(mkdtemp()) @@ -327,6 +338,7 @@ def compile_translations(): def tests(): call(["nosetests2"]) + @task def virtualenv(options): """Setup virtual environment""" @@ -362,12 +374,15 @@ def clean(): # helper functions + def walk_trans(path, EXCLUDE, endings=[".py"]): result = "" for f in path.walkfiles(): - if [True for x in EXCLUDE if x in f.dirname().relpath()]: continue - if f.name in EXCLUDE: continue + if [True for x in EXCLUDE if x in f.dirname().relpath()]: + continue + if f.name in EXCLUDE: + continue for e in endings: if f.name.endswith(e): diff --git a/pyload/Core.py b/pyload/Core.py index 4a919b689..e6f6fefcb 100755 --- a/pyload/Core.py +++ b/pyload/Core.py @@ -45,6 +45,7 @@ sys.stdout = getwriter(enc)(sys.stdout, errors="replace") # - configurable auth system ldap/mysql # - cron job like sheduler + class Core(object): """pyLoad Core, one tool to rule them all... (the filehosters) :D""" @@ -196,7 +197,8 @@ class Core(object): def isAlreadyRunning(self): pid = self.checkPidFile() - if not pid or os.name == "nt": return False + if not pid or os.name == "nt": + return False try: os.kill(pid, 0) # 0 - default signal (does nothing) except Exception: @@ -276,7 +278,8 @@ class Core(object): exit() try: signal.signal(signal.SIGQUIT, self.quit) - except Exception: pass + except Exception: + pass self.config = ConfigParser() @@ -353,7 +356,7 @@ class Core(object): self.setupDB() if self.config.oldRemoteData: self.log.info(_("Moving old user config to DB")) - self.db.addUser(self.config.oldRemoteData["username"], self.config.oldRemoteData["password"]) + self.db.addUser(self.config.oldRemoteData['username'], self.config.oldRemoteData['password']) self.log.info(_("Please check your logindata with ./pyload.py -u")) @@ -475,39 +478,69 @@ class Core(object): if self.config.get("log", "color_console"): import colorlog - if self.config.get("log", "color_template") == "label": - cfmt = "%(asctime)s %(log_color)s%(bold)s%(white)s %(levelname)-8s %(reset)s %(message)s" - clr = {'DEBUG' : "bg_cyan" , + color_template = self.config.get("log", "color_template") + extra_clr = {} + + if color_template is "mixed": + c_fmt = "%(log_color)s%(asctime)s %(label_log_color)s%(bold)s%(white)s %(levelname)-8s%(reset)s %(log_color)s%(message)s" + clr = { + 'DEBUG' : "cyan" , + 'WARNING' : "yellow", + 'ERROR' : "red" , + 'CRITICAL': "purple", + } + extra_clr = { + 'label': { + 'DEBUG' : "bg_cyan" , 'INFO' : "bg_green" , 'WARNING' : "bg_yellow", 'ERROR' : "bg_red" , - 'CRITICAL': "bg_purple"} - else: - cfmt = "%(log_color)s%(asctime)s %(levelname)-8s %(message)s" - clr = {'DEBUG' : "cyan" , - 'WARNING' : "yellow", - 'ERROR' : "red" , - 'CRITICAL': "purple"} + 'CRITICAL': "bg_purple", + } + } + + elif color_template is "label": + c_fmt = "%(asctime)s %(log_color)s%(bold)s%(white)s %(levelname)-8s%(reset)s %(message)s" + clr = { + 'DEBUG' : "bg_cyan" , + 'INFO' : "bg_green" , + 'WARNING' : "bg_yellow", + 'ERROR' : "bg_red" , + 'CRITICAL': "bg_purple", + } - console_frm = colorlog.ColoredFormatter(cfmt, date_fmt, clr) + else: + c_fmt = "%(log_color)s%(asctime)s %(levelname)-8s %(message)s" + clr = { + 'DEBUG' : "cyan" , + 'WARNING' : "yellow", + 'ERROR' : "red" , + 'CRITICAL': "purple" + } + + console_frm = colorlog.ColoredFormatter(format=c_fmt, + datefmt=date_fmt, + log_colors=clr, + secondary_log_colors=extra_clr) # Set console formatter console = logging.StreamHandler(sys.stdout) console.setFormatter(console_frm) self.log.addHandler(console) - if not exists(self.config.get("log", "log_folder")): - makedirs(self.config.get("log", "log_folder"), 0700) + log_folder = self.config.get("log", "log_folder") + if not exists(log_folder): + makedirs(log_folder, 0700) # Set file handler formatter if self.config.get("log", "file_log"): if self.config.get("log", "log_rotate"): - file_handler = logging.handlers.RotatingFileHandler(join(self.config.get("log", "log_folder"), 'log.txt'), + file_handler = logging.handlers.RotatingFileHandler(join(log_folder, 'log.txt'), maxBytes=self.config.get("log", "log_size") * 1024, backupCount=int(self.config.get("log", "log_count")), encoding="utf8") else: - file_handler = logging.FileHandler(join(self.config.get("log", "log_folder"), 'log.txt'), encoding="utf8") + file_handler = logging.FileHandler(join(log_folder, 'log.txt'), encoding="utf8") file_handler.setFormatter(fh_frm) self.log.addHandler(file_handler) diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py index 461c77cac..62af70cf8 100644 --- a/pyload/api/__init__.py +++ b/pyload/api/__init__.py @@ -92,65 +92,65 @@ class Api(Iface): def _convertPyFile(self, p): - fdata = FileData(p["id"], p["url"], p["name"], p["plugin"], p["size"], - p["format_size"], p["status"], p["statusmsg"], - p["package"], p["error"], p["order"]) + fdata = FileData(p['id'], p['url'], p['name'], p['plugin'], p['size'], + p['format_size'], p['status'], p['statusmsg'], + p['package'], p['error'], p['order']) return fdata def _convertConfigFormat(self, c): sections = {} for sectionName, sub in c.iteritems(): - section = ConfigSection(sectionName, sub["desc"]) + section = ConfigSection(sectionName, sub['desc']) items = [] for key, data in sub.iteritems(): if key in ("desc", "outline"): continue item = ConfigItem() item.name = key - item.description = data["desc"] - item.value = str(data["value"]) if not isinstance(data["value"], basestring) else data["value"] - item.type = data["type"] + item.description = data['desc'] + item.value = str(data['value']) if not isinstance(data['value'], basestring) else data['value'] + item.type = data['type'] items.append(item) section.items = items sections[sectionName] = section if "outline" in sub: - section.outline = sub["outline"] + section.outline = sub['outline'] return sections @permission(PERMS.SETTINGS) - def getConfigValue(self, category, option, section="core"): + def getConfigValue(self, section, option, section="core"): """Retrieve config value. - :param category: name of category, or plugin + :param section: name of section, or plugin :param option: config option :param section: 'plugin' or 'core' :return: config value as string """ if section == "core": - value = self.core.config.get(category, option) + value = self.core.config.get(section, option) else: - value = self.core.config.getPlugin(category, option) + value = self.core.config.getPlugin(section, option) return str(value) @permission(PERMS.SETTINGS) - def setConfigValue(self, category, option, value, section="core"): + def setConfigValue(self, section, option, value, section="core"): """Set new config value. - :param category: + :param section: :param option: :param value: new config value :param section: 'plugin' or 'core """ - self.core.addonManager.dispatchEvent("config-changed", category, option, value, section) + self.core.addonManager.dispatchEvent("config-changed", section, option, value, section) if section == "core": - self.core.config[category][option] = value + self.core.config.set(section, option, value) if option in ("limit_speed", "max_speed"): # not so nice to update the limit self.core.requestFactory.updateBucket() elif section == "plugin": - self.core.config.setPlugin(category, option, value) + self.core.config.setPlugin(section, option, value) @permission(PERMS.SETTINGS) @@ -424,7 +424,7 @@ class Api(Iface): """ result = self.core.threadManager.getInfoResult(rid) if "ALL_INFO_FETCHED" in result: - del result["ALL_INFO_FETCHED"] + del result['ALL_INFO_FETCHED'] return OnlineCheck(-1, result) else: return OnlineCheck(rid, result) @@ -475,9 +475,9 @@ class Api(Iface): data = self.core.files.getPackageData(int(pid)) if not data: raise PackageDoesNotExists(pid) - return PackageData(data["id"], data["name"], data["folder"], data["site"], data["password"], - data["queue"], data["order"], - links=[self._convertPyFile(x) for x in data["links"].itervalues()]) + return PackageData(data['id'], data['name'], data['folder'], data['site'], data['password'], + data['queue'], data['order'], + links=[self._convertPyFile(x) for x in data['links'].itervalues()]) @permission(PERMS.LIST) @@ -491,9 +491,9 @@ class Api(Iface): if not data: raise PackageDoesNotExists(pid) - return PackageData(data["id"], data["name"], data["folder"], data["site"], data["password"], - data["queue"], data["order"], - fids=[int(x) for x in data["links"]]) + return PackageData(data['id'], data['name'], data['folder'], data['site'], data['password'], + data['queue'], data['order'], + fids=[int(x) for x in data['links']]) @permission(PERMS.LIST) @@ -538,10 +538,10 @@ class Api(Iface): :return: list of `PackageInfo` """ - return [PackageData(pack["id"], pack["name"], pack["folder"], pack["site"], - pack["password"], pack["queue"], pack["order"], - pack["linksdone"], pack["sizedone"], pack["sizetotal"], - pack["linkstotal"]) + return [PackageData(pack['id'], pack['name'], pack['folder'], pack['site'], + pack['password'], pack['queue'], pack['order'], + pack['linksdone'], pack['sizedone'], pack['sizetotal'], + pack['linkstotal']) for pack in self.core.files.getInfoData(Destination.Queue).itervalues()] @@ -552,10 +552,10 @@ class Api(Iface): :return: list of `PackageData` """ - return [PackageData(pack["id"], pack["name"], pack["folder"], pack["site"], - pack["password"], pack["queue"], pack["order"], - pack["linksdone"], pack["sizedone"], pack["sizetotal"], - links=[self._convertPyFile(x) for x in pack["links"].itervalues()]) + return [PackageData(pack['id'], pack['name'], pack['folder'], pack['site'], + pack['password'], pack['queue'], pack['order'], + pack['linksdone'], pack['sizedone'], pack['sizetotal'], + links=[self._convertPyFile(x) for x in pack['links'].itervalues()]) for pack in self.core.files.getCompleteData(Destination.Queue).itervalues()] @@ -565,10 +565,10 @@ class Api(Iface): :return: list of `PackageInfo` """ - return [PackageData(pack["id"], pack["name"], pack["folder"], pack["site"], - pack["password"], pack["queue"], pack["order"], - pack["linksdone"], pack["sizedone"], pack["sizetotal"], - pack["linkstotal"]) + return [PackageData(pack['id'], pack['name'], pack['folder'], pack['site'], + pack['password'], pack['queue'], pack['order'], + pack['linksdone'], pack['sizedone'], pack['sizetotal'], + pack['linkstotal']) for pack in self.core.files.getInfoData(Destination.Collector).itervalues()] @@ -578,10 +578,10 @@ class Api(Iface): :return: list of `PackageInfo` """ - return [PackageData(pack["id"], pack["name"], pack["folder"], pack["site"], - pack["password"], pack["queue"], pack["order"], - pack["linksdone"], pack["sizedone"], pack["sizetotal"], - links=[self._convertPyFile(x) for x in pack["links"].itervalues()]) + return [PackageData(pack['id'], pack['name'], pack['folder'], pack['site'], + pack['password'], pack['queue'], pack['order'], + pack['linksdone'], pack['sizedone'], pack['sizetotal'], + links=[self._convertPyFile(x) for x in pack['links'].itervalues()]) for pack in self.core.files.getCompleteData(Destination.Collector).itervalues()] @@ -777,9 +777,9 @@ class Api(Iface): order = {} for pid in packs: pack = self.core.files.getPackageData(int(pid)) - while pack["order"] in order.keys(): # just in case - pack["order"] += 1 - order[pack["order"]] = pack["id"] + while pack['order'] in order.keys(): # just in case + pack['order'] += 1 + order[pack['order']] = pack['id'] return order @@ -792,10 +792,10 @@ class Api(Iface): """ rawdata = self.core.files.getPackageData(int(pid)) order = {} - for id, pyfile in rawdata["links"].iteritems(): - while pyfile["order"] in order.keys(): # just in case - pyfile["order"] += 1 - order[pyfile["order"]] = pyfile["id"] + for id, pyfile in rawdata['links'].iteritems(): + while pyfile['order'] in order.keys(): # just in case + pyfile['order'] += 1 + order[pyfile['order']] = pyfile['id'] return order @@ -894,8 +894,8 @@ class Api(Iface): """ accs = self.core.accountManager.getAccountInfos(False, refresh) for group in accs.values(): - accounts = [AccountInfo(acc["validuntil"], acc["login"], acc["options"], acc["valid"], - acc["trafficleft"], acc["maxtraffic"], acc["premium"], acc["type"]) + accounts = [AccountInfo(acc['validuntil'], acc['login'], acc['options'], acc['valid'], + acc['trafficleft'], acc['maxtraffic'], acc['premium'], acc['type']) for acc in group] return accounts or [] @@ -958,9 +958,9 @@ class Api(Iface): :param userdata: dictionary of user data :return: boolean """ - if userdata == "local" or userdata["role"] == ROLE.ADMIN: + if userdata == "local" or userdata['role'] == ROLE.ADMIN: return True - elif func in permMap and has_permission(userdata["permission"], permMap[func]): + elif func in permMap and has_permission(userdata['permission'], permMap[func]): return True else: return False @@ -971,14 +971,14 @@ class Api(Iface): """similar to `checkAuth` but returns UserData thrift type """ user = self.checkAuth(username, password) if user: - return UserData(user["name"], user["email"], user["role"], user["permission"], user["template"]) + return UserData(user['name'], user['email'], user['role'], user['permission'], user['template']) else: return UserData() def getAllUserData(self): """returns all known user and info""" - return dict((user, UserData(user, data["email"], data["role"], data["permission"], data["template"])) for user, data + return dict((user, UserData(user, data['email'], data['role'], data['permission'], data['template'])) for user, data in self.core.db.getAllUserData().iteritems()) diff --git a/pyload/api/types.py b/pyload/api/types.py index 10a64a813..2fd089333 100644 --- a/pyload/api/types.py +++ b/pyload/api/types.py @@ -2,13 +2,16 @@ # Autogenerated by pyload # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + class BaseObject(object): __slots__ = [] + class Destination(object): Collector = 0 Queue = 1 + class DownloadStatus(object): Aborted = 9 Custom = 11 @@ -26,10 +29,12 @@ class DownloadStatus(object): Unknown = 14 Waiting = 5 + class ElementType(object): File = 1 Package = 0 + class Input(object): BOOL = 4 CHOICE = 6 @@ -42,11 +47,13 @@ class Input(object): TEXT = 1 TEXTBOX = 2 + class Output(object): CAPTCHA = 1 NOTIFICATION = 4 QUESTION = 2 + class AccountInfo(BaseObject): __slots__ = ['validuntil', 'login', 'options', 'valid', 'trafficleft', 'maxtraffic', 'premium', 'type'] @@ -61,6 +68,7 @@ class AccountInfo(BaseObject): self.premium = premium self.type = type + class CaptchaTask(BaseObject): __slots__ = ['tid', 'data', 'type', 'resultType'] @@ -71,6 +79,7 @@ class CaptchaTask(BaseObject): self.type = type self.resultType = resultType + class ConfigItem(BaseObject): __slots__ = ['name', 'description', 'value', 'type'] @@ -81,6 +90,7 @@ class ConfigItem(BaseObject): self.value = value self.type = type + class ConfigSection(BaseObject): __slots__ = ['name', 'description', 'items', 'outline'] @@ -91,6 +101,7 @@ class ConfigSection(BaseObject): self.items = items self.outline = outline + class DownloadInfo(BaseObject): __slots__ = ['fid', 'name', 'speed', 'eta', 'format_eta', 'bleft', 'size', 'format_size', 'percent', 'status', 'statusmsg', 'format_wait', 'wait_until', 'packageID', 'packageName', 'plugin'] @@ -113,6 +124,7 @@ class DownloadInfo(BaseObject): self.packageName = packageName self.plugin = plugin + class EventInfo(BaseObject): __slots__ = ['eventname', 'id', 'type', 'destination'] @@ -123,6 +135,7 @@ class EventInfo(BaseObject): self.type = type self.destination = destination + class FileData(BaseObject): __slots__ = ['fid', 'url', 'name', 'plugin', 'size', 'format_size', 'status', 'statusmsg', 'packageID', 'error', 'order'] @@ -140,6 +153,7 @@ class FileData(BaseObject): self.error = error self.order = order + class FileDoesNotExists(Exception): __slots__ = ['fid'] @@ -147,6 +161,7 @@ class FileDoesNotExists(Exception): def __init__(self, fid=None): self.fid = fid + class InteractionTask(BaseObject): __slots__ = ['iid', 'input', 'structure', 'preset', 'output', 'data', 'title', 'description', 'plugin'] @@ -162,6 +177,7 @@ class InteractionTask(BaseObject): self.description = description self.plugin = plugin + class OnlineCheck(BaseObject): __slots__ = ['rid', 'data'] @@ -170,6 +186,7 @@ class OnlineCheck(BaseObject): self.rid = rid self.data = data + class OnlineStatus(BaseObject): __slots__ = ['name', 'plugin', 'packagename', 'status', 'size'] @@ -181,6 +198,7 @@ class OnlineStatus(BaseObject): self.status = status self.size = size + class PackageData(BaseObject): __slots__ = ['pid', 'name', 'folder', 'site', 'password', 'dest', 'order', 'linksdone', 'sizedone', 'sizetotal', 'linkstotal', 'links', 'fids'] @@ -200,6 +218,7 @@ class PackageData(BaseObject): self.links = links self.fids = fids + class PackageDoesNotExists(Exception): __slots__ = ['pid'] @@ -207,6 +226,7 @@ class PackageDoesNotExists(Exception): def __init__(self, pid=None): self.pid = pid + class ServerStatus(BaseObject): __slots__ = ['pause', 'active', 'queue', 'total', 'speed', 'download', 'reconnect'] @@ -220,6 +240,7 @@ class ServerStatus(BaseObject): self.download = download self.reconnect = reconnect + class ServiceCall(BaseObject): __slots__ = ['plugin', 'func', 'arguments', 'parseArguments'] @@ -230,6 +251,7 @@ class ServiceCall(BaseObject): self.arguments = arguments self.parseArguments = parseArguments + class ServiceDoesNotExists(Exception): __slots__ = ['plugin', 'func'] @@ -238,6 +260,7 @@ class ServiceDoesNotExists(Exception): self.plugin = plugin self.func = func + class ServiceException(Exception): __slots__ = ['msg'] @@ -245,6 +268,7 @@ class ServiceException(Exception): def __init__(self, msg=None): self.msg = msg + class UserData(BaseObject): __slots__ = ['name', 'email', 'role', 'permission', 'templateName'] @@ -256,6 +280,7 @@ class UserData(BaseObject): self.permission = permission self.templateName = templateName + class Iface(object): def addFiles(self, pid, links): diff --git a/pyload/cli/AddPackage.py b/pyload/cli/AddPackage.py index 131d0d7d7..e750274ca 100644 --- a/pyload/cli/AddPackage.py +++ b/pyload/cli/AddPackage.py @@ -21,7 +21,7 @@ class AddPackage(Handler): self.name = inp self.setInput() elif inp == "END": - #add package + # add package self.client.addPackage(self.name, self.urls, 1) self.cli.reset() else: diff --git a/pyload/cli/Cli.py b/pyload/cli/Cli.py index 4d6c3160d..84725b625 100644 --- a/pyload/cli/Cli.py +++ b/pyload/cli/Cli.py @@ -8,7 +8,7 @@ from getopt import GetoptError, getopt import pyload.utils.pylgettext as gettext import os from os import _exit -from os.path import join, exists, abspath, basename +from os.path import join, exists, basename import sys from sys import exit from threading import Thread, Lock @@ -19,6 +19,8 @@ from pyload.config.Parser import ConfigParser from codecs import getwriter +import module.common.pylgettext as gettext + if os.name == "nt": enc = "cp850" else: @@ -35,6 +37,7 @@ from pyload.remote.thriftbackend.ThriftClient import ThriftClient, NoConnection, from Getch import Getch from rename_process import renameProcess + class Cli(object): def __init__(self, client, command): @@ -51,9 +54,9 @@ class Cli(object): self.lock = Lock() - #processor funcions, these will be changed dynamically depending on control flow - self.headerHandler = self #the download status - self.bodyHandler = self #the menu section + # processor funcions, these will be changed dynamically depending on control flow + self.headerHandler = self # the download status + self.bodyHandler = self # the menu section self.inputHandler = self os.system("clear") @@ -77,7 +80,7 @@ class Cli(object): def start(self): """ main loop. handle input """ while True: - #inp = raw_input() + # inp = raw_input() inp = self.getch.impl() if ord(inp) == 3: os.system("clear") @@ -135,14 +138,14 @@ class Cli(object): def setHandler(self, klass): - #create new handler with reference to cli + # create new handler with reference to cli self.bodyHandler = self.inputHandler = klass(self) self.input = "" def renderHeader(self, line): """ prints download status """ - #print updated information + # print updated information # print "\033[J" #: clear screen # self.println(1, blue("py") + yellow("Load") + white(_(" Command Line Interface"))) # self.println(2, "") @@ -162,10 +165,10 @@ class Cli(object): println(line, cyan(download.name)) line += 1 println(line, - blue("[") + yellow(z * "#" + (25 - z) * " ") + blue("] ") + green(str(percent) + "%") + _( - " Speed: ") + green(formatSize(download.speed) + "/s") + _(" Size: ") + green( - download.format_size) + _(" Finished in: ") + green(download.format_eta) + _( - " ID: ") + green(download.fid)) + blue("[") + yellow(z * "#" + (25 - z) * " ") + blue("] ") + green(str(percent) + "%") + _( + " Speed: ") + green(formatSize(download.speed) + "/s") + _(" Size: ") + green( + download.format_size) + _(" Finished in: ") + green(download.format_eta) + _( + " ID: ") + green(download.fid)) line += 1 if download.status == 5: println(line, cyan(download.name)) @@ -181,7 +184,7 @@ class Cli(object): else: paused = _("Status:") + " " + red(_("running")) - println(line,"%s %s: %s %s: %s %s: %s" % ( + println(line, "%s %s: %s %s: %s %s: %s" % ( paused, _("total Speed"), red(formatSize(speed) + "/s"), _("Files in queue"), red( status.queue), _("Total"), red(status.total))) @@ -209,14 +212,14 @@ class Cli(object): println(line, white(" Input: ") + decode(self.input)) - #clear old output + # clear old output if line < self.lastLowestLine: for i in range(line + 1, self.lastLowestLine + 1): println(i, "") self.lastLowestLine = line - #set cursor to position + # set cursor to position print "\033[" + str(self.inputline) + ";0H" @@ -312,7 +315,6 @@ class Cli(object): rid = self.client.checkOnlineStatus(args).rid self.printOnlineCheck(self.client, rid) - elif command == "check_container": path = args[0] if not exists(join(owd, path)): @@ -326,7 +328,6 @@ class Cli(object): rid = self.client.checkOnlineStatusContainer([], basename(f.name), content).rid self.printOnlineCheck(self.client, rid) - elif command == "pause": self.client.pause() @@ -356,13 +357,17 @@ class Cli(object): sleep(1) result = client.pollResults(rid) for url, status in result.data.iteritems(): - if status.status == 2: check = "Online" - elif status.status == 1: check = "Offline" - else: check = "Unknown" + if status.status == 2: + check = "Online" + elif status.status == 1: + check = "Offline" + else: + check = "Unknown" print "%-45s %-12s\t %-15s\t %s" % (status.name, formatSize(status.size), status.plugin, check) - if result.rid == -1: break + if result.rid == -1: + break class RefreshThread(Thread): @@ -402,10 +407,10 @@ def print_help(config): print print " -u, --username=", " " * 2, "Specify Username" print " --pw=<password>", " " * 2, "Password" - print " -a, --address=", " " * 3, "Specify address (current=%s)" % config["addr"] - print " -p, --port", " " * 7, "Specify port (current=%s)" % config["port"] + print " -a, --address=", " " * 3, "Specify address (current=%s)" % config['addr'] + print " -p, --port", " " * 7, "Specify port (current=%s)" % config['port'] print - print " -l, --language", " " * 3, "Set user interface language (current=%s)" % config["language"] + print " -l, --language", " " * 3, "Set user interface language (current=%s)" % config['language'] print " -h, --help", " " * 7, "Display this help screen" print " -c, --commands", " " * 3, "List all available commands" print @@ -439,21 +444,21 @@ def print_status(download): def print_commands(): commands = [("status", _("Prints server status")), - ("queue", _("Prints downloads in queue")), - ("collector", _("Prints downloads in collector")), - ("add <name> <link1> <link2>...", _("Adds package to queue")), - ("add_coll <name> <link1> <link2>...", _("Adds package to collector")), - ("del_file <fid> <fid2>...", _("Delete Files from Queue/Collector")), - ("del_package <pid> <pid2>...", _("Delete Packages from Queue/Collector")), - ("move <pid> <pid2>...", _("Move Packages from Queue to Collector or vice versa")), - ("restart_file <fid> <fid2>...", _("Restart files")), - ("restart_package <pid> <pid2>...", _("Restart packages")), - ("check <container|url> ...", _("Check online status, works with local container")), - ("check_container path", _("Checks online status of a container file")), - ("pause", _("Pause the server")), - ("unpause", _("continue downloads")), - ("toggle", _("Toggle pause/unpause")), - ("kill", _("kill server")), ] + ("queue", _("Prints downloads in queue")), + ("collector", _("Prints downloads in collector")), + ("add <name> <link1> <link2>...", _("Adds package to queue")), + ("add_coll <name> <link1> <link2>...", _("Adds package to collector")), + ("del_file <fid> <fid2>...", _("Delete Files from Queue/Collector")), + ("del_package <pid> <pid2>...", _("Delete Packages from Queue/Collector")), + ("move <pid> <pid2>...", _("Move Packages from Queue to Collector or vice versa")), + ("restart_file <fid> <fid2>...", _("Restart files")), + ("restart_package <pid> <pid2>...", _("Restart packages")), + ("check <container|url> ...", _("Check online status, works with local container")), + ("check_container path", _("Checks online status of a container file")), + ("pause", _("Pause the server")), + ("unpause", _("continue downloads")), + ("toggle", _("Toggle pause/unpause")), + ("kill", _("kill server")), ] print _("List of commands:") print @@ -474,12 +479,12 @@ def writeConfig(opts): def main(): config = {"addr": "127.0.0.1", "port": "7227", "language": "en"} try: - config["language"] = os.environ["LANG"][0:2] + config['language'] = os.environ['LANG'][0:2] except Exception: pass - if (not exists(join(pypath, "locale", config["language"]))) or config["language"] == "": - config["language"] = "en" + if (not exists(join(pypath, "locale", config['language']))) or config['language'] == "": + config['language'] = "en" configFile = ConfigParser.ConfigParser() configFile.read(join(homedir, ".pyload-cli")) @@ -490,7 +495,7 @@ def main(): gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("Cli", join(pypath, "locale"), - languages=[config["language"], "en"], fallback=True) + languages=[config['language'], "en"], fallback=True) translation.install(unicode=True) interactive = False @@ -509,14 +514,14 @@ def main(): elif option in ("-u", "--username"): username = params elif option in ("-a", "--address"): - config["addr"] = params + config['addr'] = params elif option in ("-p", "--port"): - config["port"] = params + config['port'] = params elif option in ("-l", "--language"): - config["language"] = params + config['language'] = params gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("Cli", join(pypath, "locale"), - languages=[config["language"], "en"], fallback=True) + languages=[config['language'], "en"], fallback=True) translation.install(unicode=True) elif option in ("-h", "--help"): print_help(config) @@ -539,19 +544,19 @@ def main(): if interactive: try: - client = ThriftClient(config["addr"], int(config["port"]), username, password) + client = ThriftClient(config['addr'], int(config['port']), username, password) except WrongLogin: pass except NoSSL: print _("You need py-openssl to connect to this pyLoad Core.") exit() except NoConnection: - config["addr"] = False - config["port"] = False + config['addr'] = False + config['port'] = False if not client: - if not config["addr"]: config["addr"] = raw_input(_("Address: ")) - if not config["port"]: config["port"] = raw_input(_("Port: ")) + if not config['addr']: config['addr'] = raw_input(_("Address: ")) + if not config['port']: config['port'] = raw_input(_("Port: ")) if not username: username = raw_input(_("Username: ")) if not password: from getpass import getpass @@ -559,21 +564,21 @@ def main(): password = getpass(_("Password: ")) try: - client = ThriftClient(config["addr"], int(config["port"]), username, password) + client = ThriftClient(config['addr'], int(config['port']), username, password) except WrongLogin: print _("Login data is wrong.") except NoConnection: - print _("Could not establish connection to %(addr)s:%(port)s." % {"addr": config["addr"], - "port": config["port"]}) + print _("Could not establish connection to %(addr)s:%(port)s." % {"addr": config['addr'], + "port": config['port']}) else: try: - client = ThriftClient(config["addr"], int(config["port"]), username, password) + client = ThriftClient(config['addr'], int(config['port']), username, password) except WrongLogin: print _("Login data is wrong.") except NoConnection: - print _("Could not establish connection to %(addr)s:%(port)s." % {"addr": config["addr"], - "port": config["port"]}) + print _("Could not establish connection to %(addr)s:%(port)s." % {"addr": config['addr'], + "port": config['port']}) except NoSSL: print _("You need py-openssl to connect to this pyLoad core.") diff --git a/pyload/cli/Handler.py b/pyload/cli/Handler.py index 33e5dd8e6..444d7f6d0 100644 --- a/pyload/cli/Handler.py +++ b/pyload/cli/Handler.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # @author: RaNaN + class Handler(object): def __init__(self, cli): diff --git a/pyload/cli/ManageFiles.py b/pyload/cli/ManageFiles.py index 3bf8d1686..c010895c5 100644 --- a/pyload/cli/ManageFiles.py +++ b/pyload/cli/ManageFiles.py @@ -15,9 +15,10 @@ class ManageFiles(Handler): def init(self): self.target = Destination.Queue - self.pos = 0 #position in queue - self.package = -1 #choosen package + self.pos = 0 # position in queue + self.package = -1 # choosen package self.mode = "" # move/delete/restart + self.cache = None self.links = None self.time = 0 @@ -46,7 +47,7 @@ class ManageFiles(Handler): if input == "0": self.cli.reset() elif self.package < 0 and self.mode: - #mode select + # mode select packs = self.parseInput(input) if self.mode == "m": [self.client.movePackage((self.target + 1) % 2, x) for x in packs] @@ -56,7 +57,7 @@ class ManageFiles(Handler): [self.client.restartPackage(x) for x in packs] elif self.mode: - #edit links + # edit links links = self.parseInput(input, False) if self.mode == "d": @@ -65,7 +66,7 @@ class ManageFiles(Handler): map(self.client.restartFile, links) else: - #look into package + # look into package try: self.package = int(input) except Exception: @@ -102,7 +103,7 @@ class ManageFiles(Handler): line += 2 if self.package < 0: - #print package info + # print package info pack = self.getPackages() i = 0 for value in islice(pack, self.pos, self.pos + 5): @@ -110,13 +111,13 @@ class ManageFiles(Handler): println(line, mag(str(value.pid)) + ": " + value.name) line += 1 i += 1 - except Exception, e: + except Exception: pass - for x in range(5 - i): + for _i in range(5 - i): println(line, "") line += 1 else: - #print links info + # print links info pack = self.getLinks() i = 0 for value in islice(pack.links, self.pos, self.pos + 5): @@ -127,7 +128,7 @@ class ManageFiles(Handler): i += 1 except Exception, e: pass - for x in range(5 - i): + for _i in range(5 - i): println(line, "") line += 1 @@ -166,20 +167,12 @@ class ManageFiles(Handler): def parseInput(self, inp, package=True): inp = inp.strip() if "-" in inp: - l, n, h = inp.partition("-") - l = int(l) - h = int(h) - r = range(l, h + 1) + l, _, h = inp.partition("-") + r = range(int(l), int(h) + 1) - ret = [] if package: - for p in self.cache: - if p.pid in r: - ret.append(p.pid) - else: - for l in self.links.links: - if l.lid in r: - ret.append(l.lid) - return ret + return [p.pid for p in self.cache if p.pid in r] + return [l.lid for l in self.links.links if l.lid in r] + else: return [int(x) for x in inp.split(",")] diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py index bad512a5f..b26af6202 100644 --- a/pyload/config/Parser.py +++ b/pyload/config/Parser.py @@ -89,12 +89,12 @@ class ConfigParser(object): try: homeconf = self.parseConfig("pyload.conf") - if "username" in homeconf["remote"]: - if "password" in homeconf["remote"]: - self.oldRemoteData = {"username": homeconf["remote"]["username"]["value"], - "password": homeconf["remote"]["username"]["value"]} - del homeconf["remote"]["password"] - del homeconf["remote"]["username"] + if "username" in homeconf['remote']: + if "password" in homeconf['remote']: + self.oldRemoteData = {"username": homeconf['remote']['username']['value'], + "password": homeconf['remote']['username']['value']} + del homeconf['remote']['password'] + del homeconf['remote']['username'] self.updateValues(homeconf, self.config) except Exception: print "Config Warning" @@ -159,7 +159,7 @@ class ConfigParser(object): typ, none, option = content.strip().rpartition(" ") value = value.strip() - typ = typ.strip() + typ = typ.strip() if value.startswith("["): if value.endswith("]"): @@ -195,7 +195,7 @@ class ConfigParser(object): continue if option in dest[section]: - dest[section][option]["value"] = config[section][option]["value"] + dest[section][option]['value'] = config[section][option]['value'] # else: # dest[section][option] = config[section][option] @@ -211,25 +211,26 @@ class ConfigParser(object): chmod(filename, 0600) f.write("version: %i \n" % CONF_VERSION) for section in config.iterkeys(): - f.write('\n%s - "%s":\n' % (section, config[section]["desc"])) + f.write('\n%s - "%s":\n' % (section, config[section]['desc'])) for option, data in config[section].iteritems(): - if option in ("desc", "outline"): continue + if option in ("desc", "outline"): + continue - if isinstance(data["value"], list): + if isinstance(data['value'], list): value = "[ \n" - for x in data["value"]: + for x in data['value']: value += "\t\t" + str(x) + ",\n" value += "\t\t]\n" else: - if isinstance(data["value"], basestring): - value = data["value"] + "\n" + if isinstance(data['value'], basestring): + value = data['value'] + "\n" else: - value = str(data["value"]) + "\n" + value = str(data['value']) + "\n" try: - f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], value)) + f.write('\t%s %s : "%s" = %s' % (data['type'], option, data['desc'], value)) except UnicodeEncodeError: - f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], encode(value))) + f.write('\t%s %s : "%s" = %s' % (data['type'], option, data['desc'], encode(value))) def cast(self, typ, value): @@ -266,33 +267,31 @@ class ConfigParser(object): def get(self, section, option): """get value""" - value = self.config[section][option]["value"] + value = self.config[section][option]['value'] return decode(value) def set(self, section, option, value): """set value""" - - value = self.cast(self.config[section][option]["type"], value) - - self.config[section][option]["value"] = value + value = self.cast(self.config[section][option]['type'], value) + self.config[section][option]['value'] = value self.save() def getPlugin(self, plugin, option): """gets a value for a plugin""" - value = self.plugin[plugin][option]["value"] + value = self.plugin[plugin][option]['value'] return encode(value) def setPlugin(self, plugin, option, value): """sets a value for a plugin""" - value = self.cast(self.plugin[plugin][option]["type"], value) + value = self.cast(self.plugin[plugin][option]['type'], value) if self.pluginCB: self.pluginCB(plugin, option, value) - self.plugin[plugin][option]["value"] = value + self.plugin[plugin][option]['value'] = value self.save() @@ -315,12 +314,12 @@ class ConfigParser(object): self.plugin[name] = conf else: conf = self.plugin[name] - conf["outline"] = outline + conf['outline'] = outline for item in config: if item[0] in conf: - conf[item[0]]["type"] = item[1] - conf[item[0]]["desc"] = item[2] + conf[item[0]]['type'] = item[1] + conf[item[0]]['desc'] = item[2] else: conf[item[0]] = { "desc": item[2], diff --git a/pyload/config/default.conf b/pyload/config/default.conf index 453c40b4b..e07b92f68 100644 --- a/pyload/config/default.conf +++ b/pyload/config/default.conf @@ -21,13 +21,13 @@ webui - "Web User Interface": str prefix : "Path Prefix" = None log - "Log": - bool file_log : "File Log" = True - folder log_folder : "Folder" = Logs - int log_count : "Count" = 5 - int log_size : "Size in kb" = 100 - bool log_rotate : "Log Rotate" = True - bool color_console : "Colored console" = True - label;full color_template : "Color template" = label + bool file_log : "File Log" = True + folder log_folder : "Folder" = Logs + int log_count : "Count" = 5 + int log_size : "Size in kb" = 100 + bool log_rotate : "Log Rotate" = True + bool color_console : "Colored console" = True + label;line;mixed color_template : "Color template" = mixed general - "General": en;de;fr;it;es;nl;sv;ru;pl;cs;sr;pt_BR language : "Language" = en diff --git a/pyload/database/Backend.py b/pyload/database/Backend.py index 45a5c7361..b0e94711e 100644 --- a/pyload/database/Backend.py +++ b/pyload/database/Backend.py @@ -18,6 +18,7 @@ except Exception: DB_VERSION = 4 + class style(object): db = None @@ -59,6 +60,7 @@ class style(object): return cls.db.async(f, *args, **kwargs) return x + class DatabaseJob(object): def __init__(self, f, *args, **kwargs): @@ -79,7 +81,7 @@ class DatabaseJob(object): from os.path import basename frame = self.frame.f_back output = "" - for i in range(5): + for _i in range(5): output += "\t%s:%s, %s\n" % (basename(frame.f_code.co_filename), frame.f_lineno, frame.f_code.co_name) frame = frame.f_back del frame @@ -106,6 +108,7 @@ class DatabaseJob(object): def wait(self): self.done.wait() + class DatabaseBackend(Thread): subs = [] diff --git a/pyload/database/File.py b/pyload/database/File.py index 205cbba1a..7cbe1890a 100644 --- a/pyload/database/File.py +++ b/pyload/database/File.py @@ -87,12 +87,13 @@ class FileHandler(object): data.update([(x.id, x.toDbDict()[x.id]) for x in self.cache.values()]) for x in self.packageCache.itervalues(): - if x.queue != queue or x.id not in packs: continue + if x.queue != queue or x.id not in packs: + continue packs[x.id].update(x.toDict()[x.id]) for key, value in data.iteritems(): - if value["package"] in packs: - packs[value["package"]]["links"][key] = value + if value['package'] in packs: + packs[value['package']]['links'][key] = value return packs @@ -103,7 +104,8 @@ class FileHandler(object): packs = self.db.getAllPackages(queue) for x in self.packageCache.itervalues(): - if x.queue != queue or x.id not in packs: continue + if x.queue != queue or x.id not in packs: + continue packs[x.id].update(x.toDict()[x.id]) return packs @@ -277,11 +279,11 @@ class FileHandler(object): cache = self.cache.values() for x in cache: - if int(x.toDbDict()[x.id]["package"]) == int(id): + if int(x.toDbDict()[x.id]['package']) == int(id): tmplist.append((x.id, x.toDbDict()[x.id])) data.update(tmplist) - pack["links"] = data + pack['links'] = data return pack @@ -364,7 +366,7 @@ class FileHandler(object): if jobs: return self.getFile(jobs[0]) else: - self.jobCache["decrypt"] = "empty" + self.jobCache['decrypt'] = "empty" return None @@ -493,7 +495,8 @@ class FileHandler(object): packs = self.packageCache.values() for pack in packs: - if pack.queue != p.queue or pack.order < 0 or pack == p: continue + if pack.queue != p.queue or pack.order < 0 or pack == p: + continue if p.order > position: if pack.order >= position and pack.order < p.order: pack.order += 1 @@ -516,20 +519,21 @@ class FileHandler(object): f = self.getFileData(id) f = f[id] - e = RemoveEvent("file", id, "collector" if not self.getPackage(f["package"]).queue else "queue") + e = RemoveEvent("file", id, "collector" if not self.getPackage(f['package']).queue else "queue") self.core.pullManager.addEvent(e) self.db.reorderLink(f, position) pyfiles = self.cache.values() for pyfile in pyfiles: - if pyfile.packageid != f["package"] or pyfile.order < 0: continue - if f["order"] > position: - if pyfile.order >= position and pyfile.order < f["order"]: + if pyfile.packageid != f['package'] or pyfile.order < 0: + continue + if f['order'] > position: + if pyfile.order >= position and pyfile.order < f['order']: pyfile.order += 1 pyfile.notifyChange() - elif f["order"] < position: - if pyfile.order <= position and pyfile.order > f["order"]: + elif f['order'] < position: + if pyfile.order <= position and pyfile.order > f['order']: pyfile.order -= 1 pyfile.notifyChange() @@ -538,7 +542,7 @@ class FileHandler(object): self.db.commit() - e = InsertEvent("file", id, position, "collector" if not self.getPackage(f["package"]).queue else "queue") + e = InsertEvent("file", id, position, "collector" if not self.getPackage(f['package']).queue else "queue") self.core.pullManager.addEvent(e) @@ -568,8 +572,8 @@ class FileHandler(object): urls = [] for pyfile in data.itervalues(): - if pyfile["status"] not in (0, 12, 13): - urls.append((pyfile["url"], pyfile["plugin"])) + if pyfile['status'] not in (0, 12, 13): + urls.append((pyfile['url'], pyfile['plugin'])) self.core.threadManager.createInfoThread(urls, pid) @@ -842,12 +846,12 @@ class FileMethods(object): @style.queue def reorderLink(self, f, position): """ reorder link with f as dict for pyfile """ - if f["order"] > position: - self.c.execute('UPDATE links SET linkorder=linkorder+1 WHERE linkorder >= ? AND linkorder < ? AND package=?', (position, f["order"], f["package"])) - elif f["order"] < position: - self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder <= ? AND linkorder > ? AND package=?', (position, f["order"], f["package"])) + if f['order'] > position: + self.c.execute('UPDATE links SET linkorder=linkorder+1 WHERE linkorder >= ? AND linkorder < ? AND package=?', (position, f['order'], f['package'])) + elif f['order'] < position: + self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder <= ? AND linkorder > ? AND package=?', (position, f['order'], f['package'])) - self.c.execute('UPDATE links SET linkorder=? WHERE id=?', (position, f["id"])) + self.c.execute('UPDATE links SET linkorder=? WHERE id=?', (position, f['id'])) @style.queue @@ -871,7 +875,8 @@ class FileMethods(object): """return package instance from id""" self.c.execute("SELECT name, folder, site, password, queue, packageorder FROM packages WHERE id=?", (str(id),)) r = self.c.fetchone() - if not r: return None + if not r: + return None return PyPackage(self.manager, id, * r) @@ -882,7 +887,8 @@ class FileMethods(object): """return link instance from id""" self.c.execute("SELECT url, name, size, status, error, plugin, package, linkorder FROM links WHERE id=?", (str(id),)) r = self.c.fetchone() - if not r: return None + if not r: + return None r = list(r) r[5] = tuple(r[5].split('.')) return PyFile(self.manager, id, * r) diff --git a/pyload/database/Storage.py b/pyload/database/Storage.py index a1dfb7e9f..45ad18b2d 100644 --- a/pyload/database/Storage.py +++ b/pyload/database/Storage.py @@ -4,6 +4,7 @@ from pyload.database import style from pyload.database import DatabaseBackend + class StorageMethods(object): diff --git a/pyload/database/User.py b/pyload/database/User.py index 94f70d499..e11961e32 100644 --- a/pyload/database/User.py +++ b/pyload/database/User.py @@ -6,6 +6,7 @@ import random from pyload.database import DatabaseBackend, style + class UserMethods(object): @@ -29,7 +30,7 @@ class UserMethods(object): @style.queue def addUser(db, user, password): - salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for i in range(0, 5)]) + salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for _i in range(0, 5)]) h = sha1(salt + password) password = salt + h.hexdigest() @@ -52,7 +53,7 @@ class UserMethods(object): pw = r[2][5:] h = sha1(salt + oldpw) if h.hexdigest() == pw: - salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for i in range(0, 5)]) + salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for _i in range(0, 5)]) h = sha1(salt + newpw) password = salt + h.hexdigest() diff --git a/pyload/datatype/File.py b/pyload/datatype/File.py index 713442265..93aa636d7 100644 --- a/pyload/datatype/File.py +++ b/pyload/datatype/File.py @@ -217,7 +217,8 @@ class PyFile(object): """ formats and return wait time in humanreadable format """ seconds = self.waitUntil - time() - if seconds < 0: return "00:00:00" + if seconds < 0: + return "00:00:00" hours, seconds = divmod(seconds, 3600) minutes, seconds = divmod(seconds, 60) @@ -233,7 +234,8 @@ class PyFile(object): """ formats eta to readable format """ seconds = self.getETA() - if seconds < 0: return "00:00:00" + if seconds < 0: + return "00:00:00" hours, seconds = divmod(seconds, 3600) minutes, seconds = divmod(seconds, 60) diff --git a/pyload/datatype/Package.py b/pyload/datatype/Package.py index 7a36a1323..5ba42f596 100644 --- a/pyload/datatype/Package.py +++ b/pyload/datatype/Package.py @@ -4,6 +4,7 @@ from pyload.manager.Event import UpdateEvent from pyload.utils import safe_filename + class PyPackage(object): """ Represents a package object at runtime diff --git a/pyload/manager/Account.py b/pyload/manager/Account.py index 4e4a82aed..44a5e5c65 100644 --- a/pyload/manager/Account.py +++ b/pyload/manager/Account.py @@ -90,9 +90,12 @@ class AccountManager(object): for line in content[1:]: line = line.strip() - if not line: continue - if line.startswith("#"): continue - if line.startswith("version"): continue + if not line: + continue + if line.startswith("#"): + continue + if line.startswith("version"): + continue if line.endswith(":") and line.count(":") == 1: plugin = line[:-1] diff --git a/pyload/manager/Addon.py b/pyload/manager/Addon.py index cf23715b6..5ac56a349 100644 --- a/pyload/manager/Addon.py +++ b/pyload/manager/Addon.py @@ -41,8 +41,6 @@ class AddonManager(object): | Notes: | all_downloads-processed is *always* called before all_downloads-finished. | config-changed is *always* called before pluginConfigChanged. - - """ def __init__(self, core): diff --git a/pyload/manager/Event.py b/pyload/manager/Event.py index 90aaaca30..b3d22619f 100644 --- a/pyload/manager/Event.py +++ b/pyload/manager/Event.py @@ -4,6 +4,7 @@ from time import time from pyload.utils import uniqify + class PullManager(object): def __init__(self, core): @@ -41,6 +42,7 @@ class PullManager(object): for client in self.clients: client.addEvent(event) + class Client(object): def __init__(self, uuid): @@ -62,6 +64,7 @@ class Client(object): def addEvent(self, event): self.events.append(event) + class UpdateEvent(object): def __init__(self, itype, iid, destination): @@ -75,6 +78,7 @@ class UpdateEvent(object): def toList(self): return ["update", self.destination, self.type, self.id] + class RemoveEvent(object): def __init__(self, itype, iid, destination): @@ -88,6 +92,7 @@ class RemoveEvent(object): def toList(self): return ["remove", self.destination, self.type, self.id] + class InsertEvent(object): def __init__(self, itype, iid, after, destination): @@ -102,6 +107,7 @@ class InsertEvent(object): def toList(self): return ["insert", self.destination, self.type, self.id, self.after] + class ReloadAllEvent(object): def __init__(self, destination): @@ -112,11 +118,13 @@ class ReloadAllEvent(object): def toList(self): return ["reload", self.destination] + class AccountUpdateEvent(object): def toList(self): return ["account"] + class ConfigUpdateEvent(object): def toList(self): diff --git a/pyload/manager/Plugin.py b/pyload/manager/Plugin.py index 69a77fdf8..905ce524e 100644 --- a/pyload/manager/Plugin.py +++ b/pyload/manager/Plugin.py @@ -230,7 +230,7 @@ class PluginManager(object): elif name not in self.plugins[type]: self.core.log.warning(_("Plugin [%(type)s] %(name)s not found | Using plugin: [internal] BasePlugin") % {'name': name, 'type': type}) - return self.internalPlugins["BasePlugin"] + return self.internalPlugins['BasePlugin'] else: return self.plugins[type][name] @@ -313,7 +313,8 @@ class PluginManager(object): else: user = 0 # used as bool and int split = fullname.split(".") - if len(split) != 4 - user: return + if len(split) != 4 - user: + return type, name = split[2 - user:4 - user] if type in self.plugins and name in self.plugins[type]: diff --git a/pyload/manager/Remote.py b/pyload/manager/Remote.py index a27667070..c2d254932 100644 --- a/pyload/manager/Remote.py +++ b/pyload/manager/Remote.py @@ -4,6 +4,7 @@ from threading import Thread from traceback import print_exc + class BackendBase(Thread): def __init__(self, manager): @@ -43,7 +44,7 @@ class BackendBase(Thread): def stop(self): - self.enabled = False# set flag and call shutdowm message, so thread can react + self.enabled = False #: set flag and call shutdowm message, so thread can react self.shutdown() @@ -57,8 +58,8 @@ class RemoteManager(object): if self.core.remote: self.available.append("ThriftBackend") -# else: -# self.available.append("SocketBackend") + # else: + # self.available.append("SocketBackend") def startBackends(self): diff --git a/pyload/manager/Thread.py b/pyload/manager/Thread.py index 015bc9ab1..a8550e504 100644 --- a/pyload/manager/Thread.py +++ b/pyload/manager/Thread.py @@ -51,7 +51,7 @@ class ThreadManager(object): pycurl.global_init(pycurl.GLOBAL_DEFAULT) - for i in range(0, self.core.config.get("download", "max_downloads")): + for _i in range(0, self.core.config.get("download", "max_downloads")): self.createThread() @@ -160,9 +160,9 @@ class ThreadManager(object): if not exists(self.core.config.get("reconnect", "method")): if exists(join(pypath, self.core.config.get("reconnect", "method"))): - self.core.config['reconnect']['method'] = join(pypath, self.core.config.get("reconnect", "method")) + self.core.config.set("reconnect", "method", join(pypath, self.core.config.get("reconnect", "method"))) else: - self.core.config['reconnect']['activated'] = False + self.core.config.set("reconnect", "activated", False) self.core.log.warning(_("Reconnect script not found!")) return @@ -184,7 +184,7 @@ class ThreadManager(object): reconn = Popen(self.core.config.get("reconnect", "method"), bufsize=-1, shell=True) # , stdout=subprocess.PIPE) except Exception: self.core.log.warning(_("Failed executing reconnect script!")) - self.core.config['reconnect']['activated'] = False + self.core.config.set("reconnect", "activated", False) self.reconnecting.clear() if self.core.debug: print_exc() @@ -206,7 +206,7 @@ class ThreadManager(object): ("http://checkip.dyndns.org/", ".*Current IP Address: (\S+)</body>.*")] ip = "" - for i in range(10): + for _i in range(10): try: sv = choice(services) ip = getURL(sv[0]) @@ -250,10 +250,12 @@ class ThreadManager(object): def assignJob(self): """assing a job to a thread if possible""" - if self.pause or not self.core.api.isTimeDownload(): return + if self.pause or not self.core.api.isTimeDownload(): + return # if self.downloaded > 20: - # if not self.cleanPyCurl(): return + # if not self.cleanPyCurl(): + return free = [x for x in self.threads if not x.active] @@ -285,7 +287,7 @@ class ThreadManager(object): if free and not self.pause: thread = free[0] - #self.downloaded += 1 + # self.downloaded += 1 thread.put(job) else: @@ -299,7 +301,6 @@ class ThreadManager(object): if job: job.initPlugin() thread = DecrypterThread(self, job) - else: thread = DecrypterThread(self, job) diff --git a/pyload/manager/thread/Addon.py b/pyload/manager/thread/Addon.py index f3d219989..1da164543 100644 --- a/pyload/manager/thread/Addon.py +++ b/pyload/manager/thread/Addon.py @@ -55,14 +55,14 @@ class AddonThread(PluginThread): def run(self): try: try: - self.kwargs["thread"] = self + self.kwargs['thread'] = self self.f(*self.args, **self.kwargs) except TypeError, e: #dirty method to filter out exceptions if "unexpected keyword argument 'thread'" not in e.args[0]: raise - del self.kwargs["thread"] + del self.kwargs['thread'] self.f(*self.args, **self.kwargs) finally: local = copy(self.active) diff --git a/pyload/manager/thread/Info.py b/pyload/manager/thread/Info.py index 487c3b924..28a2e8e91 100644 --- a/pyload/manager/thread/Info.py +++ b/pyload/manager/thread/Info.py @@ -117,7 +117,7 @@ class InfoThread(PluginThread): self.updateResult(pluginname, result, True) - self.m.infoResults[self.rid]["ALL_INFO_FETCHED"] = {} + self.m.infoResults[self.rid]['ALL_INFO_FETCHED'] = {} self.m.timestamp = time() + 5 * 60 diff --git a/pyload/manager/thread/Server.py b/pyload/manager/thread/Server.py index 990325f5d..83e886253 100644 --- a/pyload/manager/thread/Server.py +++ b/pyload/manager/thread/Server.py @@ -66,7 +66,7 @@ class WebServer(threading.Thread): self.server = "builtin" else: self.core.log.info(_("Server set to threaded, due to known performance problems on windows.")) - self.core.config['webui']['server'] = "threaded" + self.core.config.set("webui", "server", "threaded") self.server = "threaded" if self.server == "threaded": diff --git a/pyload/network/Browser.py b/pyload/network/Browser.py index fab7454f3..d8617fabc 100644 --- a/pyload/network/Browser.py +++ b/pyload/network/Browser.py @@ -68,7 +68,8 @@ class Browser(object): @property def percent(self): - if not self.size: return 0 + if not self.size: + return 0 return (self.arrived * 100) / self.size @@ -118,12 +119,12 @@ class Browser(object): :param pwd: string, user:password """ - self.options["auth"] = pwd + self.options['auth'] = pwd self.renewHTTPRequest() #: we need a new request def removeAuth(self): - if "auth" in self.options: del self.options["auth"] + if "auth" in self.options: del self.options['auth'] self.renewHTTPRequest() diff --git a/pyload/network/CookieJar.py b/pyload/network/CookieJar.py index 35d7fa6ef..a970a08e5 100644 --- a/pyload/network/CookieJar.py +++ b/pyload/network/CookieJar.py @@ -24,8 +24,8 @@ class CookieJar(Cookie.SimpleCookie): def setCookie(self, domain, name, value, path="/", exp=None, secure="FALSE"): self[name] = value - self[name]["domain"] = domain - self[name]["path"] = path + self[name]['domain'] = domain + self[name]['path'] = path # Value of expires should be integer if possible # otherwise the cookie won't be used @@ -37,7 +37,7 @@ class CookieJar(Cookie.SimpleCookie): except ValueError: expires = exp - self[name]["expires"] = expires + self[name]['expires'] = expires if secure == "TRUE": - self[name]["secure"] = secure + self[name]['secure'] = secure diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py index 82e1ca76e..784b64349 100644 --- a/pyload/network/HTTPChunk.py +++ b/pyload/network/HTTPChunk.py @@ -12,6 +12,7 @@ import urllib from pyload.network.HTTPRequest import HTTPRequest + class WrongFormat(Exception): pass @@ -176,7 +177,8 @@ class HTTPChunk(HTTPRequest): if self.range: # do nothing if chunk already finished - if self.arrived + self.range[0] >= self.range[1]: return None + if self.arrived + self.range[0] >= self.range[1]: + return None if self.id == len(self.p.info.chunks) - 1: #: as last chunk dont set end range, so we get everything range = "%i-" % (self.arrived + self.range[0]) diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py index 32c165f82..13666195a 100644 --- a/pyload/network/HTTPDownload.py +++ b/pyload/network/HTTPDownload.py @@ -72,7 +72,8 @@ class HTTPDownload(object): @property def percent(self): - if not self.size: return 0 + if not self.size: + return 0 return (self.arrived * 100) / self.size @@ -134,7 +135,8 @@ class HTTPDownload(object): finally: self.close() - if self.nameDisposition and self.disposition: return self.nameDisposition + if self.nameDisposition and self.disposition: + return self.nameDisposition return None @@ -295,7 +297,8 @@ class HTTPDownload(object): def findChunk(self, handle): """ linear search to find a chunk (should be ok since chunk size is usually low) """ for chunk in self.chunks: - if chunk.c == handle: return chunk + if chunk.c == handle: + return chunk def closeChunk(self, chunk): diff --git a/pyload/network/HTTPRequest.py b/pyload/network/HTTPRequest.py index 3e5903df3..62c0ef72b 100644 --- a/pyload/network/HTTPRequest.py +++ b/pyload/network/HTTPRequest.py @@ -93,24 +93,24 @@ class HTTPRequest(object): def setInterface(self, options): - interface, proxy, ipv6 = options["interface"], options["proxies"], options["ipv6"] + interface, proxy, ipv6 = options['interface'], options['proxies'], options['ipv6'] if interface and interface.lower() != "none": self.c.setopt(pycurl.INTERFACE, str(interface)) if proxy: - if proxy["type"] == "socks4": + if proxy['type'] == "socks4": self.c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS4) - elif proxy["type"] == "socks5": + elif proxy['type'] == "socks5": self.c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5) else: self.c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_HTTP) - self.c.setopt(pycurl.PROXY, str(proxy["address"])) - self.c.setopt(pycurl.PROXYPORT, proxy["port"]) + self.c.setopt(pycurl.PROXY, str(proxy['address'])) + self.c.setopt(pycurl.PROXYPORT, proxy['port']) - if proxy["username"]: - self.c.setopt(pycurl.PROXYUSERPWD, str("%s:%s" % (proxy["username"], proxy["password"]))) + if proxy['username']: + self.c.setopt(pycurl.PROXYUSERPWD, str("%s:%s" % (proxy['username'], proxy['password']))) if ipv6: self.c.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_WHATEVER) @@ -118,10 +118,10 @@ class HTTPRequest(object): self.c.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_V4) if "auth" in options: - self.c.setopt(pycurl.USERPWD, str(options["auth"])) + self.c.setopt(pycurl.USERPWD, str(options['auth'])) if "timeout" in options: - self.c.setopt(pycurl.LOW_SPEED_TIME, options["timeout"]) + self.c.setopt(pycurl.LOW_SPEED_TIME, options['timeout']) def addCookies(self): diff --git a/pyload/network/RequestFactory.py b/pyload/network/RequestFactory.py index a80882088..0591c5162 100644 --- a/pyload/network/RequestFactory.py +++ b/pyload/network/RequestFactory.py @@ -10,6 +10,7 @@ from pyload.network.CookieJar import CookieJar from pyload.network.XDCCRequest import XDCCRequest + class RequestFactory(object): def __init__(self, core): @@ -121,6 +122,7 @@ class RequestFactory(object): else: self.bucket.setRate(self.core.config.get("download", "max_speed") * 1024) + # needs pyreq in global namespace def getURL(*args, **kwargs): return pyreq.getURL(*args, **kwargs) diff --git a/pyload/network/XDCCRequest.py b/pyload/network/XDCCRequest.py index 01fc2ea78..dff500749 100644 --- a/pyload/network/XDCCRequest.py +++ b/pyload/network/XDCCRequest.py @@ -34,10 +34,10 @@ class XDCCRequest(object): # proxy = None # if self.proxies.has_key("socks5"): # proxytype = socks.PROXY_TYPE_SOCKS5 - # proxy = self.proxies["socks5"] + # proxy = self.proxies['socks5'] # elif self.proxies.has_key("socks4"): # proxytype = socks.PROXY_TYPE_SOCKS4 - # proxy = self.proxies["socks4"] + # proxy = self.proxies['socks4'] # if proxytype: # sock = socks.socksocket() # t = _parse_proxy(proxy) @@ -145,7 +145,8 @@ class XDCCRequest(object): @property def percent(self): - if not self.filesize: return 0 + if not self.filesize: + return 0 return (self.recv * 100) / self.filesize diff --git a/pyload/plugin/Account.py b/pyload/plugin/Account.py index 23f15e8fd..c46eae5e3 100644 --- a/pyload/plugin/Account.py +++ b/pyload/plugin/Account.py @@ -166,7 +166,7 @@ class Account(Base): infos['timestamp'] = time() self.infos[name] = infos - elif "timestamp" in self.infos[name] and self.infos[name]["timestamp"] + self.info_threshold * 60 < time(): + elif "timestamp" in self.infos[name] and self.infos[name]['timestamp'] + self.info_threshold * 60 < time(): self.logDebug("Reached timeout for account data") self.scheduleRefresh(name) @@ -231,7 +231,8 @@ class Account(Base): """ returns an valid account name and data""" usable = [] for user, data in self.accounts.iteritems(): - if not data['valid']: continue + if not data['valid']: + continue if "time" in data['options'] and data['options']['time']: time_data = "" @@ -253,7 +254,8 @@ class Account(Base): usable.append((user, data)) - if not usable: return None, None + if not usable: + return None, None return choice(usable) diff --git a/pyload/plugin/Addon.py b/pyload/plugin/Addon.py index 35f010f29..bb90428e4 100644 --- a/pyload/plugin/Addon.py +++ b/pyload/plugin/Addon.py @@ -16,7 +16,6 @@ class Expose(object): def threaded(fn): - def run(*args,**kwargs): addonManager.startThread(fn, *args, **kwargs) diff --git a/pyload/plugin/Plugin.py b/pyload/plugin/Plugin.py index c18e16643..54963447c 100644 --- a/pyload/plugin/Plugin.py +++ b/pyload/plugin/Plugin.py @@ -57,6 +57,7 @@ class Base(object): A Base class with log/config/db methods *all* plugin types can use """ + def __init__(self, core): #: Core instance self.core = core @@ -568,7 +569,8 @@ class Plugin(Base): header = {"code": self.req.code} for line in res.splitlines(): line = line.strip() - if not line or ":" not in line: continue + if not line or ":" not in line: + continue key, none, value = line.partition(":") key = key.strip().lower() @@ -693,8 +695,10 @@ class Plugin(Base): size = stat(lastDownload) size = size.st_size - if api_size and api_size <= size: return None - elif size > max_size and not read_size: return None + if api_size and api_size <= size: + return None + elif size > max_size and not read_size: + return None self.logDebug("Download Check triggered") with open(lastDownload, "rb") as f: @@ -720,7 +724,8 @@ class Plugin(Base): def getPassword(self): """ get the password the user provided in the package""" password = self.pyfile.package().password - if not password: return "" + if not password: + return "" return password diff --git a/pyload/plugin/account/NoPremiumPl.py b/pyload/plugin/account/NoPremiumPl.py index d825b38ed..6cefed550 100644 --- a/pyload/plugin/account/NoPremiumPl.py +++ b/pyload/plugin/account/NoPremiumPl.py @@ -37,16 +37,16 @@ class NoPremiumPl(Account): try: result = json_loads(self.runAuthQuery()) except Exception: - # todo: return or let it be thrown? + #@TODO: return or let it be thrown? return premium = False valid_untill = -1 - if "expire" in result.keys() and result["expire"]: + if "expire" in result.keys() and result['expire']: premium = True - valid_untill = time.mktime(datetime.datetime.fromtimestamp(int(result["expire"])).timetuple()) - traffic_left = result["balance"] * 2 ** 20 + valid_untill = time.mktime(datetime.datetime.fromtimestamp(int(result['expire'])).timetuple()) + traffic_left = result['balance'] * 2 ** 20 return ({ "validuntil": valid_untill, @@ -57,7 +57,7 @@ class NoPremiumPl(Account): def login(self, user, data, req): self._usr = user - self._pwd = hashlib.sha1(hashlib.md5(data["password"]).hexdigest()).hexdigest() + self._pwd = hashlib.sha1(hashlib.md5(data['password']).hexdigest()).hexdigest() self._req = req try: @@ -73,8 +73,8 @@ class NoPremiumPl(Account): def createAuthQuery(self): query = self._api_query - query["username"] = self._usr - query["password"] = self._pwd + query['username'] = self._usr + query['password'] = self._pwd return query diff --git a/pyload/plugin/account/OboomCom.py b/pyload/plugin/account/OboomCom.py index 68e083d75..8b33d0612 100644 --- a/pyload/plugin/account/OboomCom.py +++ b/pyload/plugin/account/OboomCom.py @@ -8,6 +8,7 @@ try: except ImportError: from beaker.crypto.pbkdf2 import pbkdf2 from binascii import b2a_hex + class PBKDF2(object): def __init__(self, passphrase, salt, iterations=1000): diff --git a/pyload/plugin/account/RapideoPl.py b/pyload/plugin/account/RapideoPl.py index d40c76cb5..c58414b53 100644 --- a/pyload/plugin/account/RapideoPl.py +++ b/pyload/plugin/account/RapideoPl.py @@ -37,16 +37,16 @@ class RapideoPl(Account): try: result = json_loads(self.runAuthQuery()) except Exception: - # todo: return or let it be thrown? + #@TODO: return or let it be thrown? return premium = False valid_untill = -1 - if "expire" in result.keys() and result["expire"]: + if "expire" in result.keys() and result['expire']: premium = True - valid_untill = time.mktime(datetime.datetime.fromtimestamp(int(result["expire"])).timetuple()) + valid_untill = time.mktime(datetime.datetime.fromtimestamp(int(result['expire'])).timetuple()) - traffic_left = result["balance"] + traffic_left = result['balance'] return ({ "validuntil": valid_untill, @@ -57,7 +57,7 @@ class RapideoPl(Account): def login(self, user, data, req): self._usr = user - self._pwd = hashlib.md5(data["password"]).hexdigest() + self._pwd = hashlib.md5(data['password']).hexdigest() self._req = req try: response = json_loads(self.runAuthQuery()) @@ -72,8 +72,8 @@ class RapideoPl(Account): def createAuthQuery(self): query = self._api_query - query["username"] = self._usr - query["password"] = self._pwd + query['username'] = self._usr + query['password'] = self._pwd return query diff --git a/pyload/plugin/account/SmoozedCom.py b/pyload/plugin/account/SmoozedCom.py index 7f4beb7d9..f24799caf 100644 --- a/pyload/plugin/account/SmoozedCom.py +++ b/pyload/plugin/account/SmoozedCom.py @@ -9,6 +9,7 @@ try: except ImportError: from beaker.crypto.pbkdf2 import pbkdf2 from binascii import b2a_hex + class PBKDF2(object): def __init__(self, passphrase, salt, iterations=1000): @@ -46,10 +47,10 @@ class SmoozedCom(Account): 'premium' : False} else: # Parse account info - info = {'validuntil' : float(status["data"]["user"]["user_premium"]), - 'trafficleft': max(0, status["data"]["traffic"][1] - status["data"]["traffic"][0]), - 'session' : status["data"]["session_key"], - 'hosters' : [hoster["name"] for hoster in status["data"]["hoster"]]} + info = {'validuntil' : float(status['data']['user']['user_premium']), + 'trafficleft': max(0, status['data']['traffic'][1] - status['data']['traffic'][0]), + 'session' : status['data']['session_key'], + 'hosters' : [hoster['name'] for hoster in status['data']['hoster']]} if info['validuntil'] < time.time(): info['premium'] = False diff --git a/pyload/plugin/account/UploadableCh.py b/pyload/plugin/account/UploadableCh.py index 15717db44..c95fe7f0b 100644 --- a/pyload/plugin/account/UploadableCh.py +++ b/pyload/plugin/account/UploadableCh.py @@ -25,7 +25,7 @@ class UploadableCh(Account): def login(self, user, data, req): html = req.load("http://www.uploadable.ch/login.php", post={'userName' : user, - 'userPassword' : data["password"], + 'userPassword' : data['password'], 'autoLogin' : "1", 'action__login': "normalLogin"}, decode=True) diff --git a/pyload/plugin/account/WebshareCz.py b/pyload/plugin/account/WebshareCz.py index 47dfed255..5cbe6b1b8 100644 --- a/pyload/plugin/account/WebshareCz.py +++ b/pyload/plugin/account/WebshareCz.py @@ -51,7 +51,7 @@ class WebshareCz(Account): self.wrongPassword() salt = re.search('<salt>(.+)</salt>', salt).group(1) - password = sha1(md5_crypt.encrypt(data["password"], salt=salt)).hexdigest() + password = sha1(md5_crypt.encrypt(data['password'], salt=salt)).hexdigest() digest = md5(user + ":Webshare:" + password).hexdigest() login = req.load("https://webshare.cz/api/login/", diff --git a/pyload/plugin/account/ZeveraCom.py b/pyload/plugin/account/ZeveraCom.py index 25c2c5512..1e5eacb4c 100644 --- a/pyload/plugin/account/ZeveraCom.py +++ b/pyload/plugin/account/ZeveraCom.py @@ -19,11 +19,6 @@ class ZeveraCom(Account): HOSTER_DOMAIN = "zevera.com" - def __init__(self, manager, accounts): #@TODO: remove in 0.4.10 - self.init() - return super(ZeveraCom, self).__init__(manager, accounts) - - def init(self): if not self.HOSTER_DOMAIN: self.logError(_("Missing HOSTER_DOMAIN")) diff --git a/pyload/plugin/addon/UnSkipOnFail.py b/pyload/plugin/addon/UnSkipOnFail.py index 7fa9ef4e2..048547a1b 100644 --- a/pyload/plugin/addon/UnSkipOnFail.py +++ b/pyload/plugin/addon/UnSkipOnFail.py @@ -7,7 +7,7 @@ from pyload.plugin.Addon import Addon class UnSkipOnFail(Addon): __name = "UnSkipOnFail" __type = "addon" - __version = "0.06" + __version = "0.07" __config = [("activated", "bool", "Activated", True)] @@ -25,9 +25,9 @@ class UnSkipOnFail(Addon): msg = _("Looking for skipped duplicates of: %s (pid:%s)") self.logInfo(msg % (pyfile.name, pyfile.package().id)) - dup = self.findDuplicate(pyfile) - if dup: - self.logInfo(_("Queue found duplicate: %s (pid:%s)") % (dup.name, dup.packageID)) + link = self.findDuplicate(pyfile) + if link: + self.logInfo(_("Queue found duplicate: %s (pid:%s)") % (link.name, link.packageID)) #: Change status of "link" to "new_status". # "link" has to be a valid FileData object, diff --git a/pyload/plugin/addon/XMPPInterface.py b/pyload/plugin/addon/XMPPInterface.py index 2733cfde0..c977042e6 100644 --- a/pyload/plugin/addon/XMPPInterface.py +++ b/pyload/plugin/addon/XMPPInterface.py @@ -210,7 +210,6 @@ class XMPPInterface(IRCInterface, JabberClient): class VersionHandler(object): """Provides handler for a version query. - This class will answer version query and announce 'jabber:iq:version' namespace in the client's disco#info results.""" diff --git a/pyload/plugin/extractor/SevenZip.py b/pyload/plugin/extractor/SevenZip.py index b6d86adab..9d01965e0 100644 --- a/pyload/plugin/extractor/SevenZip.py +++ b/pyload/plugin/extractor/SevenZip.py @@ -139,8 +139,8 @@ class SevenZip(UnRar): args.append("-y") #set a password - if "password" in kwargs and kwargs["password"]: - args.append("-p%s" % kwargs["password"]) + if "password" in kwargs and kwargs['password']: + args.append("-p%s" % kwargs['password']) else: args.append("-p-") diff --git a/pyload/plugin/hook/Captcha9Kw.py b/pyload/plugin/hook/Captcha9Kw.py index 9cb8e7928..bbf283623 100644 --- a/pyload/plugin/hook/Captcha9Kw.py +++ b/pyload/plugin/hook/Captcha9Kw.py @@ -138,7 +138,7 @@ class Captcha9kw(Hook): self.logDebug(_("NewCaptchaID ticket: %s") % res, task.captchaFile) - task.data["ticket"] = res + task.data['ticket'] = res for _i in xrange(int(self.getConfig('timeout') / 5)): result = getURL(self.API_URL, @@ -231,7 +231,7 @@ class Captcha9kw(Hook): 'correct': "1" if correct else "2", 'pyload' : "1", 'source' : "pyload", - 'id' : task.data["ticket"]}) + 'id' : task.data['ticket']}) self.logDebug("Request %s: %s" % (type, res)) diff --git a/pyload/plugin/hook/NoPremiumPl.py b/pyload/plugin/hook/NoPremiumPl.py index 05bd6c0ba..527413a88 100644 --- a/pyload/plugin/hook/NoPremiumPl.py +++ b/pyload/plugin/hook/NoPremiumPl.py @@ -22,7 +22,7 @@ class NoPremiumPl(MultiHook): def getHosters(self): hostings = json_loads(self.getURL("https://www.nopremium.pl/clipboard.php?json=3").strip()) - hostings_domains = [domain for row in hostings for domain in row["domains"] if row["sdownload"] == "0"] + hostings_domains = [domain for row in hostings for domain in row['domains'] if row['sdownload'] == "0"] self.logDebug(hostings_domains) diff --git a/pyload/plugin/hook/RapideoPl.py b/pyload/plugin/hook/RapideoPl.py index a850c7710..1761659db 100644 --- a/pyload/plugin/hook/RapideoPl.py +++ b/pyload/plugin/hook/RapideoPl.py @@ -22,7 +22,7 @@ class RapideoPl(MultiHook): def getHosters(self): hostings = json_loads(self.getURL("https://www.rapideo.pl/clipboard.php?json=3").strip()) - hostings_domains = [domain for row in hostings for domain in row["domains"] if row["sdownload"] == "0"] + hostings_domains = [domain for row in hostings for domain in row['domains'] if row['sdownload'] == "0"] self.logDebug(hostings_domains) diff --git a/pyload/plugin/hook/XFileSharingPro.py b/pyload/plugin/hook/XFileSharingPro.py index 1f3a27fd5..3c16c618a 100644 --- a/pyload/plugin/hook/XFileSharingPro.py +++ b/pyload/plugin/hook/XFileSharingPro.py @@ -82,7 +82,7 @@ class XFileSharingPro(Hook): pattern = self.regexp[type][1] % match_list.replace('.', '\.') - dict = self.core.pluginManager.plugins[type]["XFileSharingPro"] + dict = self.core.pluginManager.plugins[type]['XFileSharingPro'] dict['pattern'] = pattern dict['re'] = re.compile(pattern) @@ -90,7 +90,7 @@ class XFileSharingPro(Hook): def _unload(self, type): - dict = self.core.pluginManager.plugins[type]["XFileSharingPro"] + dict = self.core.pluginManager.plugins[type]['XFileSharingPro'] dict['pattern'] = r'^unmatchable$' dict['re'] = re.compile(dict['pattern']) diff --git a/pyload/plugin/hoster/BitshareCom.py b/pyload/plugin/hoster/BitshareCom.py index afea970eb..0d26c2d53 100644 --- a/pyload/plugin/hoster/BitshareCom.py +++ b/pyload/plugin/hoster/BitshareCom.py @@ -114,7 +114,7 @@ class BitshareCom(SimpleHoster): recaptcha = ReCaptcha(self) # Try up to 3 times - for i in xrange(3): + for _i in xrange(3): response, challenge = recaptcha.challenge() res = self.load("http://bitshare.com/files-ajax/" + self.file_id + "/request.html", post={"request" : "validateCaptcha", diff --git a/pyload/plugin/hoster/MegaRapidoNet.py b/pyload/plugin/hoster/MegaRapidoNet.py index d0c3ad917..311189d1c 100644 --- a/pyload/plugin/hoster/MegaRapidoNet.py +++ b/pyload/plugin/hoster/MegaRapidoNet.py @@ -8,7 +8,7 @@ from pyload.plugin.internal.MultiHoster import MultiHoster def random_with_N_digits(n): rand = "0." not_zero = 0 - for i in range(1, n + 1): + for _i in range(1, n + 1): r = randint(0, 9) if(r > 0): not_zero += 1 diff --git a/pyload/plugin/hoster/NoPremiumPl.py b/pyload/plugin/hoster/NoPremiumPl.py index 109932721..8921afe1c 100644 --- a/pyload/plugin/hoster/NoPremiumPl.py +++ b/pyload/plugin/hoster/NoPremiumPl.py @@ -46,9 +46,9 @@ class NoPremiumPl(MultiHoster): def runFileQuery(self, url, mode=None): query = self.API_QUERY.copy() - query["username"] = self.usr - query["password"] = self.pwd - query["url"] = url + query['username'] = self.usr + query['password'] = self.pwd + query['url'] = url if mode == "fileinfo": query['check'] = 2 @@ -77,24 +77,24 @@ class NoPremiumPl(MultiHoster): self.logDebug(parsed) if "errno" in parsed.keys(): - if parsed["errno"] in self.ERROR_CODES: + if parsed['errno'] in self.ERROR_CODES: # error code in known - self.fail(self.ERROR_CODES[parsed["errno"]] % self.__class__.__name__) + self.fail(self.ERROR_CODES[parsed['errno']] % self.__class__.__name__) else: # error code isn't yet added to plugin self.fail( - parsed["errstring"] - or _("Unknown error (code: %s)") % parsed["errno"] + parsed['errstring'] + or _("Unknown error (code: %s)") % parsed['errno'] ) if "sdownload" in parsed: - if parsed["sdownload"] == "1": + if parsed['sdownload'] == "1": self.fail( _("Download from %s is possible only using NoPremium.pl website \ - directly") % parsed["hosting"]) + directly") % parsed['hosting']) - pyfile.name = parsed["filename"] - pyfile.size = parsed["filesize"] + pyfile.name = parsed['filename'] + pyfile.size = parsed['filesize'] try: self.link = self.runFileQuery(pyfile.url, 'filedownload') diff --git a/pyload/plugin/hoster/RapideoPl.py b/pyload/plugin/hoster/RapideoPl.py index 70e3fd853..e19ccc45b 100644 --- a/pyload/plugin/hoster/RapideoPl.py +++ b/pyload/plugin/hoster/RapideoPl.py @@ -46,9 +46,9 @@ class RapideoPl(MultiHoster): def runFileQuery(self, url, mode=None): query = self.API_QUERY.copy() - query["username"] = self.usr - query["password"] = self.pwd - query["url"] = url + query['username'] = self.usr + query['password'] = self.pwd + query['url'] = url if mode == "fileinfo": query['check'] = 2 @@ -77,24 +77,24 @@ class RapideoPl(MultiHoster): self.logDebug(parsed) if "errno" in parsed.keys(): - if parsed["errno"] in self.ERROR_CODES: + if parsed['errno'] in self.ERROR_CODES: # error code in known - self.fail(self.ERROR_CODES[parsed["errno"]] % self.__class__.__name__) + self.fail(self.ERROR_CODES[parsed['errno']] % self.__class__.__name__) else: # error code isn't yet added to plugin self.fail( - parsed["errstring"] - or _("Unknown error (code: %s)") % parsed["errno"] + parsed['errstring'] + or _("Unknown error (code: %s)") % parsed['errno'] ) if "sdownload" in parsed: - if parsed["sdownload"] == "1": + if parsed['sdownload'] == "1": self.fail( _("Download from %s is possible only using Rapideo.pl website \ - directly") % parsed["hosting"]) + directly") % parsed['hosting']) - pyfile.name = parsed["filename"] - pyfile.size = parsed["filesize"] + pyfile.name = parsed['filename'] + pyfile.size = parsed['filesize'] try: self.link = self.runFileQuery(pyfile.url, 'filedownload') diff --git a/pyload/plugin/hoster/SimplyPremiumCom.py b/pyload/plugin/hoster/SimplyPremiumCom.py index 51b5ac577..327bfdcc1 100644 --- a/pyload/plugin/hoster/SimplyPremiumCom.py +++ b/pyload/plugin/hoster/SimplyPremiumCom.py @@ -46,7 +46,7 @@ class SimplyPremiumCom(MultiHoster): def handlePremium(self, pyfile): - for i in xrange(5): + for _i in xrange(5): self.html = self.load("http://www.simply-premium.com/premium.php", get={'info': "", 'link': self.pyfile.url}) if self.html: diff --git a/pyload/plugin/hoster/SmoozedCom.py b/pyload/plugin/hoster/SmoozedCom.py index 6d62cef23..1ed3a539d 100644 --- a/pyload/plugin/hoster/SmoozedCom.py +++ b/pyload/plugin/hoster/SmoozedCom.py @@ -35,17 +35,17 @@ class SmoozedCom(MultiHoster): data = json_loads(self.load("http://www2.smoozed.com/api/check", get=get_data)) - if data["state"] != "ok": - self.fail(data["message"]) + if data['state'] != "ok": + self.fail(data['message']) - if data["data"].get("state", "ok") != "ok": - if data["data"] == "Offline": + if data['data'].get("state", "ok") != "ok": + if data['data'] == "Offline": self.offline() else: - self.fail(data["data"]["message"]) + self.fail(data['data']['message']) - pyfile.name = data["data"]["name"] - pyfile.size = int(data["data"]["size"]) + pyfile.name = data['data']['name'] + pyfile.size = int(data['data']['size']) # Start the download header = self.load("http://www2.smoozed.com/api/download", get=get_data, just_header=True) @@ -53,7 +53,7 @@ class SmoozedCom(MultiHoster): if not "location" in header: self.fail(_("Unable to initialize download")) else: - self.link = header["location"][-1] if isinstance(header["location"], list) else header["location"] + self.link = header['location'][-1] if isinstance(header['location'], list) else header['location'] def checkFile(self, rules={}): diff --git a/pyload/plugin/hoster/UpstoreNet.py b/pyload/plugin/hoster/UpstoreNet.py index 27fc68dc6..adf63e382 100644 --- a/pyload/plugin/hoster/UpstoreNet.py +++ b/pyload/plugin/hoster/UpstoreNet.py @@ -43,7 +43,7 @@ class UpstoreNet(SimpleHoster): recaptcha = ReCaptcha(self) # try the captcha 5 times - for i in xrange(5): + for _i in xrange(5): m = re.search(self.WAIT_PATTERN, self.html) if m is None: self.error(_("Wait pattern not found")) diff --git a/pyload/plugin/hoster/WebshareCz.py b/pyload/plugin/hoster/WebshareCz.py index 11b7b37b0..49a8da89f 100644 --- a/pyload/plugin/hoster/WebshareCz.py +++ b/pyload/plugin/hoster/WebshareCz.py @@ -34,7 +34,7 @@ class WebshareCz(SimpleHoster): if 'File not found' in api_data: info['status'] = 1 else: - info["status"] = 2 + info['status'] = 2 info['name'] = re.search('<name>(.+)</name>', api_data).group(1) or info['name'] info['size'] = re.search('<size>(.+)</size>', api_data).group(1) or info['size'] diff --git a/pyload/plugin/hoster/Xdcc.py b/pyload/plugin/hoster/Xdcc.py index f2b5d0b8f..42491404f 100644 --- a/pyload/plugin/hoster/Xdcc.py +++ b/pyload/plugin/hoster/Xdcc.py @@ -117,7 +117,7 @@ class Xdcc(Hoster): sock.send("PRIVMSG %s :xdcc send #%s\r\n" % (bot, pack)) else: - if (dl_time + self.timeout) < time.time(): # todo: add in config + if (dl_time + self.timeout) < time.time(): #@TODO: add in config sock.send("QUIT :byebye\r\n") sock.close() self.fail(_("XDCC Bot did not answer")) diff --git a/pyload/plugin/hoster/ZippyshareCom.py b/pyload/plugin/hoster/ZippyshareCom.py index a062df458..dd78071c9 100644 --- a/pyload/plugin/hoster/ZippyshareCom.py +++ b/pyload/plugin/hoster/ZippyshareCom.py @@ -88,5 +88,5 @@ class ZippyshareCom(SimpleHoster): scripts = ['\n'.join(('try{', script, '} catch(err){}')) for script in scripts] # get the file's url by evaluating all the scripts - scripts = ['var GVAR = {}'] + list(initScripts) + scripts + ['GVAR["dlbutton_href"]'] + scripts = ['var GVAR = {}'] + list(initScripts) + scripts + ['GVAR['dlbutton_href']'] return self.js.eval('\n'.join(scripts)) diff --git a/pyload/plugin/internal/SimpleHoster.py b/pyload/plugin/internal/SimpleHoster.py index add54786f..930f5a313 100644 --- a/pyload/plugin/internal/SimpleHoster.py +++ b/pyload/plugin/internal/SimpleHoster.py @@ -418,7 +418,7 @@ class SimpleHoster(Hoster): self.info = {} self.html = "" - self.link = "" #@TODO: Move to hoster class in 0.4.10 + self.link = "" #@TODO: Move to hoster class in 0.4.10 self.directDL = False #@TODO: Move to hoster class in 0.4.10 self.multihost = False #@TODO: Move to hoster class in 0.4.10 @@ -652,9 +652,8 @@ class SimpleHoster(Hoster): self.checkStatus(getinfo=False) - #: Deprecated - + #: Deprecated def getFileInfo(self): self.info = {} self.checkInfo() diff --git a/pyload/remote/ClickNLoadBackend.py b/pyload/remote/ClickNLoadBackend.py index 31678ab8b..5c08986a7 100644 --- a/pyload/remote/ClickNLoadBackend.py +++ b/pyload/remote/ClickNLoadBackend.py @@ -18,6 +18,7 @@ from pyload.manager.Remote import BackendBase core = None js = None + class ClickNLoadBackend(BackendBase): def setup(self, host, port): @@ -31,6 +32,7 @@ class ClickNLoadBackend(BackendBase): while self.enabled: self.httpd.handle_request() + class CNLHandler(BaseHTTPRequestHandler): def add_package(self, name, urls, queue=0): diff --git a/pyload/remote/SocketBackend.py b/pyload/remote/SocketBackend.py index 6b88663f8..8b74d19ff 100644 --- a/pyload/remote/SocketBackend.py +++ b/pyload/remote/SocketBackend.py @@ -4,6 +4,7 @@ import SocketServer from pyload.manager.Remote import BackendBase + class RequestHandler(SocketServer.BaseRequestHandler): def setup(self): @@ -11,15 +12,13 @@ class RequestHandler(SocketServer.BaseRequestHandler): def handle(self): - print self.request.recv(1024) - class SocketBackend(BackendBase): def setup(self, host, port): - #local only + # local only self.server = SocketServer.ThreadingTCPServer(("localhost", port), RequestHandler) diff --git a/pyload/remote/ThriftBackend.py b/pyload/remote/ThriftBackend.py index 0ac7f1bb5..a6f1841e2 100644 --- a/pyload/remote/ThriftBackend.py +++ b/pyload/remote/ThriftBackend.py @@ -13,6 +13,7 @@ from pyload.remote.thriftbackend.Transport import TransportFactory from thrift.server import TServer + class ThriftBackend(BackendBase): def setup(self, host, port): diff --git a/pyload/remote/socketbackend/create_ttypes.py b/pyload/remote/socketbackend/create_ttypes.py index 72bc4c231..9b001f1bf 100644 --- a/pyload/remote/socketbackend/create_ttypes.py +++ b/pyload/remote/socketbackend/create_ttypes.py @@ -37,6 +37,7 @@ def main(): # Autogenerated by pyload # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + class BaseObject(object): \t__slots__ = [] @@ -48,7 +49,8 @@ class BaseObject(object): f.write("class %s:\n" % name) for attr in dir(enum): - if attr.startswith("_") or attr in ("read", "write"): continue + if attr.startswith("_") or attr in ("read", "write"): + continue f.write("\t%s = %s\n" % (attr, getattr(enum, attr))) @@ -72,7 +74,8 @@ class BaseObject(object): f.write("class Iface(object):\n") for name in dir(Iface): - if name.startswith("_"): continue + if name.startswith("_"): + continue func = inspect.getargspec(getattr(Iface, name)) diff --git a/pyload/remote/thriftbackend/Processor.py b/pyload/remote/thriftbackend/Processor.py index 24a0c05b6..7ccc2bee2 100644 --- a/pyload/remote/thriftbackend/Processor.py +++ b/pyload/remote/thriftbackend/Processor.py @@ -2,6 +2,7 @@ from pyload.remote.thriftbackend.thriftgen.pyload import Pyload + class Processor(Pyload.Processor): def __init__(self, *args, **kwargs): @@ -66,7 +67,7 @@ class Processor(Pyload.Processor): self._processMap[name](self, seqid, iprot, oprot) else: - #no permission + # no permission iprot.skip(Pyload.TType.STRUCT) iprot.readMessageEnd() # 21 - Not authorized diff --git a/pyload/remote/thriftbackend/Protocol.py b/pyload/remote/thriftbackend/Protocol.py index c020e7a23..ecf0680ad 100644 --- a/pyload/remote/thriftbackend/Protocol.py +++ b/pyload/remote/thriftbackend/Protocol.py @@ -2,12 +2,13 @@ from thrift.protocol import TBinaryProtocol + class Protocol(TBinaryProtocol.TBinaryProtocol): def writeString(self, str): try: str = str.encode("utf8", "ignore") - except Exception, e: + except Exception: pass self.writeI32(len(str)) diff --git a/pyload/remote/thriftbackend/Socket.py b/pyload/remote/thriftbackend/Socket.py index 7d078ab93..3d2435a92 100644 --- a/pyload/remote/thriftbackend/Socket.py +++ b/pyload/remote/thriftbackend/Socket.py @@ -10,32 +10,33 @@ from thrift.transport.TSocket import TSocket, TServerSocket, TTransportException WantReadError = Exception #: overwritten when ssl is used + class SecureSocketConnection(object): def __init__(self, connection): - self.__dict__["connection"] = connection + self.__dict__['connection'] = connection def __getattr__(self, name): - return getattr(self.__dict__["connection"], name) + return getattr(self.__dict__['connection'], name) def __setattr__(self, name, value): - setattr(self.__dict__["connection"], name, value) + setattr(self.__dict__['connection'], name, value) def shutdown(self, how=1): - self.__dict__["connection"].shutdown() + self.__dict__['connection'].shutdown() def accept(self): - connection, address = self.__dict__["connection"].accept() + connection, address = self.__dict__['connection'].accept() return SecureSocketConnection(connection), address def send(self, buff): try: - return self.__dict__["connection"].send(buff) + return self.__dict__['connection'].send(buff) except WantReadError: sleep(0.1) return self.send(buff) @@ -43,11 +44,12 @@ class SecureSocketConnection(object): def recv(self, buff): try: - return self.__dict__["connection"].recv(buff) + return self.__dict__['connection'].recv(buff) except WantReadError: sleep(0.1) return self.recv(buff) + class Socket(TSocket): def __init__(self, host='localhost', port=7228, ssl=False): diff --git a/pyload/remote/thriftbackend/ThriftClient.py b/pyload/remote/thriftbackend/ThriftClient.py index 60a4e9ca9..4f1c8dcc2 100644 --- a/pyload/remote/thriftbackend/ThriftClient.py +++ b/pyload/remote/thriftbackend/ThriftClient.py @@ -18,15 +18,19 @@ from pyload.remote.thriftbackend.thriftgen.pyload.ttypes import * ConnectionClosed = TTransport.TTransportException + class WrongLogin(Exception): pass + class NoConnection(Exception): pass + class NoSSL(Exception): pass + class ThriftClient(object): def __init__(self, host="localhost", port=7227, user="", password=""): diff --git a/pyload/remote/thriftbackend/ThriftTest.py b/pyload/remote/thriftbackend/ThriftTest.py index fb8dd03c9..0c5ea4783 100644 --- a/pyload/remote/thriftbackend/ThriftTest.py +++ b/pyload/remote/thriftbackend/ThriftTest.py @@ -22,9 +22,10 @@ from time import time import xmlrpclib + def bench(f, *args, **kwargs): s = time() - ret = [f(*args, **kwargs) for i in range(0, 100)] + ret = [f(*args, **kwargs) for _i in range(0, 100)] e = time() try: print "%s: %f s" % (f._Method__name, e-s) diff --git a/pyload/remote/thriftbackend/Transport.py b/pyload/remote/thriftbackend/Transport.py index 7ecb16746..1d3d81718 100644 --- a/pyload/remote/thriftbackend/Transport.py +++ b/pyload/remote/thriftbackend/Transport.py @@ -3,6 +3,7 @@ from thrift.transport.TTransport import TBufferedTransport from thrift.transport.TZlibTransport import TZlibTransport + class Transport(TBufferedTransport): DEFAULT_BUFFER = 4096 @@ -12,6 +13,7 @@ class Transport(TBufferedTransport): self.handle = trans.handle self.remoteaddr = trans.handle.getpeername() + class TransportCompressed(TZlibTransport): DEFAULT_BUFFER = 4096 @@ -21,12 +23,14 @@ class TransportCompressed(TZlibTransport): self.handle = trans.handle self.remoteaddr = trans.handle.getpeername() + class TransportFactory(object): def getTransport(self, trans): buffered = Transport(trans) return buffered + class TransportFactoryCompressed(object): _last_trans = None _last_z = None diff --git a/pyload/remote/thriftbackend/thriftgen/pyload/Pyload.py b/pyload/remote/thriftbackend/thriftgen/pyload/Pyload.py index a5e730c35..1ba11dbb6 100644 --- a/pyload/remote/thriftbackend/thriftgen/pyload/Pyload.py +++ b/pyload/remote/thriftbackend/thriftgen/pyload/Pyload.py @@ -2705,76 +2705,76 @@ class Processor(Iface, TProcessor): def __init__(self, handler): self._handler = handler self._processMap = {} - self._processMap["getConfigValue"] = Processor.process_getConfigValue - self._processMap["setConfigValue"] = Processor.process_setConfigValue - self._processMap["getConfig"] = Processor.process_getConfig - self._processMap["getPluginConfig"] = Processor.process_getPluginConfig - self._processMap["pauseServer"] = Processor.process_pauseServer - self._processMap["unpauseServer"] = Processor.process_unpauseServer - self._processMap["togglePause"] = Processor.process_togglePause - self._processMap["statusServer"] = Processor.process_statusServer - self._processMap["freeSpace"] = Processor.process_freeSpace - self._processMap["getServerVersion"] = Processor.process_getServerVersion - self._processMap["kill"] = Processor.process_kill - self._processMap["restart"] = Processor.process_restart - self._processMap["getLog"] = Processor.process_getLog - self._processMap["isTimeDownload"] = Processor.process_isTimeDownload - self._processMap["isTimeReconnect"] = Processor.process_isTimeReconnect - self._processMap["toggleReconnect"] = Processor.process_toggleReconnect - self._processMap["generatePackages"] = Processor.process_generatePackages - self._processMap["checkURLs"] = Processor.process_checkURLs - self._processMap["parseURLs"] = Processor.process_parseURLs - self._processMap["checkOnlineStatus"] = Processor.process_checkOnlineStatus - self._processMap["checkOnlineStatusContainer"] = Processor.process_checkOnlineStatusContainer - self._processMap["pollResults"] = Processor.process_pollResults - self._processMap["statusDownloads"] = Processor.process_statusDownloads - self._processMap["getPackageData"] = Processor.process_getPackageData - self._processMap["getPackageInfo"] = Processor.process_getPackageInfo - self._processMap["getFileData"] = Processor.process_getFileData - self._processMap["getQueue"] = Processor.process_getQueue - self._processMap["getCollector"] = Processor.process_getCollector - self._processMap["getQueueData"] = Processor.process_getQueueData - self._processMap["getCollectorData"] = Processor.process_getCollectorData - self._processMap["getPackageOrder"] = Processor.process_getPackageOrder - self._processMap["getFileOrder"] = Processor.process_getFileOrder - self._processMap["generateAndAddPackages"] = Processor.process_generateAndAddPackages - self._processMap["addPackage"] = Processor.process_addPackage - self._processMap["addFiles"] = Processor.process_addFiles - self._processMap["uploadContainer"] = Processor.process_uploadContainer - self._processMap["deleteFiles"] = Processor.process_deleteFiles - self._processMap["deletePackages"] = Processor.process_deletePackages - self._processMap["pushToQueue"] = Processor.process_pushToQueue - self._processMap["pullFromQueue"] = Processor.process_pullFromQueue - self._processMap["restartPackage"] = Processor.process_restartPackage - self._processMap["restartFile"] = Processor.process_restartFile - self._processMap["recheckPackage"] = Processor.process_recheckPackage - self._processMap["stopAllDownloads"] = Processor.process_stopAllDownloads - self._processMap["stopDownloads"] = Processor.process_stopDownloads - self._processMap["setPackageName"] = Processor.process_setPackageName - self._processMap["movePackage"] = Processor.process_movePackage - self._processMap["moveFiles"] = Processor.process_moveFiles - self._processMap["orderPackage"] = Processor.process_orderPackage - self._processMap["orderFile"] = Processor.process_orderFile - self._processMap["setPackageData"] = Processor.process_setPackageData - self._processMap["deleteFinished"] = Processor.process_deleteFinished - self._processMap["restartFailed"] = Processor.process_restartFailed - self._processMap["getEvents"] = Processor.process_getEvents - self._processMap["getAccounts"] = Processor.process_getAccounts - self._processMap["getAccountTypes"] = Processor.process_getAccountTypes - self._processMap["updateAccount"] = Processor.process_updateAccount - self._processMap["removeAccount"] = Processor.process_removeAccount - self._processMap["login"] = Processor.process_login - self._processMap["getUserData"] = Processor.process_getUserData - self._processMap["getAllUserData"] = Processor.process_getAllUserData - self._processMap["getServices"] = Processor.process_getServices - self._processMap["hasService"] = Processor.process_hasService - self._processMap["call"] = Processor.process_call - self._processMap["getAllInfo"] = Processor.process_getAllInfo - self._processMap["getInfoByPlugin"] = Processor.process_getInfoByPlugin - self._processMap["isCaptchaWaiting"] = Processor.process_isCaptchaWaiting - self._processMap["getCaptchaTask"] = Processor.process_getCaptchaTask - self._processMap["getCaptchaTaskStatus"] = Processor.process_getCaptchaTaskStatus - self._processMap["setCaptchaResult"] = Processor.process_setCaptchaResult + self._processMap['getConfigValue'] = Processor.process_getConfigValue + self._processMap['setConfigValue'] = Processor.process_setConfigValue + self._processMap['getConfig'] = Processor.process_getConfig + self._processMap['getPluginConfig'] = Processor.process_getPluginConfig + self._processMap['pauseServer'] = Processor.process_pauseServer + self._processMap['unpauseServer'] = Processor.process_unpauseServer + self._processMap['togglePause'] = Processor.process_togglePause + self._processMap['statusServer'] = Processor.process_statusServer + self._processMap['freeSpace'] = Processor.process_freeSpace + self._processMap['getServerVersion'] = Processor.process_getServerVersion + self._processMap['kill'] = Processor.process_kill + self._processMap['restart'] = Processor.process_restart + self._processMap['getLog'] = Processor.process_getLog + self._processMap['isTimeDownload'] = Processor.process_isTimeDownload + self._processMap['isTimeReconnect'] = Processor.process_isTimeReconnect + self._processMap['toggleReconnect'] = Processor.process_toggleReconnect + self._processMap['generatePackages'] = Processor.process_generatePackages + self._processMap['checkURLs'] = Processor.process_checkURLs + self._processMap['parseURLs'] = Processor.process_parseURLs + self._processMap['checkOnlineStatus'] = Processor.process_checkOnlineStatus + self._processMap['checkOnlineStatusContainer'] = Processor.process_checkOnlineStatusContainer + self._processMap['pollResults'] = Processor.process_pollResults + self._processMap['statusDownloads'] = Processor.process_statusDownloads + self._processMap['getPackageData'] = Processor.process_getPackageData + self._processMap['getPackageInfo'] = Processor.process_getPackageInfo + self._processMap['getFileData'] = Processor.process_getFileData + self._processMap['getQueue'] = Processor.process_getQueue + self._processMap['getCollector'] = Processor.process_getCollector + self._processMap['getQueueData'] = Processor.process_getQueueData + self._processMap['getCollectorData'] = Processor.process_getCollectorData + self._processMap['getPackageOrder'] = Processor.process_getPackageOrder + self._processMap['getFileOrder'] = Processor.process_getFileOrder + self._processMap['generateAndAddPackages'] = Processor.process_generateAndAddPackages + self._processMap['addPackage'] = Processor.process_addPackage + self._processMap['addFiles'] = Processor.process_addFiles + self._processMap['uploadContainer'] = Processor.process_uploadContainer + self._processMap['deleteFiles'] = Processor.process_deleteFiles + self._processMap['deletePackages'] = Processor.process_deletePackages + self._processMap['pushToQueue'] = Processor.process_pushToQueue + self._processMap['pullFromQueue'] = Processor.process_pullFromQueue + self._processMap['restartPackage'] = Processor.process_restartPackage + self._processMap['restartFile'] = Processor.process_restartFile + self._processMap['recheckPackage'] = Processor.process_recheckPackage + self._processMap['stopAllDownloads'] = Processor.process_stopAllDownloads + self._processMap['stopDownloads'] = Processor.process_stopDownloads + self._processMap['setPackageName'] = Processor.process_setPackageName + self._processMap['movePackage'] = Processor.process_movePackage + self._processMap['moveFiles'] = Processor.process_moveFiles + self._processMap['orderPackage'] = Processor.process_orderPackage + self._processMap['orderFile'] = Processor.process_orderFile + self._processMap['setPackageData'] = Processor.process_setPackageData + self._processMap['deleteFinished'] = Processor.process_deleteFinished + self._processMap['restartFailed'] = Processor.process_restartFailed + self._processMap['getEvents'] = Processor.process_getEvents + self._processMap['getAccounts'] = Processor.process_getAccounts + self._processMap['getAccountTypes'] = Processor.process_getAccountTypes + self._processMap['updateAccount'] = Processor.process_updateAccount + self._processMap['removeAccount'] = Processor.process_removeAccount + self._processMap['login'] = Processor.process_login + self._processMap['getUserData'] = Processor.process_getUserData + self._processMap['getAllUserData'] = Processor.process_getAllUserData + self._processMap['getServices'] = Processor.process_getServices + self._processMap['hasService'] = Processor.process_hasService + self._processMap['call'] = Processor.process_call + self._processMap['getAllInfo'] = Processor.process_getAllInfo + self._processMap['getInfoByPlugin'] = Processor.process_getInfoByPlugin + self._processMap['isCaptchaWaiting'] = Processor.process_isCaptchaWaiting + self._processMap['getCaptchaTask'] = Processor.process_getCaptchaTask + self._processMap['getCaptchaTaskStatus'] = Processor.process_getCaptchaTaskStatus + self._processMap['setCaptchaResult'] = Processor.process_setCaptchaResult def process(self, iprot, oprot): @@ -3652,6 +3652,7 @@ class Processor(Iface, TProcessor): # HELPER FUNCTIONS AND STRUCTURES + class getConfigValue_args(TBase): """ Attributes: diff --git a/pyload/remote/thriftbackend/thriftgen/pyload/constants.py b/pyload/remote/thriftbackend/thriftgen/pyload/constants.py index 3bdd64cc1..e0a811c8a 100644 --- a/pyload/remote/thriftbackend/thriftgen/pyload/constants.py +++ b/pyload/remote/thriftbackend/thriftgen/pyload/constants.py @@ -8,3 +8,4 @@ from thrift.Thrift import TType, TMessageType, TException from ttypes import * + diff --git a/pyload/remote/thriftbackend/thriftgen/pyload/ttypes.py b/pyload/remote/thriftbackend/thriftgen/pyload/ttypes.py index 1c18f6421..8abd775a9 100644 --- a/pyload/remote/thriftbackend/thriftgen/pyload/ttypes.py +++ b/pyload/remote/thriftbackend/thriftgen/pyload/ttypes.py @@ -64,6 +64,7 @@ class DownloadStatus(TBase): "Unknown": 14, } + class Destination(TBase): Collector = 0 Queue = 1 @@ -78,6 +79,7 @@ class Destination(TBase): "Queue": 1, } + class ElementType(TBase): Package = 0 File = 1 @@ -92,6 +94,7 @@ class ElementType(TBase): "File": 1, } + class Input(TBase): NONE = 0 TEXT = 1 @@ -130,6 +133,7 @@ class Input(TBase): "TABLE": 9, } + class Output(TBase): CAPTCHA = 1 QUESTION = 2 diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py index 648432c26..2e23bf99b 100644 --- a/pyload/utils/__init__.py +++ b/pyload/utils/__init__.py @@ -116,13 +116,17 @@ def compare_time(start, end): start = map(int, start) end = map(int, end) - if start == end: return True + if start == end: + return True now = list(time.localtime()[3:5]) - if start < now < end: return True - elif start > end and (now > start or now < end): return True - elif start < now > end < start: return True - else: return False + if start < now < end: + return True + elif start > end and (now > start or now < end): + return True + elif start < now > end < start: + return True + return False def formatSize(size): diff --git a/pyload/utils/packagetools.py b/pyload/utils/packagetools.py index 9dbde9b50..0ab68a869 100644 --- a/pyload/utils/packagetools.py +++ b/pyload/utils/packagetools.py @@ -136,7 +136,7 @@ def parseNames(files): else: name = "" - # fallback: package by hoster + #@NOTE: fallback: package by hoster if not name: name = urlparse(file).netloc if name: diff --git a/pyload/utils/printer.py b/pyload/utils/printer.py index 5d333e238..1122c7f4c 100644 --- a/pyload/utils/printer.py +++ b/pyload/utils/printer.py @@ -5,6 +5,7 @@ import colorama colorama.init(autoreset=True) + def color(color, text): return colorama.Fore.(c.upper())(text) diff --git a/pyload/utils/pylgettext.py b/pyload/utils/pylgettext.py index 0e3ebad80..86cfc586a 100644 --- a/pyload/utils/pylgettext.py +++ b/pyload/utils/pylgettext.py @@ -6,12 +6,10 @@ _searchdirs = None origfind = find + def setpaths(pathlist): global _searchdirs - if isinstance(pathlist, list): - _searchdirs = pathlist - else: - _searchdirs = list(pathlist) + _searchdirs = pathlist if isinstance(pathlist, list) else list(pathlist) def addpath(path): @@ -32,8 +30,7 @@ def delpath(path): def clearpath(): global _searchdirs - if _searchdirs is not None: - _searchdirs = None + _searchdirs = None def find(domain, localedir=None, languages=None, all=False): diff --git a/pyload/webui/__init__.py b/pyload/webui/__init__.py index d965db3a0..841e5abd9 100644 --- a/pyload/webui/__init__.py +++ b/pyload/webui/__init__.py @@ -65,19 +65,19 @@ env = Environment(loader=loader, extensions=['jinja2.ext.i18n', 'jinja2.ext.auto from filters import quotepath, path_make_relative, path_make_absolute, truncate, date -env.filters["quotepath"] = quotepath -env.filters["truncate"] = truncate -env.filters["date"] = date -env.filters["path_make_relative"] = path_make_relative -env.filters["path_make_absolute"] = path_make_absolute -env.filters["decode"] = decode -env.filters["type"] = lambda x: str(type(x)) -env.filters["formatsize"] = formatSize -env.filters["getitem"] = lambda x, y: x.__getitem__(y) +env.filters['quotepath'] = quotepath +env.filters['truncate'] = truncate +env.filters['date'] = date +env.filters['path_make_relative'] = path_make_relative +env.filters['path_make_absolute'] = path_make_absolute +env.filters['decode'] = decode +env.filters['type'] = lambda x: str(type(x)) +env.filters['formatsize'] = formatSize +env.filters['getitem'] = lambda x, y: x.__getitem__(y) if PREFIX: - env.filters["url"] = lambda x: x + env.filters['url'] = lambda x: x else: - env.filters["url"] = lambda x: PREFIX + x if x.startswith("/") else x + env.filters['url'] = lambda x: PREFIX + x if x.startswith("/") else x gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("django", join(PYLOAD_DIR, "locale"), @@ -102,6 +102,7 @@ if PREFIX: import pyload.webui.app + def run_simple(host="0.0.0.0", port="8000"): run(app=web, host=host, port=port, quiet=True) diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py index dd8521a07..0e36b7c1f 100644 --- a/pyload/webui/app/api.py +++ b/pyload/webui/app/api.py @@ -13,6 +13,8 @@ from pyload.utils import json from SafeEval import const_eval as literal_eval from pyload.api import BaseObject + + # json encoder that accepts TBase objects class TBaseEncoder(json.JSONEncoder): @@ -23,7 +25,6 @@ class TBaseEncoder(json.JSONEncoder): # accepting positional arguments, as well as kwargs via post and get - @route('/api/<func><args:re:[a-zA-Z0-9\-_/\"\'\[\]%{},]*>') @route('/api/<func><args:re:[a-zA-Z0-9\-_/\"\'\[\]%{},]*>', method='POST') def call_api(func, args=""): @@ -37,14 +38,15 @@ def call_api(func, args=""): if not s or not s.get("authenticated", False): return HTTPError(403, json.dumps("Forbidden")) - if not PYLOAD.isAuthorized(func, {"role": s["role"], "permission": s["perms"]}): + if not PYLOAD.isAuthorized(func, {"role": s['role'], "permission": s['perms']}): return HTTPError(401, json.dumps("Unauthorized")) args = args.split("/")[1:] kwargs = {} for x, y in chain(request.GET.iteritems(), request.POST.iteritems()): - if x == "session": continue + if x == "session": + continue kwargs[x] = unquote(y) try: @@ -63,9 +65,7 @@ def callApi(func, *args, **kwargs): **dict((x, literal_eval(y)) for x, y in kwargs.iteritems())) # null is invalid json response - if result is None: result = True - - return json.dumps(result, cls=TBaseEncoder) + return json.dumps(result or True, cls=TBaseEncoder) # post -> username, password @@ -86,7 +86,7 @@ def login(): # get the session id by dirty way, documentations seems wrong try: - sid = s._headers["cookie_out"].split("=")[1].split(";")[0] + sid = s._headers['cookie_out'].split("=")[1].split(";")[0] return json.dumps(sid) except Exception: return json.dumps(True) diff --git a/pyload/webui/app/cnl.py b/pyload/webui/app/cnl.py index 51767033f..73087ad2d 100644 --- a/pyload/webui/app/cnl.py +++ b/pyload/webui/app/cnl.py @@ -73,8 +73,8 @@ def addcrypted(): @local_check def addcrypted2(): package = request.forms.get("source", None) - crypted = request.forms["crypted"] - jk = request.forms["jk"] + crypted = request.forms['crypted'] + jk = request.forms['jk'] crypted = standard_b64decode(unquote(crypted.replace(" ", "+"))) if JS: diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py index 700b310a0..12dce2484 100644 --- a/pyload/webui/app/json.py +++ b/pyload/webui/app/json.py @@ -22,7 +22,7 @@ def format_time(seconds): def get_sort_key(item): - return item["order"] + return item['order'] @route('/json/status') @@ -87,29 +87,29 @@ def packages(): def package(id): try: data = toDict(PYLOAD.getPackageData(id)) - data["links"] = [toDict(x) for x in data["links"]] - - for pyfile in data["links"]: - if pyfile["status"] == 0: - pyfile["icon"] = "status_finished.png" - elif pyfile["status"] in (2, 3): - pyfile["icon"] = "status_queue.png" - elif pyfile["status"] in (9, 1): - pyfile["icon"] = "status_offline.png" - elif pyfile["status"] == 5: - pyfile["icon"] = "status_waiting.png" - elif pyfile["status"] == 8: - pyfile["icon"] = "status_failed.png" - elif pyfile["status"] == 4: - pyfile["icon"] = "arrow_right.png" - elif pyfile["status"] in (11, 13): - pyfile["icon"] = "status_proc.png" + data['links'] = [toDict(x) for x in data['links']] + + for pyfile in data['links']: + if pyfile['status'] == 0: + pyfile['icon'] = "status_finished.png" + elif pyfile['status'] in (2, 3): + pyfile['icon'] = "status_queue.png" + elif pyfile['status'] in (9, 1): + pyfile['icon'] = "status_offline.png" + elif pyfile['status'] == 5: + pyfile['icon'] = "status_waiting.png" + elif pyfile['status'] == 8: + pyfile['icon'] = "status_failed.png" + elif pyfile['status'] == 4: + pyfile['icon'] = "arrow_right.png" + elif pyfile['status'] in (11, 13): + pyfile['icon'] = "status_proc.png" else: - pyfile["icon"] = "status_downloading.png" + pyfile['icon'] = "status_downloading.png" - tmp = data["links"] + tmp = data['links'] tmp.sort(key=get_sort_key) - data["links"] = tmp + data['links'] = tmp return data except Exception: @@ -217,7 +217,7 @@ def edit_package(): def set_captcha(): if request.environ.get('REQUEST_METHOD', "GET") == "POST": try: - PYLOAD.setCaptchaResult(request.forms["cap_id"], request.forms["cap_result"]) + PYLOAD.setCaptchaResult(request.forms['cap_id'], request.forms['cap_result']) except Exception: pass @@ -241,12 +241,13 @@ def load_config(category, section): conf = PYLOAD.getPluginConfigDict() for key, option in conf[section].iteritems(): - if key in ("desc", "outline"): continue + if key in ("desc", "outline"): + continue - if ";" in option["type"]: - option["list"] = option["type"].split(";") + if ";" in option['type']: + option['list'] = option['type'].split(";") - option["value"] = decode(option["value"]) + option['value'] = decode(option['value']) return render_to_response("settings_item.html", {"skey": section, "section": conf[section]}) @@ -268,9 +269,9 @@ def save_config(category): @route('/json/add_account', method='POST') @login_required("ACCOUNTS") def add_account(): - login = request.POST["account_login"] - password = request.POST["account_password"] - type = request.POST["account_type"] + login = request.POST['account_login'] + password = request.POST['account_password'] + type = request.POST['account_type'] PYLOAD.updateAccount(type, login, password) @@ -282,12 +283,14 @@ def update_accounts(): for name, value in request.POST.iteritems(): value = value.strip() - if not value: continue + if not value: + continue tmp, user = name.split(";") plugin, action = tmp.split("|") - if (plugin, user) in deleted: continue + if (plugin, user) in deleted: + continue if action == "password": PYLOAD.updateAccount(plugin, user, value) @@ -299,12 +302,13 @@ def update_accounts(): deleted.append((plugin,user)) PYLOAD.removeAccount(plugin, user) + @route('/json/change_password', method='POST') def change_password(): - user = request.POST["user_login"] - oldpw = request.POST["login_current_password"] - newpw = request.POST["login_new_password"] + user = request.POST['user_login'] + oldpw = request.POST['login_current_password'] + newpw = request.POST['login_new_password'] if not PYLOAD.changePassword(user, oldpw, newpw): print "Wrong password" diff --git a/pyload/webui/app/pyloadweb.py b/pyload/webui/app/pyloadweb.py index cc2185fd4..1604bd576 100644 --- a/pyload/webui/app/pyloadweb.py +++ b/pyload/webui/app/pyloadweb.py @@ -34,16 +34,16 @@ def pre_processor(): captcha = False update = False plugins = False - if user["is_authenticated"]: + if user['is_authenticated']: status = PYLOAD.statusServer() info = PYLOAD.getInfoByPlugin("UpdateManager") captcha = PYLOAD.isCaptchaWaiting() # check if update check is available if info: - if info["pyload"] == "True": - update = info["version"] - if info["plugins"] == "True": + if info['pyload'] == "True": + update = info['version'] + if info['plugins'] == "True": plugins = True return {"user": user, @@ -165,8 +165,8 @@ def home(): return redirect("/login") for link in res: - if link["status"] == 12: - link["information"] = "%s kB @ %s kB/s" % (link["size"] - link["bleft"], link["speed"]) + if link['status'] == 12: + link['information'] = "%s kB @ %s kB/s" % (link['size'] - link['bleft'], link['speed']) return render_to_response("home.html", {"res": res}, [pre_processor]) @@ -282,14 +282,14 @@ def config(): data.validuntil = time.strftime("%d.%m.%Y - %H:%M:%S", t) try: - data.options["time"] = data.options["time"][0] + data.options['time'] = data.options['time'][0] except Exception: - data.options["time"] = "0:00-0:00" + data.options['time'] = "0:00-0:00" if "limitDL" in data.options: - data.options["limitdl"] = data.options["limitDL"][0] + data.options['limitdl'] = data.options['limitDL'][0] else: - data.options["limitdl"] = "0" + data.options['limitdl'] = "0" return render_to_response('settings.html', {'conf': {'plugin': plugin_menu, 'general': conf_menu, 'accs': accs}, 'types': PYLOAD.getAccountTypes()}, @@ -482,30 +482,30 @@ def admin(): perms = permlist() for data in user.itervalues(): - data["perms"] = {} - get_permission(data["perms"], data["permission"]) - data["perms"]["admin"] = True if data["role"] is 0 else False + data['perms'] = {} + get_permission(data['perms'], data['permission']) + data['perms']['admin'] = True if data['role'] is 0 else False s = request.environ.get('beaker.session') if request.environ.get('REQUEST_METHOD', "GET") == "POST": for name in user: if request.POST.get("%s|admin" % name, False): - user[name]["role"] = 0 - user[name]["perms"]["admin"] = True - elif name != s["name"]: - user[name]["role"] = 1 - user[name]["perms"]["admin"] = False + user[name]['role'] = 0 + user[name]['perms']['admin'] = True + elif name != s['name']: + user[name]['role'] = 1 + user[name]['perms']['admin'] = False # set all perms to false for perm in perms: - user[name]["perms"][perm] = False + user[name]['perms'][perm] = False for perm in request.POST.getall("%s|perms" % name): - user[name]["perms"][perm] = True + user[name]['perms'][perm] = True - user[name]["permission"] = set_permission(user[name]["perms"]) + user[name]['permission'] = set_permission(user[name]['perms']) - PYLOAD.setUserPermission(name, user[name]["permission"], user[name]["role"]) + PYLOAD.setUserPermission(name, user[name]['permission'], user[name]['role']) return render_to_response("admin.html", {"users": user, "permlist": perms}, [pre_processor]) @@ -528,10 +528,10 @@ def info(): "os" : " ".join((os.name, sys.platform) + extra), "version" : PYLOAD.getServerVersion(), "folder" : abspath(PYLOAD_DIR), "config": abspath(""), - "download" : abspath(conf["general"]["download_folder"]["value"]), + "download" : abspath(conf['general']['download_folder']['value']), "freespace": formatSize(PYLOAD.freeSpace()), - "remote" : conf["remote"]["port"]["value"], - "webif" : conf["webui"]["port"]["value"], - "language" : conf["general"]["language"]["value"]} + "remote" : conf['remote']['port']['value'], + "webif" : conf['webui']['port']['value'], + "language" : conf['general']['language']['value']} return render_to_response("info.html", data, [pre_processor]) diff --git a/pyload/webui/app/utils.py b/pyload/webui/app/utils.py index ac7fa84fb..69067d8fe 100644 --- a/pyload/webui/app/utils.py +++ b/pyload/webui/app/utils.py @@ -9,6 +9,7 @@ from pyload.webui import env, THEME from pyload.api import has_permission, PERMS, ROLE + def render_to_response(file, args={}, proc=[]): for p in proc: args.update(p()) @@ -18,8 +19,8 @@ def render_to_response(file, args={}, proc=[]): def parse_permissions(session): perms = dict((x, False) for x in dir(PERMS) if not x.startswith("_")) - perms["ADMIN"] = False - perms["is_admin"] = False + perms['ADMIN'] = False + perms['is_admin'] = False if not session.get("authenticated", False): return perms @@ -56,7 +57,8 @@ def set_permission(perms): """ permission = 0 for name in dir(PERMS): - if name.startswith("_"): continue + if name.startswith("_"): + continue if name in perms and perms[name]: permission |= getattr(PERMS, name) @@ -66,12 +68,12 @@ def set_permission(perms): def set_session(request, info): s = request.environ.get('beaker.session') - s["authenticated"] = True - s["user_id"] = info["id"] - s["name"] = info["name"] - s["role"] = info["role"] - s["perms"] = info["permission"] - s["template"] = info["template"] + s['authenticated'] = True + s['user_id'] = info['id'] + s['name'] = info['name'] + s['role'] = info['role'] + s['perms'] = info['permission'] + s['template'] = info['template'] s.save() return s diff --git a/pyload/webui/filters.py b/pyload/webui/filters.py index c784b248d..ea4b159fa 100644 --- a/pyload/webui/filters.py +++ b/pyload/webui/filters.py @@ -18,7 +18,7 @@ except Exception: path_list = abspath(path).split(sep) # Work out how much of the filepath is shared by start and path. i = len(commonprefix([start_list, path_list])) - rel_list = [pardir] * (len(start_list)-i) + path_list[i:] + rel_list = [pardir] * (len(start_list) - i) + path_list[i:] if not rel_list: return curdir return join(*rel_list) @@ -32,6 +32,7 @@ def quotepath(path): except Exception: return "" + def unquotepath(path): try: return path.replace(quotechar, "../") @@ -40,6 +41,7 @@ def unquotepath(path): except Exception: return "" + def path_make_absolute(path): p = os.path.abspath(path) if p[-1] == os.path.sep: @@ -47,6 +49,7 @@ def path_make_absolute(path): else: return p + os.path.sep + def path_make_relative(path): p = relpath(path) if p[-1] == os.path.sep: @@ -54,10 +57,12 @@ def path_make_relative(path): else: return p + os.path.sep + def truncate(value, n): if (n - len(value)) < 3: - return value[:n]+"..." + return value[:n] + "..." return value + def date(date, format): return date diff --git a/pyload/webui/middlewares.py b/pyload/webui/middlewares.py index 26537f900..c3f4952db 100644 --- a/pyload/webui/middlewares.py +++ b/pyload/webui/middlewares.py @@ -7,6 +7,7 @@ try: except ImportError: from StringIO import StringIO + class StripPathMiddleware(object): def __init__(self, app): @@ -26,7 +27,7 @@ class PrefixMiddleware(object): def __call__(self, e, h): - path = e["PATH_INFO"] + path = e['PATH_INFO'] if path.startswith(self.prefix): e['PATH_INFO'] = path.replace(self.prefix, "", 1) return self.app(e, h) @@ -40,6 +41,7 @@ class PrefixMiddleware(object): # WSGI middleware # Gzip-encodes the response. + class GZipMiddleWare(object): def __init__(self, application, compress_level=6): @@ -60,21 +62,25 @@ class GZipMiddleWare(object): return response.write() + def header_value(headers, key): for header, value in headers: if key.lower() == header.lower(): return value + def update_header(headers, key, value): remove_header(headers, key) headers.append((key, value)) + def remove_header(headers, key): for header, value in headers: if key.lower() == header.lower(): headers.remove((header, value)) break + class GzipResponse(object): def __init__(self, start_response, compress_level): @@ -88,16 +94,15 @@ class GzipResponse(object): def gzip_start_response(self, status, headers, exc_info=None): self.headers = headers - ct = header_value(headers,'content-type') - ce = header_value(headers,'content-encoding') + ct = header_value(headers, 'content-type') + ce = header_value(headers, 'content-encoding') cl = header_value(headers, 'content-length') if cl: cl = int(cl) else: cl = 201 self.compressible = False - if ct and (ct.startswith('text/') or ct.startswith('application/')) \ - and 'zip' not in ct and cl > 200: + if ct and (ct.startswith('text/') or ct.startswith('application/')) and 'zip' not in ct and cl > 200: self.compressible = True if ce: self.compressible = False @@ -119,8 +124,7 @@ class GzipResponse(object): def finish_response(self, app_iter): if self.compressible: - output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, - fileobj=self.buffer) + output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, fileobj=self.buffer) else: output = self.buffer try: @@ -136,5 +140,5 @@ class GzipResponse(object): pass content_length = self.buffer.tell() - update_header(self.headers, "Content-Length" , str(content_length)) + update_header(self.headers, "Content-Length", str(content_length)) self.start_response(self.status, self.headers) diff --git a/pyload/webui/servers/lighttpd_default.conf b/pyload/webui/servers/lighttpd_default.conf index a821096c6..444ef39c5 100644 --- a/pyload/webui/servers/lighttpd_default.conf +++ b/pyload/webui/servers/lighttpd_default.conf @@ -115,7 +115,7 @@ accesslog.filename = "%(path)/access.log" url.access-deny = ( "~", ".inc" ) -$HTTP["url"] =~ "\.pdf$" { +$HTTP['url'] =~ "\.pdf$" { server.range-requests = "disable" } diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py index 38dd9fceb..d17f81ae2 100644 --- a/tests/APIExerciser.py +++ b/tests/APIExerciser.py @@ -3,15 +3,15 @@ import string from threading import Thread -from random import choice, random, sample, randint -from time import time, sleep +from random import choice, sample, randint +from time import time from math import floor import gc - from traceback import print_exc, format_exc from pyload.remote.thriftbackend.ThriftClient import ThriftClient, Destination + def createURLs(): """ create some urls, some may fail """ urls = [] @@ -24,6 +24,7 @@ def createURLs(): return urls + AVOID = (0, 3, 8) idPool = 0 @@ -31,9 +32,10 @@ sumCalled = 0 def startApiExerciser(core, n): - for i in range(n): + for _i in range(n): APIExerciser(core).start() + class APIExerciser(Thread): def __init__(self, core, thrift=False, user=None, pw=None): @@ -45,17 +47,13 @@ class APIExerciser(Thread): self.count = 0 #: number of methods self.time = time() - if thrift: - self.api = ThriftClient(user=user, password=pw) - else: - self.api = core.api - + self.api = ThriftClient(user=user, password=pw) if thrift else core.api self.id = idPool idPool += 1 - #self.start() + # self.start() def run(self): @@ -63,7 +61,7 @@ class APIExerciser(Thread): self.core.log.info("API Excerciser started %d" % self.id) out = open("error.log", "ab") - #core errors are not logged of course + # core errors are not logged of course out.write("\n" + "Starting\n") out.flush() @@ -87,9 +85,7 @@ class APIExerciser(Thread): self.core.log.info("Approx. %.2f calls per second." % persec) self.core.log.info("Approx. %.2f ms per call." % (1000 / persec)) self.core.log.info("Collected garbage: %d" % gc.collect()) - - - #sleep(random() / 500) + # sleep(random() / 500) def testAPI(self): @@ -97,10 +93,10 @@ class APIExerciser(Thread): m = ["statusDownloads", "statusServer", "addPackage", "getPackageData", "getFileData", "deleteFiles", "deletePackages", "getQueue", "getCollector", "getQueueData", "getCollectorData", "isCaptchaWaiting", - "getCaptchaTask", "stopAllDownloads", "getAllInfo", "getServices" , "getAccounts", "getAllUserData"] + "getCaptchaTask", "stopAllDownloads", "getAllInfo", "getServices", "getAccounts", "getAllUserData"] method = choice(m) - #print "Testing:", method + # print "Testing:", method if hasattr(self, method): res = getattr(self, method)() @@ -110,7 +106,7 @@ class APIExerciser(Thread): self.count += 1 sumCalled += 1 - #print res + # print res def addPackage(self): @@ -122,7 +118,8 @@ class APIExerciser(Thread): def deleteFiles(self): info = self.api.getQueueData() - if not info: return + if not info: + return pack = choice(info) fids = pack.links @@ -134,11 +131,12 @@ class APIExerciser(Thread): def deletePackages(self): info = choice([self.api.getQueue(), self.api.getCollector()]) - if not info: return + if not info: + return pids = [p.pid for p in info] - if len(pids): - pids = sample(pids, randint(1, max(floor(len(pids) / 2.5), 1))) + if pids: + pids = sample(pids, randint(1, max(floor(len(pids) / 2.5), 1))) self.api.deletePackages(pids) diff --git a/tests/clonedigger.sh b/tests/clonedigger.sh index 641e7ff64..4c53eab0d 100644 --- a/tests/clonedigger.sh +++ b/tests/clonedigger.sh @@ -1,4 +1,4 @@ #!/bin/sh PYLOAD="../pyload" # Check pyload directory -clonedigger -o cpd.xml --cpd-output --fast --ignore-dir="remote" $PYLOAD +clonedigger -o cpd.xml --cpd-output --fast --ignore-dir="remote" ${PYLOAD} diff --git a/tests/code_analysis.sh b/tests/code_analysis.sh index c4dc8e99a..cba614929 100644 --- a/tests/code_analysis.sh +++ b/tests/code_analysis.sh @@ -4,12 +4,12 @@ PYLOAD="../pyload" # Check pyload directory echo "Running sloccount ..." REPORT="sloccount.sc" -sloccount --duplicates --wide --details $PYLOAD > $REPORT && echo "Done. Report saved to $REPORT" +sloccount --duplicates --wide --details ${PYLOAD} > ${REPORT} && echo "Done. Report saved to $REPORT" echo "Running pep8 ..." REPORT="pep8.txt" -pep8 $PYLOAD > $REPORT && echo "Done. Report saved to $REPORT" +pep8 ${PYLOAD} > ${REPORT} && echo "Done. Report saved to $REPORT" echo "Running pylint ..." REPORT="pylint.txt" -pylint --reports=no $PYLOAD > $REPORT && echo "Done. Report saved to $REPORT" +pylint --reports=no ${PYLOAD} > ${REPORT} && echo "Done. Report saved to $REPORT" diff --git a/tests/test_api.py b/tests/test_api.py index 9c12da51c..13e783d54 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -20,5 +20,5 @@ class TestApi(object): @nottest def test_random(self): - for _ in range(0, 100): + for _i in range(0, 100): self.api.testAPI() diff --git a/tests/test_json.py b/tests/test_json.py index f87a32139..a83ef0a24 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -14,7 +14,7 @@ class TestJson(object): def call(self, name, post=None): if not post: post = {} - post["session"] = self.key + post['session'] = self.key u = urlopen(url % name, data=urlencode(post)) return loads(u.read()) |