diff options
Diffstat (limited to 'pyload/cli/Cli.py')
-rw-r--r-- | pyload/cli/Cli.py | 119 |
1 files changed, 62 insertions, 57 deletions
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.") |