diff options
| author | 2009-06-19 22:50:37 +0200 | |
|---|---|---|
| committer | 2009-06-19 22:50:37 +0200 | |
| commit | e083caef997b87150da03c05194baf8cd17f06a7 (patch) | |
| tree | 36c64ad71c0ac5d5069d00f03e5cf7ee8ca887e2 | |
| parent | new pyLoadCli input system (diff) | |
| download | pyload-e083caef997b87150da03c05194baf8cd17f06a7.tar.xz | |
some new cli stuff (no interactive functions yet)
| -rw-r--r-- | module/remote/RequestObject.py | 3 | ||||
| -rw-r--r-- | pyLoadCli.py | 87 | ||||
| -rw-r--r-- | pyLoadCore.py | 9 | 
3 files changed, 75 insertions, 24 deletions
| diff --git a/module/remote/RequestObject.py b/module/remote/RequestObject.py index 07f22cd17..0141b5e1d 100644 --- a/module/remote/RequestObject.py +++ b/module/remote/RequestObject.py @@ -11,8 +11,9 @@ class RequestObject(object):      def __init__(self):          self.version = 0          self.sender = "ip" +        self.status = {}          self.command = None          self.function = ""          self.args = []          self.response = None -        self.data = None
\ No newline at end of file +        self.data = None 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:]) diff --git a/pyLoadCore.py b/pyLoadCore.py index 2f89b9af6..84d1322dd 100644 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -221,9 +221,16 @@ class Core(object):          obj = RequestObject()          obj.command = "update"          obj.data = self.get_downloads() - +        obj.status = self.server_status()          self.server.push_all(obj) +    def server_status(self): +        status = {} +        status['pause'] = self.thread_list.pause +        status['queue'] = len(self.file_list.files) +        return status + +      def init_server(self):          self.server = ServerThread(self)          self.server.start() | 
