From f162ae0de0f71391c56957389cc3c8babc8022e1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Apr 2015 16:37:00 +0200 Subject: Use with statement --- pyload/Core.py | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'pyload/Core.py') diff --git a/pyload/Core.py b/pyload/Core.py index f723d8366..481026a68 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...")) -- cgit v1.2.3 From e1c22fad3fffb485da400e4b34c094f201a2c72e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Apr 2015 18:03:46 +0200 Subject: range -> xrange --- pyload/Core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyload/Core.py') diff --git a/pyload/Core.py b/pyload/Core.py index 481026a68..d1404d00f 100755 --- a/pyload/Core.py +++ b/pyload/Core.py @@ -612,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: @@ -678,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) -- cgit v1.2.3 From 5a86c3cb1db6cd87bf9ae22e09dd209cecc0a363 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 20 Apr 2015 22:48:30 +0200 Subject: Spare code cosmetics (8) --- pyload/Core.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'pyload/Core.py') diff --git a/pyload/Core.py b/pyload/Core.py index d1404d00f..ae6bde4a9 100755 --- a/pyload/Core.py +++ b/pyload/Core.py @@ -137,7 +137,7 @@ class Core(object): print "" print " -v, --version", " " * 10, "Print version to terminal" print " -c, --clear", " " * 12, "Delete all saved packages/links" - #print " -a, --add=", " " * 2, "Add the specified links" + # print " -a, --add=", " " * 2, "Add the specified links" print " -u, --user", " " * 13, "Manages users" print " -d, --debug", " " * 12, "Enable debug mode" print " -s, --setup", " " * 12, "Run Setup Assistant" @@ -339,10 +339,10 @@ class Core(object): self.log.debug("Remote activated: %s" % self.remote) self.check_install("Crypto", _("pycrypto to decode container files")) - #img = self.check_install("Image", _("Python Image Library (PIL) for captcha reading")) - #self.check_install("pycurl", _("pycurl to download any files"), True, True) + # img = self.check_install("Image", _("Python Image Library (PIL) for captcha reading")) + # self.check_install("pycurl", _("pycurl to download any files"), True, True) self.check_file("tmp", _("folder for temporary files"), True) - #tesser = self.check_install("tesseract", _("tesseract for captcha reading"), False) if os.name != "nt" else True + # tesser = self.check_install("tesseract", _("tesseract for captcha reading"), False) if os.name != "nt" else True self.captcha = True #: checks seems to fail, although tesseract is available @@ -379,7 +379,7 @@ class Core(object): self.scheduler = Scheduler(self) - #hell yeah, so many important managers :D + # hell yeah, so many important managers :D self.pluginManager = PluginManager(self) self.pullManager = PullManager(self) self.accountManager = AccountManager(self) @@ -417,7 +417,7 @@ class Core(object): if f.read().strip(): self.api.addPackage("links.txt", [link_file], 1) - #self.scheduler.addJob(0, self.accountManager.getAccountInfos) + # self.scheduler.addJob(0, self.accountManager.getAccountInfos) self.log.info(_("Activating Accounts...")) self.accountManager.getAccountInfos() @@ -592,7 +592,7 @@ class Core(object): if not file_exists and not quiet: if file_created: - #self.log.info( _("%s created") % description ) + # self.log.info( _("%s created") % description ) pass else: if not empty: -- cgit v1.2.3 From 892b7cbd4981b764bed30b2ccc5ca73d791c39f2 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 20 Apr 2015 22:56:34 +0200 Subject: Spare code cosmetics (9) --- pyload/Core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyload/Core.py') diff --git a/pyload/Core.py b/pyload/Core.py index ae6bde4a9..e833314f0 100755 --- a/pyload/Core.py +++ b/pyload/Core.py @@ -198,7 +198,7 @@ class Core(object): if not pid or os.name == "nt": return False try: - os.kill(pid, 0) # 0 - default signal (does nothing) + os.kill(pid, 0) #: 0 - default signal (does nothing) except Exception: return 0 -- cgit v1.2.3