diff options
43 files changed, 278 insertions, 265 deletions
diff --git a/locale/pavement.py b/locale/pavement.py index 06a4f9775..cb2c6c01e 100644 --- a/locale/pavement.py +++ b/locale/pavement.py @@ -270,11 +270,11 @@ def upload_translations(options): shutil.copy(f, tmp / 'pyLoad') config = tmp / 'crowdin.yaml' - content = open(config, 'rb').read() + with open(config, 'rb') as f: + content = f.read() content = content.format(key=options.key, tmp=tmp) - f = open(config, 'wb') - f.write(content) - f.close() + with open(config, 'wb') as f: + f.write(content) call(['crowdin-cli', '-c', config, 'upload', 'source']) @@ -300,11 +300,11 @@ def download_translations(options): shutil.copy(f, tmp / 'pyLoad') config = tmp / 'crowdin.yaml' - content = open(config, 'rb').read() + with open(config, 'rb') as f: + content = f.read() content = content.format(key=options.key, tmp=tmp) - f = open(config, 'wb') - f.write(content) - f.close() + with open(config, 'wb') as f: + f.write(content) call(['crowdin-cli', '-c', config, 'download']) @@ -395,14 +395,12 @@ def walk_trans(path, EXCLUDE, endings=[".py"]): def makepot(domain, p, excludes=[], includes="", endings=[".py"], xxargs=[]): print "Generate %s.pot" % domain - f = open("includes.txt", "wb") - if includes: - f.write(includes) + with open("includes.txt", "wb") as f: + if includes: + f.write(includes) - if p: - f.write(walk_trans(path(p), excludes, endings)) - - f.close() + if p: + f.write(walk_trans(path(p), excludes, endings)) call(["xgettext", "--files-from=includes.txt", "--default-domain=%s" % domain] + xargs + xxargs) diff --git a/pyload/Core.py b/pyload/Core.py index f723d8366..d1404d00f 100755 --- a/pyload/Core.py +++ b/pyload/Core.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -# @author: RaNaN, mkaay, sebnapi, spoob +# @author: RaNaN, mkaay, sebnapi, spoob, vuolter # @version: v0.4.10 -CURRENT_VERSION = '0.4.10' +from __future__ import with_statement +import pyload import __builtin__ from getopt import getopt, GetoptError @@ -41,11 +42,10 @@ from codecs import getwriter enc = get_console_encoding(sys.stdout.encoding) sys.stdout = getwriter(enc)(sys.stdout, errors="replace") + # TODO List # - configurable auth system ldap/mysql # - cron job like sheduler - - class Core(object): """pyLoad Core, one tool to rule them all... (the filehosters) :D""" @@ -68,7 +68,7 @@ class Core(object): for option, argument in options: if option in ("-v", "--version"): - print "pyLoad", CURRENT_VERSION + print "pyLoad", pyload.__version__ exit() elif option in ("-p", "--pidfile"): self.pidfile = argument @@ -127,7 +127,7 @@ class Core(object): def print_help(self): print - print "pyLoad v%s 2008-2015 the pyLoad Team" % CURRENT_VERSION + print "pyLoad v%s 2008-2015 the pyLoad Team" % pyload.__version__ print if sys.argv[0].endswith(".py"): print "Usage: python pyload.py [options]" @@ -171,9 +171,8 @@ class Core(object): def writePidFile(self): self.deletePidFile() pid = os.getpid() - f = open(self.pidfile, "wb") - f.write(str(pid)) - f.close() + with open(self.pidfile, "wb") as f: + f.write(str(pid)) def deletePidFile(self): @@ -185,9 +184,8 @@ class Core(object): def checkPidFile(self): """ return pid as int or 0""" if os.path.isfile(self.pidfile): - f = open(self.pidfile, "rb") - pid = f.read().strip() - f.close() + with open(self.pidfile, "rb") as f: + pid = f.read().strip() if pid: pid = int(pid) return pid @@ -253,7 +251,7 @@ class Core(object): def start(self, rpc=True, web=True): """ starts the fun :D """ - self.version = CURRENT_VERSION + self.version = pyload.__version__ if not exists("pyload.conf"): from pyload.config.Setup import SetupAssistant as Setup @@ -330,7 +328,7 @@ class Core(object): self.do_restart = False self.shuttedDown = False - self.log.info(_("Starting") + " pyLoad %s" % CURRENT_VERSION) + self.log.info(_("Starting") + " pyLoad %s" % pyload.__version__) self.log.info(_("Using home directory: %s") % getcwd()) self.writePidFile() @@ -409,17 +407,15 @@ class Core(object): link_file = join(pypath, "links.txt") if exists(link_file): - f = open(link_file, "rb") - if f.read().strip(): - self.api.addPackage("links.txt", [link_file], 1) - f.close() + with open(link_file, "rb") as f: + if f.read().strip(): + self.api.addPackage("links.txt", [link_file], 1) link_file = "links.txt" if exists(link_file): - f = open(link_file, "rb") - if f.read().strip(): - self.api.addPackage("links.txt", [link_file], 1) - f.close() + with open(link_file, "rb") as f: + if f.read().strip(): + self.api.addPackage("links.txt", [link_file], 1) #self.scheduler.addJob(0, self.accountManager.getAccountInfos) self.log.info(_("Activating Accounts...")) @@ -616,7 +612,7 @@ class Core(object): self.shutdown() chdir(owd) # close some open fds - for i in range(3, 50): + for i in xrange(3, 50): try: close(i) except Exception: @@ -682,7 +678,7 @@ def deamon(): sys.exit(1) # Iterate through and close some file descriptors. - for fd in range(0, 3): + for fd in xrange(0, 3): try: os.close(fd) except OSError: # ERROR, fd wasn't open to begin with (ignored) diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py index b5c1dfbf4..ab717525d 100644 --- a/pyload/api/__init__.py +++ b/pyload/api/__init__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # @author: RaNaN +from __future__ import with_statement + from base64 import standard_b64encode from os.path import join from time import time @@ -265,9 +267,8 @@ class Api(Iface): """ filename = join(self.core.config.get("log", "log_folder"), 'log.txt') try: - fh = open(filename, "r") - lines = fh.readlines() - fh.close() + with open(filename, "r") as fh: + lines = fh.readlines() if offset >= len(lines): return [] return lines[offset:] @@ -409,9 +410,8 @@ class Api(Iface): :param data: file content :return: online check """ - th = open(join(self.core.config.get("general", "download_folder"), "tmp_" + container), "wb") - th.write(str(data)) - th.close() + with open(join(self.core.config.get("general", "download_folder"), "tmp_" + container), "wb") as th: + th.write(str(data)) return self.checkOnlineStatus(urls + [th.name]) @@ -707,9 +707,8 @@ class Api(Iface): :param filename: filename, extension is important so it can correctly decrypted :param data: file content """ - th = open(join(self.core.config.get("general", "download_folder"), "tmp_" + filename), "wb") - th.write(str(data)) - th.close() + with open(join(self.core.config.get("general", "download_folder"), "tmp_" + filename), "wb") as th: + th.write(str(data)) self.addPackage(th.name, [th.name], Destination.Queue) diff --git a/pyload/api/types.py b/pyload/api/types.py index 2fd089333..9381df3c7 100644 --- a/pyload/api/types.py +++ b/pyload/api/types.py @@ -2,7 +2,6 @@ # Autogenerated by pyload # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - class BaseObject(object): __slots__ = [] diff --git a/pyload/cli/Cli.py b/pyload/cli/Cli.py index 84725b625..cd3252220 100644 --- a/pyload/cli/Cli.py +++ b/pyload/cli/Cli.py @@ -214,7 +214,7 @@ class Cli(object): # clear old output if line < self.lastLowestLine: - for i in range(line + 1, self.lastLowestLine + 1): + for i in xrange(line + 1, self.lastLowestLine + 1): println(i, "") self.lastLowestLine = line @@ -321,9 +321,8 @@ class Cli(object): print _("File does not exists.") return - f = open(join(owd, path), "rb") - content = f.read() - f.close() + with open(join(owd, path), "rb") as f: + content = f.read() rid = self.client.checkOnlineStatusContainer([], basename(f.name), content).rid self.printOnlineCheck(self.client, rid) diff --git a/pyload/cli/Handler.py b/pyload/cli/Handler.py index 444d7f6d0..33e5dd8e6 100644 --- a/pyload/cli/Handler.py +++ b/pyload/cli/Handler.py @@ -1,7 +1,6 @@ # -*- 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 c010895c5..2e7f725dd 100644 --- a/pyload/cli/ManageFiles.py +++ b/pyload/cli/ManageFiles.py @@ -113,7 +113,7 @@ class ManageFiles(Handler): i += 1 except Exception: pass - for _i in range(5 - i): + for _i in xrange(5 - i): println(line, "") line += 1 else: @@ -128,7 +128,7 @@ class ManageFiles(Handler): i += 1 except Exception, e: pass - for _i in range(5 - i): + for _i in xrange(5 - i): println(line, "") line += 1 @@ -168,7 +168,7 @@ class ManageFiles(Handler): inp = inp.strip() if "-" in inp: l, _, h = inp.partition("-") - r = range(int(l), int(h) + 1) + r = xrange(int(l), int(h) + 1) if package: return [p.pid for p in self.cache if p.pid in r] diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py index 1d76c0164..45fb1c8d0 100644 --- a/pyload/config/Parser.py +++ b/pyload/config/Parser.py @@ -52,29 +52,26 @@ class ConfigParser(object): copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf") if not exists("plugin.conf"): - f = open("plugin.conf", "wb") - f.write("version: " + str(CONF_VERSION)) - f.close() + with open("plugin.conf", "wb") as f: + f.write("version: " + str(CONF_VERSION)) - f = open("pyload.conf", "rb") - v = f.readline() - f.close() + with open("pyload.conf", "rb") as f: + v = f.readline() v = v[v.find(":") + 1:].strip() if not v or int(v) < CONF_VERSION: copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf") print "Old version of config was replaced" - f = open("plugin.conf", "rb") - v = f.readline() - f.close() + with open("plugin.conf", "rb") as f: + v = f.readline() v = v[v.find(":") + 1:].strip() if not v or int(v) < CONF_VERSION: - f = open("plugin.conf", "wb") - f.write("version: " + str(CONF_VERSION)) - f.close() + with open("plugin.conf", "wb") as f: + f.write("version: " + str(CONF_VERSION)) print "Old version of plugin-config replaced" + except Exception: if n >= 3: raise @@ -104,9 +101,8 @@ class ConfigParser(object): def parseConfig(self, config): """parses a given configfile""" - f = open(config) - - config = f.read() + with open(config) as f: + config = f.read() config = config.splitlines()[1:] @@ -183,7 +179,6 @@ class ConfigParser(object): print "Config Warning" print_exc() - f.close() return conf diff --git a/pyload/config/default.conf b/pyload/config/default.conf index e07b92f68..b36ed6c9c 100644 --- a/pyload/config/default.conf +++ b/pyload/config/default.conf @@ -1,4 +1,4 @@ -version: 2 +version: 1 remote - "Remote": bool activated : "Activated" = True diff --git a/pyload/database/Backend.py b/pyload/database/Backend.py index b0e94711e..b6540b2be 100644 --- a/pyload/database/Backend.py +++ b/pyload/database/Backend.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- # @author: RaNaN, mkaay +from __future__ import with_statement + from threading import Event, Thread from os import remove from os.path import exists from shutil import move - from Queue import Queue from traceback import print_exc @@ -36,6 +37,7 @@ class style(object): def x(*args, **kwargs): if cls.db: return f(cls.db, *args, **kwargs) + return x @@ -47,6 +49,7 @@ class style(object): def x(*args, **kwargs): if cls.db: return cls.db.queue(f, *args, **kwargs) + return x @@ -73,15 +76,16 @@ class DatabaseJob(object): self.result = None self.exception = False -# import inspect -# self.frame = inspect.currentframe() + # import inspect + # self.frame = inspect.currentframe() def __repr__(self): from os.path import basename + frame = self.frame.f_back output = "" - for _i in range(5): + for _i in xrange(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 @@ -167,26 +171,22 @@ class DatabaseBackend(Thread): def _checkVersion(self): """ check db version and delete it if needed""" if not exists("files.version"): - f = open("files.version", "wb") - f.write(str(DB_VERSION)) - f.close() + with open("files.version", "wb") as f: + f.write(str(DB_VERSION)) return - f = open("files.version", "rb") - v = int(f.read().strip()) - f.close() - if v < DB_VERSION: - if v < 2: - try: - self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version.")) - except Exception: - print "Filedatabase was deleted due to incompatible version." - remove("files.version") - move("files.db", "files.backup.db") - f = open("files.version", "wb") - f.write(str(DB_VERSION)) - f.close() - return v + with open("files.version", "wb+") as f: + v = int(f.read().strip()) + if v < DB_VERSION: + if v < 2: + try: + self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version.")) + except Exception: + print "Filedatabase was deleted due to incompatible version." + remove("files.version") + move("files.db", "files.backup.db") + f.write(str(DB_VERSION)) + return v def _convertDB(self, v): @@ -198,11 +198,12 @@ class DatabaseBackend(Thread): except Exception: print "Filedatabase could NOT be converted." - #convert scripts start----------------------------------------------------- + # convert scripts start --------------------------------------------------- def _convertV2(self): - self.c.execute('CREATE TABLE IF NOT EXISTS "storage" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "identifier" TEXT NOT NULL, "key" TEXT NOT NULL, "value" TEXT DEFAULT "")') + self.c.execute( + 'CREATE TABLE IF NOT EXISTS "storage" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "identifier" TEXT NOT NULL, "key" TEXT NOT NULL, "value" TEXT DEFAULT "")') try: self.manager.core.log.info(_("Database was converted from v2 to v3.")) except Exception: @@ -211,47 +212,45 @@ class DatabaseBackend(Thread): def _convertV3(self): - self.c.execute('CREATE TABLE IF NOT EXISTS "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "email" TEXT DEFAULT "" NOT NULL, "password" TEXT NOT NULL, "role" INTEGER DEFAULT 0 NOT NULL, "permission" INTEGER DEFAULT 0 NOT NULL, "template" TEXT DEFAULT "default" NOT NULL)') + self.c.execute( + 'CREATE TABLE IF NOT EXISTS "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "email" TEXT DEFAULT "" NOT NULL, "password" TEXT NOT NULL, "role" INTEGER DEFAULT 0 NOT NULL, "permission" INTEGER DEFAULT 0 NOT NULL, "template" TEXT DEFAULT "default" NOT NULL)') try: self.manager.core.log.info(_("Database was converted from v3 to v4.")) except Exception: print "Database was converted from v3 to v4." - #convert scripts end------------------------------------------------------- + # convert scripts end ----------------------------------------------------- def _createTables(self): """create tables for database""" - self.c.execute('CREATE TABLE IF NOT EXISTS "packages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "folder" TEXT, "password" TEXT DEFAULT "", "site" TEXT DEFAULT "", "queue" INTEGER DEFAULT 0 NOT NULL, "packageorder" INTEGER DEFAULT 0 NOT NULL)') - self.c.execute('CREATE TABLE IF NOT EXISTS "links" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "url" TEXT NOT NULL, "name" TEXT, "size" INTEGER DEFAULT 0 NOT NULL, "status" INTEGER DEFAULT 3 NOT NULL, "plugin" TEXT DEFAULT "BasePlugin" NOT NULL, "error" TEXT DEFAULT "", "linkorder" INTEGER DEFAULT 0 NOT NULL, "package" INTEGER DEFAULT 0 NOT NULL, FOREIGN KEY(package) REFERENCES packages(id))') + self.c.execute( + 'CREATE TABLE IF NOT EXISTS "packages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "folder" TEXT, "password" TEXT DEFAULT "", "site" TEXT DEFAULT "", "queue" INTEGER DEFAULT 0 NOT NULL, "packageorder" INTEGER DEFAULT 0 NOT NULL)') + self.c.execute( + 'CREATE TABLE IF NOT EXISTS "links" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "url" TEXT NOT NULL, "name" TEXT, "size" INTEGER DEFAULT 0 NOT NULL, "status" INTEGER DEFAULT 3 NOT NULL, "plugin" TEXT DEFAULT "BasePlugin" NOT NULL, "error" TEXT DEFAULT "", "linkorder" INTEGER DEFAULT 0 NOT NULL, "package" INTEGER DEFAULT 0 NOT NULL, FOREIGN KEY(package) REFERENCES packages(id))') self.c.execute('CREATE INDEX IF NOT EXISTS "pIdIndex" ON links(package)') - self.c.execute('CREATE TABLE IF NOT EXISTS "storage" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "identifier" TEXT NOT NULL, "key" TEXT NOT NULL, "value" TEXT DEFAULT "")') - self.c.execute('CREATE TABLE IF NOT EXISTS "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "email" TEXT DEFAULT "" NOT NULL, "password" TEXT NOT NULL, "role" INTEGER DEFAULT 0 NOT NULL, "permission" INTEGER DEFAULT 0 NOT NULL, "template" TEXT DEFAULT "default" NOT NULL)') + self.c.execute( + 'CREATE TABLE IF NOT EXISTS "storage" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "identifier" TEXT NOT NULL, "key" TEXT NOT NULL, "value" TEXT DEFAULT "")') + self.c.execute( + 'CREATE TABLE IF NOT EXISTS "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "email" TEXT DEFAULT "" NOT NULL, "password" TEXT NOT NULL, "role" INTEGER DEFAULT 0 NOT NULL, "permission" INTEGER DEFAULT 0 NOT NULL, "template" TEXT DEFAULT "default" NOT NULL)') self.c.execute('CREATE VIEW IF NOT EXISTS "pstats" AS \ SELECT p.id AS id, SUM(l.size) AS sizetotal, COUNT(l.id) AS linkstotal, linksdone, sizedone\ FROM packages p JOIN links l ON p.id = l.package LEFT OUTER JOIN\ (SELECT p.id AS id, COUNT(*) AS linksdone, SUM(l.size) AS sizedone \ - FROM packages p JOIN links l ON p.id = l.package AND l.status in (0, 4, 13) GROUP BY p.id) s ON s.id = p.id \ + FROM packages p JOIN links l ON p.id = l.package AND l.status IN (0, 4, 13) GROUP BY p.id) s ON s.id = p.id \ GROUP BY p.id') - #try to lower ids + # try to lower ids self.c.execute('SELECT max(id) FROM LINKS') fid = self.c.fetchone()[0] - if fid: - fid = int(fid) - else: - fid = 0 + fid = int(fid) if fid else 0 self.c.execute('UPDATE SQLITE_SEQUENCE SET seq=? WHERE name=?', (fid, "links")) - self.c.execute('SELECT max(id) FROM packages') pid = self.c.fetchone()[0] - if pid: - pid = int(pid) - else: - pid = 0 + pid = int(pid) if pid else 0 self.c.execute('UPDATE SQLITE_SEQUENCE SET seq=? WHERE name=?', (pid, "packages")) self.c.execute('VACUUM') @@ -265,7 +264,7 @@ class DatabaseBackend(Thread): print "Converting old Django DB" conn = sqlite3.connect('pyload.db') c = conn.cursor() - c.execute("SELECT username, password, email from auth_user WHERE is_superuser") + c.execute("SELECT username, password, email FROM auth_user WHERE is_superuser") users = [] for r in c: pw = r[1].split("$") diff --git a/pyload/database/File.py b/pyload/database/File.py index 7cbe1890a..a49ba6d3a 100644 --- a/pyload/database/File.py +++ b/pyload/database/File.py @@ -2,7 +2,6 @@ # @author: RaNaN, mkaay from threading import RLock -from time import time from pyload.utils import formatSize, lock from pyload.manager.Event import InsertEvent, ReloadAllEvent, RemoveEvent, UpdateEvent @@ -25,7 +24,9 @@ class FileHandler(object): self.core = core # translations - self.statusMsg = [_("finished"), _("offline"), _("online"), _("queued"), _("skipped"), _("waiting"), _("temp. offline"), _("starting"), _("failed"), _("aborted"), _("decrypting"), _("custom"), _("downloading"), _("processing"), _("unknown")] + self.statusMsg = [_("finished"), _("offline"), _("online"), _("queued"), _("skipped"), _("waiting"), + _("temp. offline"), _("starting"), _("failed"), _("aborted"), _("decrypting"), _("custom"), + _("downloading"), _("processing"), _("unknown")] self.cache = {} # holds instances for files self.packageCache = {} # same for packages @@ -34,7 +35,7 @@ class FileHandler(object): self.jobCache = {} self.lock = RLock() #@TODO: should be a Lock w/o R - #self.lock._Verbose__verbose = True + # self.lock._Verbose__verbose = True self.filecount = -1 # if an invalid value is set get current value from db self.queuecount = -1 # number of package to be loaded @@ -52,6 +53,7 @@ class FileHandler(object): args[0].queuecount = -1 args[0].jobCache = {} return func(*args) + return new @@ -149,7 +151,8 @@ class FileHandler(object): p = self.getPackage(id) if not p: - if id in self.packageCache: del self.packageCache[id] + if id in self.packageCache: + del self.packageCache[id] return oldorder = p.order @@ -349,7 +352,7 @@ class FileHandler(object): #@TODO: maybe the new job has to be approved... - #pyfile = self.getFile(self.jobCache[occ].pop()) + # pyfile = self.getFile(self.jobCache[occ].pop()) return pyfile @@ -498,11 +501,11 @@ class FileHandler(object): 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: + if position <= pack.order < p.order: pack.order += 1 pack.notifyChange() elif p.order < position: - if pack.order <= position and pack.order > p.order: + if position >= pack.order > p.order: pack.order -= 1 pack.notifyChange() @@ -529,11 +532,11 @@ class FileHandler(object): if pyfile.packageid != f['package'] or pyfile.order < 0: continue if f['order'] > position: - if pyfile.order >= position and pyfile.order < f['order']: + if position <= pyfile.order < f['order']: pyfile.order += 1 pyfile.notifyChange() elif f['order'] < position: - if pyfile.order <= position and pyfile.order > f['order']: + if position >= pyfile.order > f['order']: pyfile.order -= 1 pyfile.notifyChange() @@ -592,11 +595,9 @@ class FileHandler(object): new_packs.update(self.db.getAllPackages(1)) # get new packages only from db - deleted = [] - for id in old_packs.iterkeys(): - if id not in new_packs: - deleted.append(id) - self.deletePackage(int(id)) + deleted = [id for id in old_packs.iterkeys() if id not in new_packs] + for id_deleted in deleted: + self.deletePackage(int(id_deleted)) return deleted @@ -614,21 +615,26 @@ class FileMethods(object): @style.queue def filecount(self, queue): """returns number of files in queue""" - self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=?", (queue,)) + self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=?", + (queue,)) return self.c.fetchone()[0] @style.queue def queuecount(self, queue): """ number of files in queue not finished yet""" - self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status NOT IN (0, 4)", (queue,)) + self.c.execute( + "SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status NOT IN (0, 4)", + (queue,)) return self.c.fetchone()[0] @style.queue def processcount(self, queue, fid): """ number of files which have to be proccessed """ - self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status IN (2, 3, 5, 7, 12) AND l.id != ?", (queue, str(fid))) + self.c.execute( + "SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status IN (2, 3, 5, 7, 12) AND l.id != ?", + (queue, str(fid))) return self.c.fetchone()[0] @@ -655,7 +661,8 @@ class FileMethods(object): @style.queue def addLink(self, url, name, plugin, package): order = self._nextFileOrder(package) - self.c.execute('INSERT INTO links(url, name, plugin, package, linkorder) VALUES(?,?,?,?,?)', (url, name, ".".join(plugintype, pluginname), package, order)) + self.c.execute('INSERT INTO links(url, name, plugin, package, linkorder) VALUES(?,?,?,?,?)', + (url, name, ".".join(plugintype, pluginname), package, order)) return self.c.lastrowid @@ -663,7 +670,7 @@ class FileMethods(object): def addLinks(self, links, package): """ links is a list of tupels (url, plugin)""" order = self._nextFileOrder(package) - orders = [order + x for x in range(len(links))] + orders = [order + x for x in xrange(len(links))] links = [(x[0], x[0], ".".join((x[1], x[2])), package, o) for x, o in zip(links, orders)] self.c.executemany('INSERT INTO links(url, name, plugin, package, linkorder) VALUES(?,?,?,?,?)', links) @@ -671,7 +678,8 @@ class FileMethods(object): @style.queue def addPackage(self, name, folder, queue): order = self._nextPackageOrder(queue) - self.c.execute('INSERT INTO packages(name, folder, queue, packageorder) VALUES(?,?,?,?)', (name, folder, queue, order)) + self.c.execute('INSERT INTO packages(name, folder, queue, packageorder) VALUES(?,?,?,?)', + (name, folder, queue, order)) return self.c.lastrowid @@ -679,13 +687,15 @@ class FileMethods(object): def deletePackage(self, p): self.c.execute('DELETE FROM links WHERE package=?', (str(p.id),)) self.c.execute('DELETE FROM packages WHERE id=?', (str(p.id),)) - self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder > ? AND queue=?', (p.order, p.queue)) + self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder > ? AND queue=?', + (p.order, p.queue)) @style.queue def deleteLink(self, f): self.c.execute('DELETE FROM links WHERE id=?', (str(f.id),)) - self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder > ? AND package=?', (f.order, str(f.packageid))) + self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder > ? AND package=?', + (f.order, str(f.packageid))) @style.queue @@ -702,7 +712,9 @@ class FileMethods(object): } """ - self.c.execute('SELECT l.id, l.url, l.name, l.size, l.status, l.error, l.plugin, l.package, l.linkorder FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? ORDER BY l.linkorder', (q,)) + self.c.execute( + 'SELECT l.id, l.url, l.name, l.size, l.status, l.error, l.plugin, l.package, l.linkorder FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? ORDER BY l.linkorder', + (q,)) data = {} for r in self.c: data[r[0]] = { @@ -763,7 +775,8 @@ class FileMethods(object): @style.queue def getLinkData(self, id): """get link information as dict""" - self.c.execute('SELECT id, url, name, size, status, error, plugin, package, linkorder FROM links WHERE id=?', (str(id),)) + self.c.execute('SELECT id, url, name, size, status, error, plugin, package, linkorder FROM links WHERE id=?', + (str(id),)) data = {} r = self.c.fetchone() if not r: @@ -788,7 +801,9 @@ class FileMethods(object): @style.queue def getPackageData(self, id): """get data about links for a package""" - self.c.execute('SELECT id, url, name, size, status, error, plugin, package, linkorder FROM links WHERE package=? ORDER BY linkorder', (str(id),)) + self.c.execute( + 'SELECT id, url, name, size, status, error, plugin, package, linkorder FROM links WHERE package=? ORDER BY linkorder', + (str(id),)) data = {} for r in self.c: @@ -811,13 +826,14 @@ class FileMethods(object): @style.async def updateLink(self, f): - self.c.execute('UPDATE links SET url=?, name=?, size=?, status=?, error=?, package=? WHERE id=?', (f.url, f.name, f.size, f.status, str(f.error), str(f.packageid), str(f.id))) + self.c.execute('UPDATE links SET url=?, name=?, size=?, status=?, error=?, package=? WHERE id=?', + (f.url, f.name, f.size, f.status, str(f.error), str(f.packageid), str(f.id))) @style.queue def updatePackage(self, p): - self.c.execute('UPDATE packages SET name=?, folder=?, site=?, password=?, queue=? WHERE id=?', (p.name, p.folder, p.site, p.password, p.queue, str(p.id))) - + self.c.execute('UPDATE packages SET name=?, folder=?, site=?, password=?, queue=? WHERE id=?', + (p.name, p.folder, p.site, p.password, p.queue, str(p.id))) @style.queue def updateLinkInfo(self, data): @@ -836,9 +852,13 @@ class FileMethods(object): position = self._nextPackageOrder(p.queue) if not noMove: if p.order > position: - self.c.execute('UPDATE packages SET packageorder=packageorder+1 WHERE packageorder >= ? AND packageorder < ? AND queue=? AND packageorder >= 0', (position, p.order, p.queue)) + self.c.execute( + 'UPDATE packages SET packageorder=packageorder+1 WHERE packageorder >= ? AND packageorder < ? AND queue=? AND packageorder >= 0', + (position, p.order, p.queue)) elif p.order < position: - self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder <= ? AND packageorder > ? AND queue=? AND packageorder >= 0', (position, p.order, p.queue)) + self.c.execute( + 'UPDATE packages SET packageorder=packageorder-1 WHERE packageorder <= ? AND packageorder > ? AND queue=? AND packageorder >= 0', + (position, p.order, p.queue)) self.c.execute('UPDATE packages SET packageorder=? WHERE id=?', (position, str(p.id))) @@ -847,9 +867,11 @@ class FileMethods(object): 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'])) + 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=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'])) @@ -857,7 +879,8 @@ class FileMethods(object): @style.queue def clearPackageOrder(self, p): self.c.execute('UPDATE packages SET packageorder=? WHERE id=?', (-1, str(p.id))) - self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder > ? AND queue=? AND id != ?', (p.order, p.queue, str(p.id))) + self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder > ? AND queue=? AND id != ?', + (p.order, p.queue, str(p.id))) @style.async @@ -877,7 +900,7 @@ class FileMethods(object): r = self.c.fetchone() if not r: return None - return PyPackage(self.manager, id, * r) + return PyPackage(self.manager, id, *r) #-------------------------------------------------------------------------- @@ -885,13 +908,14 @@ class FileMethods(object): @style.queue def getFile(self, id): """return link instance from id""" - self.c.execute("SELECT url, name, size, status, error, plugin, package, linkorder FROM links WHERE id=?", (str(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 r = list(r) r[5] = tuple(r[5].split('.')) - return PyFile(self.manager, id, * r) + return PyFile(self.manager, id, *r) @style.queue @@ -947,7 +971,9 @@ class FileMethods(object): @style.queue def findDuplicates(self, id, folder, filename): """ checks if filename exists with different id and same package """ - self.c.execute("SELECT l.plugin FROM links as l INNER JOIN packages as p ON l.package=p.id AND p.folder=? WHERE l.id!=? AND l.status=0 AND l.name=?", (folder, id, filename)) + self.c.execute( + "SELECT l.plugin FROM links as l INNER JOIN packages as p ON l.package=p.id AND p.folder=? WHERE l.id!=? AND l.status=0 AND l.name=?", + (folder, id, filename)) return self.c.fetchone() @@ -956,4 +982,5 @@ class FileMethods(object): self.c.execute("DELETE FROM links;") self.c.execute("DELETE FROM packages;") + DatabaseBackend.registerSub(FileMethods) diff --git a/pyload/database/Storage.py b/pyload/database/Storage.py index 45ad18b2d..70932b55c 100644 --- a/pyload/database/Storage.py +++ b/pyload/database/Storage.py @@ -26,14 +26,12 @@ class StorageMethods(object): return row[0] else: db.c.execute("SELECT key, value FROM storage WHERE identifier=?", (identifier,)) - d = {} - for row in db.c: - d[row[0]] = row[1] - return d + return {row[0]: row[1] for row in db.c} @style.queue def delStorage(db, identifier, key): db.c.execute("DELETE FROM storage WHERE identifier=? AND key=?", (identifier, key)) + DatabaseBackend.registerSub(StorageMethods) diff --git a/pyload/database/User.py b/pyload/database/User.py index e11961e32..2aedc3bba 100644 --- a/pyload/database/User.py +++ b/pyload/database/User.py @@ -30,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 xrange(0, 5)]) h = sha1(salt + password) password = salt + h.hexdigest() @@ -53,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 xrange(0, 5)]) h = sha1(salt + newpw) password = salt + h.hexdigest() @@ -76,24 +76,18 @@ class UserMethods(object): @style.queue def listUsers(db): db.c.execute('SELECT name FROM users') - users = [] - for row in db.c: - users.append(row[0]) - return users + return [row[0] for row in db.c] @style.queue def getAllUserData(db): db.c.execute("SELECT name, permission, role, template, email FROM users") - user = {} - for r in db.c: - user[r[0]] = {"permission": r[1], "role": r[2], "template": r[3], "email": r[4]} - - return user + return {{"permission": r[1], "role": r[2], "template": r[3], "email": r[4]} for r in db.c} @style.queue def removeUser(db, user): db.c.execute('DELETE FROM users WHERE name=?', (user,)) + DatabaseBackend.registerSub(UserMethods) diff --git a/pyload/manager/Thread.py b/pyload/manager/Thread.py index a8550e504..782cf7b2a 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 xrange(0, self.core.config.get("download", "max_downloads")): self.createThread() @@ -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 xrange(10): try: sv = choice(services) ip = getURL(sv[0]) diff --git a/pyload/manager/thread/Plugin.py b/pyload/manager/thread/Plugin.py index 08a2664da..348f005a5 100644 --- a/pyload/manager/thread/Plugin.py +++ b/pyload/manager/thread/Plugin.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # @author: RaNaN +from __future__ import with_statement + from Queue import Queue from threading import Thread from os import listdir, stat @@ -64,9 +66,8 @@ class PluginThread(Thread): self.m.log.debug("Error creating zip file: %s" % e) dump_name = dump_name.replace(".zip", ".txt") - f = open(dump_name, "wb") - f.write(dump) - f.close() + with open(dump_name, "wb") as f: + f.write(dump) self.m.core.log.info("Debug Report written to %s" % dump_name) diff --git a/pyload/network/Browser.py b/pyload/network/Browser.py index d8617fabc..a499336c3 100644 --- a/pyload/network/Browser.py +++ b/pyload/network/Browser.py @@ -124,7 +124,8 @@ class Browser(object): def removeAuth(self): - if "auth" in self.options: del self.options['auth'] + if "auth" in self.options: + del self.options['auth'] self.renewHTTPRequest() @@ -134,7 +135,8 @@ class Browser(object): def deleteOption(self, name): - if name in self.options: del self.options[name] + if name in self.options: + del self.options[name] def clearHeaders(self): diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py index 784b64349..86c88fe8e 100644 --- a/pyload/network/HTTPChunk.py +++ b/pyload/network/HTTPChunk.py @@ -51,7 +51,7 @@ class ChunkInfo(object): chunk_size = self.size / chunks current = 0 - for i in range(chunks): + for i in xrange(chunks): end = self.size - 1 if (i == chunks - 1) else current + chunk_size self.addChunk("%s.chunk%s" % (self.name, i), (current, end)) current += chunk_size + 1 @@ -310,7 +310,8 @@ class HTTPChunk(HTTPRequest): """ closes everything, unusable after this """ if self.fp: self.fp.close() self.c.close() - if hasattr(self, "p"): del self.p + if hasattr(self, "p"): + del self.p def charEnc(enc): diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py index 13666195a..8bf822a15 100644 --- a/pyload/network/HTTPDownload.py +++ b/pyload/network/HTTPDownload.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # @author: RaNaN +from __future__ import with_statement + from os import remove, fsync from os.path import dirname from time import sleep, time @@ -81,27 +83,24 @@ class HTTPDownload(object): init = fs_encode(self.info.getChunkName(0)) #: initial chunk name if self.info.getCount() > 1: - fo = open(init, "rb+") #: first chunkfile - for i in range(1, self.info.getCount()): - #input file - fo.seek( - self.info.getChunkRange(i - 1)[1] + 1) #: seek to beginning of chunk, to get rid of overlapping chunks - fname = fs_encode("%s.chunk%d" % (self.filename, i)) - fi = open(fname, "rb") - buf = 32 * 1024 - while True: #: copy in chunks, consumes less memory - data = fi.read(buf) - if not data: - break - fo.write(data) - fi.close() - if fo.tell() < self.info.getChunkRange(i)[1]: - fo.close() - remove(init) - self.info.remove() #: there are probably invalid chunks - raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.") - remove(fname) #: remove chunk - fo.close() + with open(init, "rb+") as fo: #: first chunkfile + for i in xrange(1, self.info.getCount()): + #input file + fo.seek( + self.info.getChunkRange(i - 1)[1] + 1) #: seek to beginning of chunk, to get rid of overlapping chunks + fname = fs_encode("%s.chunk%d" % (self.filename, i)) + with open(fname, "rb") as fi: + buf = 32 * 1024 + while True: #: copy in chunks, consumes less memory + data = fi.read(buf) + if not data: + break + fo.write(data) + if fo.tell() < self.info.getChunkRange(i)[1]: + remove(init) + self.info.remove() #: there are probably invalid chunks + raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.") + remove(fname) #: remove chunk if self.nameDisposition and self.disposition: self.filename = fs_join(dirname(self.filename), self.nameDisposition) @@ -174,7 +173,7 @@ class HTTPDownload(object): init.setRange(self.info.getChunkRange(0)) - for i in range(1, chunks): + for i in xrange(1, chunks): c = HTTPChunk(i, self, self.info.getChunkRange(i), resume) handle = c.getHandle() diff --git a/pyload/network/HTTPRequest.py b/pyload/network/HTTPRequest.py index 62c0ef72b..d87a3ee7e 100644 --- a/pyload/network/HTTPRequest.py +++ b/pyload/network/HTTPRequest.py @@ -24,7 +24,7 @@ def myurlencode(data): data = dict(data) return urlencode(dict((encode(x), encode(y)) for x, y in data.iteritems())) -bad_headers = range(400, 404) + range(405, 418) + range(500, 506) +bad_headers = xrange(400, 404) + xrange(405, 418) + xrange(500, 506) class BadHeader(Exception): diff --git a/pyload/plugin/crypter/DevhostSt.py b/pyload/plugin/crypter/DevhostSt.py index 4fb82e0ad..46d33885f 100644 --- a/pyload/plugin/crypter/DevhostSt.py +++ b/pyload/plugin/crypter/DevhostSt.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# http://d-h.st/users/shine/?fld_id=37263#files +# http://d-h.st/users/shine/?fld_id=37263#files import re diff --git a/pyload/plugin/hoster/CzshareCom.py b/pyload/plugin/hoster/CzshareCom.py index da9aa68d5..9926c8d74 100644 --- a/pyload/plugin/hoster/CzshareCom.py +++ b/pyload/plugin/hoster/CzshareCom.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# http://czshare.com/5278880/random.bin +# http://czshare.com/5278880/random.bin import re diff --git a/pyload/plugin/hoster/DataHu.py b/pyload/plugin/hoster/DataHu.py index 1f44e62e5..ba3576d10 100644 --- a/pyload/plugin/hoster/DataHu.py +++ b/pyload/plugin/hoster/DataHu.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# http://data.hu/get/6381232/random.bin +# http://data.hu/get/6381232/random.bin import re diff --git a/pyload/plugin/hoster/FileomCom.py b/pyload/plugin/hoster/FileomCom.py index bac912c56..b01b34db0 100644 --- a/pyload/plugin/hoster/FileomCom.py +++ b/pyload/plugin/hoster/FileomCom.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# http://fileom.com/gycaytyzdw3g/random.bin.html +# http://fileom.com/gycaytyzdw3g/random.bin.html from pyload.plugin.internal.XFSHoster import XFSHoster diff --git a/pyload/plugin/hoster/FilepupNet.py b/pyload/plugin/hoster/FilepupNet.py index 72237285c..91d640e00 100644 --- a/pyload/plugin/hoster/FilepupNet.py +++ b/pyload/plugin/hoster/FilepupNet.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # # Test links: -# http://www.filepup.net/files/k5w4ZVoF1410184283.html -# http://www.filepup.net/files/R4GBq9XH1410186553.html +# http://www.filepup.net/files/k5w4ZVoF1410184283.html +# http://www.filepup.net/files/R4GBq9XH1410186553.html import re diff --git a/pyload/plugin/hoster/FilerNet.py b/pyload/plugin/hoster/FilerNet.py index 86a5809da..fbefba8db 100644 --- a/pyload/plugin/hoster/FilerNet.py +++ b/pyload/plugin/hoster/FilerNet.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # # Test links: -# http://filer.net/get/ivgf5ztw53et3ogd -# http://filer.net/get/hgo14gzcng3scbvv +# http://filer.net/get/ivgf5ztw53et3ogd +# http://filer.net/get/hgo14gzcng3scbvv import pycurl import re diff --git a/pyload/plugin/hoster/GooIm.py b/pyload/plugin/hoster/GooIm.py index 8fd958660..322dd6101 100644 --- a/pyload/plugin/hoster/GooIm.py +++ b/pyload/plugin/hoster/GooIm.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# https://goo.im/devs/liquidsmooth/3.x/codina/Nightly/LS-KK-v3.2-2014-08-01-codina.zip +# https://goo.im/devs/liquidsmooth/3.x/codina/Nightly/LS-KK-v3.2-2014-08-01-codina.zip import re diff --git a/pyload/plugin/hoster/LetitbitNet.py b/pyload/plugin/hoster/LetitbitNet.py index 0cfc225e4..35f5f9cf4 100644 --- a/pyload/plugin/hoster/LetitbitNet.py +++ b/pyload/plugin/hoster/LetitbitNet.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- # # API Documentation: -# http://api.letitbit.net/reg/static/api.pdf +# http://api.letitbit.net/reg/static/api.pdf # # Test links: -# http://letitbit.net/download/07874.0b5709a7d3beee2408bb1f2eefce/random.bin.html +# http://letitbit.net/download/07874.0b5709a7d3beee2408bb1f2eefce/random.bin.html import re diff --git a/pyload/plugin/hoster/LoadTo.py b/pyload/plugin/hoster/LoadTo.py index 0b4d40fe9..3a625dbe3 100644 --- a/pyload/plugin/hoster/LoadTo.py +++ b/pyload/plugin/hoster/LoadTo.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # # Test links: -# http://www.load.to/JWydcofUY6/random.bin -# http://www.load.to/oeSmrfkXE/random100.bin +# http://www.load.to/JWydcofUY6/random.bin +# http://www.load.to/oeSmrfkXE/random100.bin import re diff --git a/pyload/plugin/hoster/MegaRapidoNet.py b/pyload/plugin/hoster/MegaRapidoNet.py index 311189d1c..54a167b65 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 xrange(1, n + 1): r = randint(0, 9) if(r > 0): not_zero += 1 diff --git a/pyload/plugin/hoster/NovafileCom.py b/pyload/plugin/hoster/NovafileCom.py index 82f92959b..f76d77269 100644 --- a/pyload/plugin/hoster/NovafileCom.py +++ b/pyload/plugin/hoster/NovafileCom.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # # Test links: -# http://novafile.com/vfun4z6o2cit -# http://novafile.com/s6zrr5wemuz4 +# http://novafile.com/vfun4z6o2cit +# http://novafile.com/s6zrr5wemuz4 from pyload.plugin.internal.XFSHoster import XFSHoster diff --git a/pyload/plugin/hoster/OboomCom.py b/pyload/plugin/hoster/OboomCom.py index 07c40a397..c37e89339 100644 --- a/pyload/plugin/hoster/OboomCom.py +++ b/pyload/plugin/hoster/OboomCom.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# https://www.oboom.com/B7CYZIEB/10Mio.dat +# https://www.oboom.com/B7CYZIEB/10Mio.dat import re diff --git a/pyload/plugin/hoster/RemixshareCom.py b/pyload/plugin/hoster/RemixshareCom.py index 6e376fd6d..ba61887cd 100644 --- a/pyload/plugin/hoster/RemixshareCom.py +++ b/pyload/plugin/hoster/RemixshareCom.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- # # Test links: -# http://remixshare.com/download/z8uli +# http://remixshare.com/download/z8uli # # Note: -# The remixshare.com website is very very slow, so -# if your download not starts because of pycurl timeouts: -# Adjust timeouts in /usr/share/pyload/pyload/network/HTTPRequest.py +# The remixshare.com website is very very slow, so +# if your download not starts because of pycurl timeouts: +# Adjust timeouts in /usr/share/pyload/pyload/network/HTTPRequest.py import re diff --git a/pyload/plugin/hoster/SolidfilesCom.py b/pyload/plugin/hoster/SolidfilesCom.py index 39e5dd010..9998f26ad 100644 --- a/pyload/plugin/hoster/SolidfilesCom.py +++ b/pyload/plugin/hoster/SolidfilesCom.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# http://www.solidfiles.com/d/609cdb4b1b +# http://www.solidfiles.com/d/609cdb4b1b from pyload.plugin.internal.SimpleHoster import SimpleHoster diff --git a/pyload/plugin/hoster/SpeedyshareCom.py b/pyload/plugin/hoster/SpeedyshareCom.py index 99626c765..b6d0a5898 100644 --- a/pyload/plugin/hoster/SpeedyshareCom.py +++ b/pyload/plugin/hoster/SpeedyshareCom.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# http://speedy.sh/ep2qY/Zapp-Brannigan.jpg +# http://speedy.sh/ep2qY/Zapp-Brannigan.jpg import re diff --git a/pyload/plugin/hoster/UploadheroCom.py b/pyload/plugin/hoster/UploadheroCom.py index 912f4c505..d1c9fd2c7 100644 --- a/pyload/plugin/hoster/UploadheroCom.py +++ b/pyload/plugin/hoster/UploadheroCom.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# http://uploadhero.co/dl/wQBRAVSM +# http://uploadhero.co/dl/wQBRAVSM import re diff --git a/pyload/plugin/hoster/VidPlayNet.py b/pyload/plugin/hoster/VidPlayNet.py index ab571f9ea..5d98d2fb3 100644 --- a/pyload/plugin/hoster/VidPlayNet.py +++ b/pyload/plugin/hoster/VidPlayNet.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # Test links: -# BigBuckBunny_320x180.mp4 - 61.7 Mb - http://vidplay.net/38lkev0h3jv0 +# http://vidplay.net/38lkev0h3jv0 from pyload.plugin.internal.XFSHoster import XFSHoster diff --git a/pyload/remote/socketbackend/create_ttypes.py b/pyload/remote/socketbackend/create_ttypes.py index 9b001f1bf..26dd5d06b 100644 --- a/pyload/remote/socketbackend/create_ttypes.py +++ b/pyload/remote/socketbackend/create_ttypes.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + import inspect import os import platform @@ -30,10 +32,9 @@ def main(): enums.append(klass) - f = open(os.path.join(pypath, "pyload", "api", "types.py"), "wb") - - f.write( - """# -*- coding: utf-8 -*- + with open(os.path.join(pypath, "pyload", "api", "types.py"), "wb") as f: + f.write( +"""# -*- coding: utf-8 -*- # Autogenerated by pyload # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING diff --git a/pyload/remote/thriftbackend/ThriftTest.py b/pyload/remote/thriftbackend/ThriftTest.py index 0c5ea4783..ed4557e2d 100644 --- a/pyload/remote/thriftbackend/ThriftTest.py +++ b/pyload/remote/thriftbackend/ThriftTest.py @@ -25,7 +25,7 @@ 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 xrange(0, 100)] e = time() try: print "%s: %f s" % (f._Method__name, e-s) diff --git a/pyload/webui/app/cnl.py b/pyload/webui/app/cnl.py index 73087ad2d..b6cbd6b55 100644 --- a/pyload/webui/app/cnl.py +++ b/pyload/webui/app/cnl.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- + +from __future__ import with_statement + from os.path import join import re from urllib import unquote @@ -57,9 +60,8 @@ def addcrypted(): dlc = request.forms['crypted'].replace(" ", "+") dlc_path = join(DL_ROOT, package.replace("/", "").replace("\\", "").replace(":", "") + ".dlc") - dlc_file = open(dlc_path, "wb") - dlc_file.write(dlc) - dlc_file.close() + with open(dlc_path, "wb") as dlc_file: + dlc_file.write(dlc) try: PYLOAD.addPackage(package, [dlc_path], 0) diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py index 0805e9f5b..30778f1f7 100644 --- a/pyload/webui/app/json.py +++ b/pyload/webui/app/json.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + from os.path import join from traceback import print_exc from shutil import copyfileobj @@ -166,9 +168,8 @@ def add_package(): name = f.name fpath = join(PYLOAD.getConfigValue("general", "download_folder"), "tmp_" + f.filename) - destination = open(fpath, 'wb') - copyfileobj(f.file, destination) - destination.close() + with open(fpath, 'wb') as destination: + copyfileobj(f.file, destination) links.insert(0, fpath) except Exception: pass diff --git a/pyload/webui/filters.py b/pyload/webui/filters.py index ea4b159fa..e11944c94 100644 --- a/pyload/webui/filters.py +++ b/pyload/webui/filters.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + import os from os.path import abspath, commonprefix, join diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py index d17f81ae2..f4b082479 100644 --- a/tests/APIExerciser.py +++ b/tests/APIExerciser.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import with_statement + import string from threading import Thread from random import choice, sample, randint @@ -15,7 +17,7 @@ from pyload.remote.thriftbackend.ThriftClient import ThriftClient, Destination def createURLs(): """ create some urls, some may fail """ urls = [] - for x in range(0, randint(20, 100)): + for x in xrange(0, randint(20, 100)): name = "DEBUG_API" if randint(0, 5) == 5: name = "" #: this link will fail @@ -32,7 +34,7 @@ sumCalled = 0 def startApiExerciser(core, n): - for _i in range(n): + for _i in xrange(n): APIExerciser(core).start() @@ -60,32 +62,32 @@ 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 - out.write("\n" + "Starting\n") - out.flush() - - while True: - try: - self.testAPI() - except Exception: - self.core.log.error("Excerciser %d throw an execption" % self.id) - print_exc() - out.write(format_exc() + 2 * "\n") - out.flush() - - if not self.count % 100: - self.core.log.info("Exerciser %d tested %d api calls" % (self.id, self.count)) - if not self.count % 1000: - out.flush() - - if not sumCalled % 1000: #: not thread safe - self.core.log.info("Exercisers tested %d api calls" % sumCalled) - persec = sumCalled / (time() - self.time) - 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) + with open("error.log", "ab") as out: + # core errors are not logged of course + out.write("\n" + "Starting\n") + out.flush() + + while True: + try: + self.testAPI() + except Exception: + self.core.log.error("Excerciser %d throw an execption" % self.id) + print_exc() + out.write(format_exc() + 2 * "\n") + out.flush() + + if not self.count % 100: + self.core.log.info("Exerciser %d tested %d api calls" % (self.id, self.count)) + if not self.count % 1000: + out.flush() + + if not sumCalled % 1000: #: not thread safe + self.core.log.info("Exercisers tested %d api calls" % sumCalled) + persec = sumCalled / (time() - self.time) + 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) def testAPI(self): diff --git a/tests/test_api.py b/tests/test_api.py index 13e783d54..1e02d8aa3 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -20,5 +20,5 @@ class TestApi(object): @nottest def test_random(self): - for _i in range(0, 100): + for _i in xrange(0, 100): self.api.testAPI() |