diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-17 18:08:14 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-17 18:08:14 +0200 |
commit | ce939d413bd45abd3e09b3fb63dcf5a269578d56 (patch) | |
tree | f0ae4b5ffa1a68a122a718248140646bd985c310 | |
parent | PEP-8, Python Zen, refactor and reduce code (part 4 in master script). Bash v... (diff) | |
download | pyload-ce939d413bd45abd3e09b3fb63dcf5a269578d56.tar.xz |
PEP-8, Python Zen, refactor and reduce code (part 5 in master module/cli)
Conflicts:
module/cli/Handler.py
module/cli/printer.py
pyload/cli/AddPackage.py
pyload/cli/Cli.py
pyload/cli/ManageFiles.py
-rw-r--r-- | pyload/cli/AddPackage.py | 2 | ||||
-rw-r--r-- | pyload/cli/Cli.py | 75 | ||||
-rw-r--r-- | pyload/cli/ManageFiles.py | 39 |
3 files changed, 56 insertions, 60 deletions
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 7b30d5f44..a5348a776 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: @@ -52,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") @@ -78,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") @@ -136,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, "") @@ -163,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)) @@ -182,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))) @@ -210,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" @@ -313,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)): @@ -327,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() @@ -357,9 +357,12 @@ 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) @@ -440,21 +443,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 @@ -491,7 +494,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 @@ -517,7 +520,7 @@ def main(): 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) diff --git a/pyload/cli/ManageFiles.py b/pyload/cli/ManageFiles.py index 3bf8d1686..b95e6f2db 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 _ 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 _ 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(",")] |