summaryrefslogtreecommitdiffstats
path: root/pyLoadCli.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-19 22:50:37 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-19 22:50:37 +0200
commite083caef997b87150da03c05194baf8cd17f06a7 (patch)
tree36c64ad71c0ac5d5069d00f03e5cf7ee8ca887e2 /pyLoadCli.py
parentnew pyLoadCli input system (diff)
downloadpyload-e083caef997b87150da03c05194baf8cd17f06a7.tar.xz
some new cli stuff (no interactive functions yet)
Diffstat (limited to 'pyLoadCli.py')
-rw-r--r--pyLoadCli.py87
1 files changed, 65 insertions, 22 deletions
diff --git a/pyLoadCli.py b/pyLoadCli.py
index cc6963f23..f948e1fb5 100644
--- a/pyLoadCli.py
+++ b/pyLoadCli.py
@@ -26,13 +26,17 @@ from module.remote.ClientSocket import SocketThread
class pyLoadCli:
def __init__(self, adress, port, pw):
- os.system("clear")
- self.println(1, "pyLoad Command Line Interface")
- self.println(2, "")
self.thread = SocketThread(adress, int(port), pw, self)
self.getch = _Getch()
self.input = ""
+ self.pos = [0]
self.inputline = 0
+ self.menuline = 0
+
+ os.system("clear")
+ self.println(1, "pyLoad Command Line Interface")
+ self.println(2, "")
+
self.start()
def start(self):
@@ -40,49 +44,88 @@ class pyLoadCli:
#inp = raw_input()
inp = self.getch.impl()
if ord(inp) == 3:
+ os.system("clear")
sys.exit() # ctrl + c
elif ord(inp) == 13:
+ self.handle_input()
self.input = "" #enter
- self.println(self.inputline, self.input)
+ self.print_input()
elif ord(inp) == 127:
self.input = self.input[:-1] #backspace
- self.println(self.inputline, self.input)
+ self.print_input()
+ elif ord(inp) == 27: #ugly symbol
+ pass
else:
self.input += inp
- self.println(self.inputline, self.input)
+ self.print_input()
def format_time(self, seconds):
seconds = int(seconds)
- if seconds > 60:
- hours, seconds = divmod(seconds, 3600)
- minutes, seconds = divmod(seconds, 60)
- return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
- return _("%i seconds") % seconds
+
+ hours, seconds = divmod(seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
def println(self, line, content):
- print "\033["+ str(line) +";0H" + str(content) + " " * 60
+ print "\033["+ str(line) +";0H\033[2K" + str(content) + "\033["+ str((self.inputline if self.inputline > 0 else self.inputline + 1) - 1) +";0H"
+ def print_input(self):
+ self.println(self.inputline," Input: " + self.input)
def data_arrived(self, obj):
"""Handle incoming data"""
if obj.command == "update":
- #print obj.data
-
+ #print updated information
+ self.println(1, "pyLoad Command Line Interface")
+ self.println(2, "")
self.println(3, "%s Downloads" % (len(obj.data)))
line = 4
+ speed = 0
for download in obj.data:
if download["status"] == "downloading":
percent = download["percent"]
- z = percent / 2
- print "\033[" + str(line) + ";0H[" + z * "#" + (50-z) * " " + "] " + str(percent) + "% of " + download["name"]
+ z = percent / 4
+ speed += download['speed']
+ self.println(line, download["name"])
+ line += 1
+ self.println(line, "[" + z * "#" + (25-z) * " " + "] " + str(percent)+"% DL: "+str(int(download['speed']))+" kb/s ETA: " + self.format_time(download['eta']))
line += 1
- line += 2
- self.inputline = line + 2
- print("\033[" + str(line) + ";0HMeldungen:")
- for download in obj.data:
if download["status"] == "waiting":
- print "\033[" + str(line) + ";0HWarte %s auf Downlod Ticket für %s" % (self.format_time(download["wait_until"]), download["name"])
+ self.println(line, download["name"])
+ line += 1
+ self.println(line, "waiting")
line += 1
+
+ line += 1
+ self.println(line, "Status: paused" if obj.status['pause'] else "Status: running" + " Speed: "+ str(int(speed))+" kb/s Files in queue: "+ str(obj.status["queue"]) )
+ line += 1
+ self.println(line, "")
+ line += 1
+ self.menuline = line
+
+ self.build_menu()
+
+ def build_menu(self):
+ line = self.menuline
+ self.println(line, "Menu:")
+ line += 1
+ if self.pos[0] == 0:# main menu
+ self.println(line, "1. Add Link")
+ line += 1
+ self.println(line, "2. Remove Link")
+ line += 1
+ self.println(line, "3. Pause Server")
+ line += 1
+ self.println(line, "4. Kill Server")
+ line += 1
+ self.println(line, "5. Quit")
+ line += 1
+
+ self.inputline = line +1
+ self.print_input()
+
+ def handle_input(self):
+ input = self.input
class _Getch:
"""Gets a single character from standard input. Does not echo to the screen."""
@@ -134,4 +177,4 @@ if __name__ == "__main__":
#password = "pwhere"
cli = pyLoadCli(address, port, password)
else:
- cli = pyLoadCli( * sys.argv[1:]) \ No newline at end of file
+ cli = pyLoadCli( * sys.argv[1:])