From 1d3b74dc93d403783924c654cc22f3304a1d7f0a Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 25 Nov 2009 18:55:38 +0100 Subject: basic curses cli --- pyLoadCli.py | 527 ++++++++++++++++++++++++----------------------------------- 1 file changed, 210 insertions(+), 317 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index fd65e04da..186281e32 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -1,77 +1,142 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# -#Copyright (C) 2009 RaNaN -# -#This program is free software; you can redistribute it and/or modify -#it under the terms of the GNU General Public License as published by -#the Free Software Foundation; either version 3 of the License, -#or (at your option) any later version. -# -#This program is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -#See the GNU General Public License for more details. -# -#You should have received a copy of the GNU General Public License -# along with this program; if not, see . -# -### -import ConfigParser -import subprocess -import os +import curses, traceback, string, os +from time import sleep, time +import xmlrpclib +from threading import RLock, Thread +import sys import os.path from os import chdir from os.path import dirname from os.path import abspath from os import sep -from time import sleep -import sys -import time - -from module.remote.ClientSocket import SocketThread +import ConfigParser class pyLoadCli: - def __init__(self, adress, port, pw): - self.thread = SocketThread(adress, int(port), pw, self) - self.getch = _Getch() - self.input = "" - self.pos = [0, 0] - self.inputline = 0 - self.menuline = 0 - - self.links_added = 0 - - os.system("clear") - self.println(1, blue("py") + yellow("Load") + white(" Command Line Interface")) - self.println(2, "") - - - self.file_list = {} - self.thread.push_exec("get_links") - - self.start() - - def start(self): + menu_items = [] + + def __init__(self, stdscr, server_url): + self.stdscr = stdscr + self.lock = RLock() + self.lock.acquire() + self.stop = False + + self.download_win = None + self.add_win = None + self.proxy = None + + self.downloads = [] + self.current_dwin_rows = 0 + self.lock.release() + + self.connect(server_url) + + self.lock.acquire() + curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) + curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) + + self.screen = self.stdscr.subwin(23, 79, 0, 0) + self.screen.box() + self.screen.addstr(1, 48, "py", curses.color_pair(1)) + self.screen.addstr(1, 50, "Load", curses.color_pair(2)) + self.screen.addstr(1, 55, "Command Line Interface") + self.lock.release() + + self.add_menu("Add", "a", self.show_add_box) + self.add_menu("Quit", "q", self.exit) + + self.init_download_win() + self.update_downloads() + + def connect(self, server_url): + self.lock.acquire() + self.proxy = xmlrpclib.ServerProxy(server_url, allow_none=True) + self.lock.release() + + def refresh(self): + self.lock.acquire() + self.screen.refresh() + self.lock.release() + + def init_download_win(self): + self.lock.acquire() + rows = 2 + if self.current_dwin_rows != 0: + rows = self.current_dwin_rows*3 + 1 + self.download_win = self.screen.subwin(rows, 75, 3, 2) + self.download_win.box() + self.lock.release() + + def adjust_download_win_size(self, down_num): + if self.current_dwin_rows != down_num: + self.lock.acquire() + self.download_win.erase() + self.current_dwin_rows = down_num + self.lock.release() + self.init_download_win() + self.screen.redrawwin() + + def update_downloads(self): + self.lock.acquire() + self.downloads = self.proxy.status_downloads() + self.lock.release() + self.adjust_download_win_size(len(self.downloads)) + self.show_downloads() + + def show_downloads(self): + self.lock.acquire() + self.download_win.redrawwin() + for r, d in enumerate(self.downloads): + r = r*3+1 + if d["status"] == "downloading": + self.download_win.addstr(r, 2, d["name"], curses.color_pair(4)) + self.download_win.addstr(r, 35, "[", curses.color_pair(1)) + self.download_win.addstr(r, 36, "#" * (int(d["percent"])/4), curses.color_pair(2)) + self.download_win.addstr(r, 61, "]", curses.color_pair(1)) + self.download_win.addstr(r, 63, "%s%%" % d["percent"], curses.color_pair(3)) + self.download_win.addstr(r+1, 8, "Speed:", curses.color_pair(0)) + self.download_win.addstr(r+1, 15, "%s kb/s" % int(d["speed"]), curses.color_pair(3)) + self.download_win.addstr(r+1, 25, "Size:", curses.color_pair(0)) + self.download_win.addstr(r+1, 31, self.format_size(d["size"]), curses.color_pair(3)) + self.download_win.addstr(r+1, 38, "ETA:", curses.color_pair(0)) + self.download_win.addstr(r+1, 43, self.format_time(d['eta']), curses.color_pair(3)) + self.download_win.addstr(r+1, 52, "ID:", curses.color_pair(0)) + self.download_win.addstr(r+1, 55, str(d["id"]), curses.color_pair(3)) + elif d["status"] == "waiting": + self.download_win.addstr(r, 2, d["name"], curses.color_pair(4)) + self.download_win.addstr(r+1, 4, "waiting: " + self.format_time(d["wait_until"]- time()), curses.color_pair(3)) + self.lock.release() + self.refresh() + + def show_add_box(self): + self.lock.acquire() + curses.echo() + box = self.screen.subwin(4, 75, 18, 2) + box.box() + self.lock.release() + box.addstr(1, 2, "URL: (type 'END' if done)") + rows = [] while True: - #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.print_input() - elif ord(inp) == 127: - self.input = self.input[:-1] #backspace - self.print_input() - elif ord(inp) == 27: #ugly symbol - pass + box.move(2, 2) + s = box.getstr() + if s == "END": + break else: - self.input += inp - self.print_input() - + rows.append(s) + box.addstr(2, 2, " "*72) + box.erase() + self.lock.acquire() + curses.noecho() + for row in rows: + if row[:7] == "http://" or self.proxy.file_exists(row): + self.proxy.add_urls([row]) + self.lock.release() + + def update_status(self): + self.update_downloads() + def format_time(self, seconds): seconds = int(seconds) @@ -80,247 +145,75 @@ class pyLoadCli: return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) def format_size(self, size): - return str(size / 1024) + " MiB" - - def println(self, line, content): - 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, white(" Input: ") + self.input) - self.println(self.inputline + 1, "") - self.println(self.inputline + 2, "") - self.println(self.inputline + 3, "") - self.println(self.inputline + 4, "") - - def data_arrived(self, obj): - """Handle incoming data""" - if obj.command == "update": - #print updated information - print "\033[J" #clear screen - self.println(1, blue("py") + yellow("Load") + white(" Command Line Interface")) - self.println(2, "") - self.println(3, white("%s Downloads:" % (len(obj.data)))) - line = 4 - speed = 0 - for download in obj.data: - if download["status"] == "downloading": - percent = download["percent"] - z = percent / 4 - speed += download['speed'] - self.println(line, cyan(download["name"])) - line += 1 - self.println(line, blue("[") + yellow(z * "#" + (25-z) * " ") + blue("] ") + green(str(percent) + "%") + " Speed: " + green(str(int(download['speed'])) + " kb/s") + " Size: " + green(self.format_size(download['size'])) + " Finished in: " + green(self.format_time(download['eta'])) + " ID: " + green(str(download['id']))) - line += 1 - if download["status"] == "waiting": - self.println(line, cyan(download["name"])) - line += 1 - self.println(line, "waiting: " + green(self.format_time(download["wait_until"]- time.time()))) - line += 1 - self.println(line, "") - line += 1 - if obj.status['pause']: - self.println(line, "Status: " + red("paused") + " total Speed: " + red(str(int(speed)) + " kb/s") + " Files in queue: " + red(str(obj.status["queue"]))) - else: - self.println(line, "Status: " + red("running") + " total Speed: " + red(str(int(speed)) + " kb/s") + " Files in queue: " + red(str(obj.status["queue"]))) - line += 1 - self.println(line, "") - line += 1 - self.menuline = line - - self.build_menu() - elif obj.command == "file_list" or obj.function == "get_links": - self.file_list = obj.data - - def build_menu(self): - line = self.menuline - self.println(line, white("Menu:")) - line += 1 - if self.pos[0] == 0:# main menu - self.println(line, "") - line += 1 - self.println(line, mag("1.") + " Add Links") - line += 1 - self.println(line, mag("2.") + " Remove Links") - line += 1 - self.println(line, mag("3.") + " (Un)Pause Server") - line += 1 - self.println(line, mag("4.") + " Kill Server") - line += 1 - self.println(line, mag("5.") + " Quit") - line += 1 - self.println(line, "") - line += 1 - self.println(line, "") - elif self.pos[0] == 1:#add links - self.println(line, "Parse the links you want to add.") - line += 1 - self.println(line, "") - line += 1 - self.println(line, "") - line += 1 - self.println(line, "Links added: " + mag(str(self.links_added))) - line += 1 - self.println(line, "") - line += 1 - self.println(line, "") - line += 1 - self.println(line, mag("0.") + " back to main menu") - line += 1 - self.println(line, "") - elif self.pos[0] == 2:#remove links - self.println(line, "Type the number of the link you want to delete.") - line += 1 - i = 0 - for id in range(self.pos[1], self.pos[1] + 5): - if id < 0 or id >= len(self.file_list['order']): - continue - item = self.file_list['order'][id] - self.println(line, mag(str(item)) + ": " + self.file_list[item].url) - line += 1 - i += 1 - for x in range(5-i): - self.println(line, "") - line += 1 - - self.println(line, mag("p") + " - previous" + " | " + mag("n") + " - next") - line += 1 - self.println(line, mag("0.") + " back to main menu") - - self.inputline = line + 1 - self.print_input() - - def handle_input(self): - inp = self.input.strip() - if inp == "0": - self.pos = [0, 0] - self.build_menu() - return True - - if self.pos[0] == 0: - if inp == "1": - self.links_added = 0 - self.pos[0] = 1 - elif inp == "2": - self.pos[0] = 2 - self.pos[1] = 0 - elif inp == "3": - self.thread.push_exec("toggle_pause") - elif inp == "4": - self.thread.push_exec("kill") - sys.exit() - elif inp == "5": - os.system('clear') - sys.exit() - elif self.pos[0] == 1: #add links - if inp[:7] == "http://" or os.path.exists(inp): - self.thread.push_exec("add_links", [(inp, None)]) - self.links_added += 1 - elif self.pos[0] == 2: #remove links - if inp == "p": - self.pos[1] -= 5 - elif inp == "n": - self.pos[1] += 5 - else: - self.thread.push_exec("remove_links", [[inp]]) - - self.build_menu() - -class _Getch: - """ - Gets a single character from standard input. Does not echo to - the screen. - """ - def __init__(self): - try: - self.impl = _GetchWindows() - except ImportError: - try: - self.impl = _GetchMacCarbon() - except(AttributeError, ImportError): - self.impl = _GetchUnix() - - def __call__(self): return self.impl() - - -class _GetchUnix: - def __init__(self): - import tty - import sys - - def __call__(self): - import sys - import tty - import termios - - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(sys.stdin.fileno()) - ch = sys.stdin.read(1) - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - return ch - - -class _GetchWindows: - def __init__(self): - import msvcrt - - def __call__(self): - import msvcrt - return msvcrt.getch() - -class _GetchMacCarbon: - """ - A function which returns the current ASCII key that is down; - if no ASCII key is down, the null string is returned. The - page http://www.mactech.com/macintosh-c/chap02-1.html was - very helpful in figuring out how to do this. - """ - def __init__(self): - import Carbon - Carbon.Evt #see if it has this (in Unix, it doesn't) - - def __call__(self): - import Carbon - if Carbon.Evt.EventAvail(0x0008)[0] == 0: # 0x0008 is the keyDownMask - return '' + return str(size / 1024) + " MB" + + def add_menu(self, name, key, func): + self.lock.acquire() + left = 2 + for item in self.menu_items: + left += len(item[0]) + 1 + self.menu_items.append((name, key.lower(), func)) + self.screen.addstr(1, left, name) + p = name.lower().find(key.lower()) + if not p == -1: + self.screen.addstr(1, left+p, name[p], curses.A_BOLD | curses.A_UNDERLINE) + self.lock.release() + + def get_menu_func(self, key): + for item in self.menu_items: + if ord(item[1]) == key: + return item[2] + return None + + def get_command(self): + c = self.screen.getch() + if c == curses.KEY_END: + self.exit() else: - # - # The event contains the following info: - # (what,msg,when,where,mod)=Carbon.Evt.GetNextEvent(0x0008)[1] - # - # The message (msg) contains the ASCII char which is - # extracted with the 0x000000FF charCodeMask; this - # number is converted to an ASCII character with chr() and - # returned - # - (what, msg, when, where, mod) = Carbon.Evt.GetNextEvent(0x0008)[1] - return chr(msg) - -def blue(string): - return "\033[1;34m" + string + "\033[0m" - -def green(string): - return "\033[1;32m" + string + "\033[0m" - -def yellow(string): - return "\033[1;33m" + string + "\033[0m" - -def red(string): - return "\033[1;31m" + string + "\033[0m" - -def cyan(string): - return "\033[1;36m" + string + "\033[0m" - -def mag(string): - return "\033[1;35m" + string + "\033[0m" - -def white(string): - return "\033[1;37m" + string + "\033[0m" - -if __name__ == "__main__": - + f = self.get_menu_func(c) + if f: + f() + self.refresh() + + def exit(self): + self.stop = True + +class LoopThread(Thread): + def __init__(self, func, ret_func=None, sleep_time=None): + self.func = func + self.ret_func = ret_func + self.sleep_time = sleep_time + self.running = True + Thread.__init__(self) + + def run(self): + while self.running: + if self.sleep_time: + sleep(self.sleep_time) + ret = self.func() + if self.ret_func: + self.ret_func(ret) + + def stop(self): + self.running = False + +server_url = "" +def main(stdscr): + global server_url + cli = pyLoadCli(stdscr, server_url) + refresh_loop = LoopThread(cli.update_status, sleep_time=1) + refresh_loop.start() + getch_loop = LoopThread(cli.get_command) + getch_loop.start() + try: + while not cli.stop: + sleep(1) + finally: + getch_loop.stop() + refresh_loop.stop() + return + +if __name__=='__main__': if len(sys.argv) > 1: shortOptions = 'l' @@ -332,19 +225,19 @@ if __name__ == "__main__": chdir(dirname(abspath(__file__)) + sep) config = ConfigParser.SafeConfigParser() config.read('config') - - pipe = subprocess.PIPE - subprocess.Popen("./pyLoadCore.py", stdout=pipe, stderr=pipe) - print "Starting pyLoad Core" - sleep(1) - cli = pyLoadCli("127.0.0.1", config.get("remote", "port"), config.get("remote", "password")) - if len(extraparams) == 3: - address, port, password = sys.argv[1:4] - cli = pyLoadCli(address, port, password) + server_url = "https://%s:%s@%s:%s/" % ( + config.get("remote", "username"), + config.get("remote", "password"), + config.get("remote", "listenaddr"), + config.get("remote", "port") + ) + + if len(extraparams) == 1: + server_url = sys.argv[1] else: - address = raw_input("Adress:") - port = raw_input("Port:") - password = raw_input("Password:") - cli = pyLoadCli(address, port, password) - + print "URL scheme: https://user:password@host:port/" + server_url = raw_input("URL: ") + + curses.wrapper(main) + sys.exit() -- cgit v1.2.3 From 523e2857c47cdef1da6b43523bcf7871ed9e1d63 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 26 Nov 2009 22:05:11 +0100 Subject: complete new file_list, cleaned up --- pyLoadCli.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 186281e32..2a03c8e59 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -1,5 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . + + @author: mkaay + @version: v0.3 +""" + +SERVER_VERSION = "0.3" + import curses, traceback, string, os from time import sleep, time import xmlrpclib @@ -53,7 +74,10 @@ class pyLoadCli: def connect(self, server_url): self.lock.acquire() self.proxy = xmlrpclib.ServerProxy(server_url, allow_none=True) + server_version = self.proxy.get_server_version() self.lock.release() + if not server_version == SERVER_VERSION: + raise Exception("server is version %s client accepts version %s" % (server_version, SERVER_VERSION)) def refresh(self): self.lock.acquire() -- cgit v1.2.3 From f3c2e597ebb63094c43ec39acb67a23a1cc2c141 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 30 Nov 2009 17:47:42 +0100 Subject: added xmlrpc auth without ssl --- pyLoadCli.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 2a03c8e59..2d38ab4ca 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -250,7 +250,11 @@ if __name__=='__main__': config = ConfigParser.SafeConfigParser() config.read('config') - server_url = "https://%s:%s@%s:%s/" % ( + ssl = "" + if config.get("ssl", "activated") == "True": + ssl = "s" + server_url = "http%s://%s:%s@%s:%s/" % ( + ssl, config.get("remote", "username"), config.get("remote", "password"), config.get("remote", "listenaddr"), @@ -260,7 +264,7 @@ if __name__=='__main__': if len(extraparams) == 1: server_url = sys.argv[1] else: - print "URL scheme: https://user:password@host:port/" + print "URL scheme: http[s]://user:password@host:port/" server_url = raw_input("URL: ") curses.wrapper(main) -- cgit v1.2.3 From 0511d85691e8cf1c0c70045cf23e8abc6fc7cf40 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 30 Nov 2009 19:24:07 +0100 Subject: WIP: package system for cli --- pyLoadCli.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 2d38ab4ca..169b267eb 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -47,6 +47,7 @@ class pyLoadCli: self.proxy = None self.downloads = [] + self.tmp_bind = [] self.current_dwin_rows = 0 self.lock.release() @@ -56,7 +57,8 @@ class pyLoadCli: curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) - curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) + curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) + curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE) self.screen = self.stdscr.subwin(23, 79, 0, 0) self.screen.box() @@ -65,7 +67,10 @@ class pyLoadCli: self.screen.addstr(1, 55, "Command Line Interface") self.lock.release() - self.add_menu("Add", "a", self.show_add_box) + self.add_menu("Status", "s", None) + self.add_menu("Collector", "c", None) + self.add_menu("Add-Link", "l", self.show_addl_box) + self.add_menu("New-Package", "p", self.show_newp_box) self.add_menu("Quit", "q", self.exit) self.init_download_win() @@ -93,8 +98,8 @@ class pyLoadCli: self.download_win.box() self.lock.release() - def adjust_download_win_size(self, down_num): - if self.current_dwin_rows != down_num: + def adjust_download_win_size(self, down_num, force=False): + if self.current_dwin_rows != down_num or force: self.lock.acquire() self.download_win.erase() self.current_dwin_rows = down_num @@ -134,7 +139,7 @@ class pyLoadCli: self.lock.release() self.refresh() - def show_add_box(self): + def show_addl_box(self): self.lock.acquire() curses.echo() box = self.screen.subwin(4, 75, 18, 2) @@ -158,6 +163,46 @@ class pyLoadCli: self.proxy.add_urls([row]) self.lock.release() + def show_newp_box(self): + self.lock.acquire() + curses.echo() + box = self.screen.subwin(4, 75, 18, 2) + box.box() + self.lock.release() + box.addstr(1, 2, "Package Name:") + box.move(2, 2) + s = box.getstr() + box.erase() + self.lock.acquire() + curses.noecho() + id = self.proxy.new_package(s) + self.lock.release() + self.show_package_edit(id) + + def show_package_edit(self, id): + self.lock.acquire() + self.tmp_bind = [] + box = self.screen.subwin(6, 71, 4, 4) + box.box() + box.bkgdset(" ", curses.color_pair(0)) + self.lock.release() + data = self.proxy.get_package_data(id) + box.addstr(1, 2, "ID: %(id)s" % data) + box.addstr(2, 2, "Name: %(package_name)s" % data) + box.addstr(3, 2, "Folder: %(folder)s" % data) + + cfiles = self.proxy.get_collector_files() + box2 = self.screen.subwin(len(cfiles)+2, 71, 11, 4) + box2.box() + for r, fid in enumerate(cfiles[0:7]): + data = self.proxy.get_file_info(fid) + box2.addstr(r+1, 2, "#%(id)d - %(url)s" % data) + + box.getch() + box.erase() + box2.erase() + self.adjust_download_win_size(len(self.downloads), force=True) + def update_status(self): self.update_downloads() @@ -189,12 +234,20 @@ class pyLoadCli: return item[2] return None + def get_tmp_func(self, key): + for item in self.tmp_bind: + if item[0] == key: + return item[1] + return None + def get_command(self): c = self.screen.getch() if c == curses.KEY_END: self.exit() else: f = self.get_menu_func(c) + if not f: + f = self.get_tmp_func(c) if f: f() self.refresh() -- cgit v1.2.3 From 7caec14b0a307df9f2bd9ea6a9db6977a836145b Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 30 Nov 2009 21:25:33 +0100 Subject: WIP: package system second draft - unstable --- pyLoadCli.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 12 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 169b267eb..e94a7e57d 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -43,6 +43,7 @@ class pyLoadCli: self.stop = False self.download_win = None + self.collectorbox = None self.add_win = None self.proxy = None @@ -68,7 +69,7 @@ class pyLoadCli: self.lock.release() self.add_menu("Status", "s", None) - self.add_menu("Collector", "c", None) + self.add_menu("Collector", "c", self.collector_menu) self.add_menu("Add-Link", "l", self.show_addl_box) self.add_menu("New-Package", "p", self.show_newp_box) self.add_menu("Quit", "q", self.exit) @@ -182,26 +183,88 @@ class pyLoadCli: def show_package_edit(self, id): self.lock.acquire() self.tmp_bind = [] - box = self.screen.subwin(6, 71, 4, 4) + data = self.proxy.get_package_data(id) + pfiles = self.proxy.get_package_files(id) + box = self.screen.subwin(7+len(pfiles[0:5]), 71, 4, 4) box.box() box.bkgdset(" ", curses.color_pair(0)) self.lock.release() - data = self.proxy.get_package_data(id) box.addstr(1, 2, "ID: %(id)s" % data) box.addstr(2, 2, "Name: %(package_name)s" % data) box.addstr(3, 2, "Folder: %(folder)s" % data) - + box.addstr(4, 2, "Files in Package:") + for r, fid in enumerate(pfiles[0:5]): + data = self.proxy.get_file_info(fid) + box.addstr(5+r, 2, "#%(id)d - %(url)s" % data) + box.move(len(pfiles[0:5])+5, 2) + self.show_link_collector() + curses.echo() + fid = box.getstr() + curses.noecho() + self.proxy.move_file_2_package(int(fid), id) + box.erase() + self.hide_collector() + self.redraw() + + def show_link_collector(self): + self.lock.acquire() cfiles = self.proxy.get_collector_files() - box2 = self.screen.subwin(len(cfiles)+2, 71, 11, 4) - box2.box() - for r, fid in enumerate(cfiles[0:7]): + self.collectorbox = self.screen.subwin(len(cfiles[0:5])+2, 71, 14, 4) + self.collectorbox.box() + for r, fid in enumerate(cfiles[0:5]): data = self.proxy.get_file_info(fid) - box2.addstr(r+1, 2, "#%(id)d - %(url)s" % data) + self.collectorbox.addstr(r+1, 2, "#%(id)d - %(url)s" % data) + self.lock.release() + + def show_package_collector(self): + show = True + page = 0 + rows_pp = 6 + while show: + self.lock.acquire() + cpack = self.proxy.get_collector_packages() + self.collectorbox = self.screen.subwin(2+len(cpack[rows_pp*page:rows_pp*(page+1)]), 71, 14, 4) + self.collectorbox.box() + for r, data in enumerate(cpack[rows_pp*page:rows_pp*(page+1)]): + self.collectorbox.addstr(r+1, 2, "#%(id)d - %(package_name)s" % data) + self.lock.release() + self.refresh() + c = self.collectorbox.getch() + if c == ord("n"): + if page <= float(len(cpack))/float(rows_pp)-1: + page = page+1 + elif c == ord("p"): + page = page-1 + if page < 0: + page = 0 + elif c == ord("d"): + curses.echo() + id = self.collectorbox.getstr() + curses.noecho() + self.proxy.push_package_2_queue(int(id)) + else: + show = False + self.hide_collector() + + def hide_collector(self): + self.lock.acquire() + self.collectorbox.erase() + self.lock.release() - box.getch() - box.erase() - box2.erase() - self.adjust_download_win_size(len(self.downloads), force=True) + def collector_menu(self): + menu = self.screen.subwin(4, 12, 2, 10) + menu.box() + menu.addstr(1, 1, " inks ") + menu.addstr(2, 1, " ackages ") + menu.addstr(1, 2, "L", curses.A_BOLD | curses.A_UNDERLINE) + menu.addstr(2, 2, "P", curses.A_BOLD | curses.A_UNDERLINE) + c = menu.getch() + menu.erase() + self.redraw() + if c == ord("l"): + return + elif c == ord("p"): + self.show_package_collector() def update_status(self): self.update_downloads() @@ -252,6 +315,9 @@ class pyLoadCli: f() self.refresh() + def redraw(self): + self.adjust_download_win_size(len(self.downloads), force=True) + def exit(self): self.stop = True -- cgit v1.2.3 From dcf9df576d0e30e016bb6ecb9fb67decc04d2761 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 30 Nov 2009 23:31:37 +0100 Subject: Fixed EOL Errors, beautified js --- pyLoadCli.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index e94a7e57d..cf75019be 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -54,12 +54,13 @@ class pyLoadCli: self.connect(server_url) - self.lock.acquire() - curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) - curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE) + self.lock.acquire() + + curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) + curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) + curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE ) self.screen = self.stdscr.subwin(23, 79, 0, 0) self.screen.box() @@ -86,7 +87,7 @@ class pyLoadCli: raise Exception("server is version %s client accepts version %s" % (server_version, SERVER_VERSION)) def refresh(self): - self.lock.acquire() + self.lock.acquire() self.screen.refresh() self.lock.release() @@ -342,7 +343,7 @@ class LoopThread(Thread): server_url = "" def main(stdscr): - global server_url + global server_url cli = pyLoadCli(stdscr, server_url) refresh_loop = LoopThread(cli.update_status, sleep_time=1) refresh_loop.start() -- cgit v1.2.3 From 2c7203032324820c122b1e7b77604212391f75f9 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 10 Dec 2009 15:44:37 +0100 Subject: cleaned some code, pyLoad Script Support (closed #16) --- pyLoadCli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index cf75019be..b6d08a238 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -21,7 +21,10 @@ SERVER_VERSION = "0.3" -import curses, traceback, string, os +import curses +import traceback +import string +import os from time import sleep, time import xmlrpclib from threading import RLock, Thread -- cgit v1.2.3 From 95d09b338ac7aed2b387bf143a5cfd1c4b29f612 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 15 Dec 2009 17:48:30 +0100 Subject: new Django webinterface(in development), small fixes --- pyLoadCli.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index b6d08a238..96165a7b5 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -22,14 +22,10 @@ SERVER_VERSION = "0.3" import curses -import traceback -import string -import os from time import sleep, time import xmlrpclib from threading import RLock, Thread import sys -import os.path from os import chdir from os.path import dirname from os.path import abspath -- cgit v1.2.3 From 18d827faf2960efcfb2e1196375e5542e25d20ab Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 20 Dec 2009 00:27:02 +0100 Subject: reimplemented old CLI --- pyLoadCli.py | 713 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 360 insertions(+), 353 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 96165a7b5..d5e214ca4 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -1,274 +1,88 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +# +#Copyright (C) 2009 RaNaN +# +#This program is free software; you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation; either version 3 of the License, +#or (at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +#See the GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +### +import ConfigParser +import subprocess +import os +import os.path +from os import chdir +from os.path import join +from os.path import abspath +from os.path import dirname +from os import sep +from time import sleep +import sys +import time +import threading +import xmlrpclib -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. +from module.XMLConfigParser import XMLConfigParser - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. +class pyLoadCli: + def __init__(self, server_url): + self.core = xmlrpclib.ServerProxy(server_url, allow_none=True) + self.getch = _Getch() + self.input = "" + self.pos = [0, 0] + self.inputline = 0 + self.menuline = 0 - You should have received a copy of the GNU General Public License - along with this program; if not, see . - - @author: mkaay - @version: v0.3 -""" + try: + self.core.get_server_version() + except: + print "pyLoadCore not running" + exit() -SERVER_VERSION = "0.3" + self.links_added = 0 -import curses -from time import sleep, time -import xmlrpclib -from threading import RLock, Thread -import sys -from os import chdir -from os.path import dirname -from os.path import abspath -from os import sep -import ConfigParser + os.system("clear") + self.println(1, blue("py") + yellow("Load") + white(" Command Line Interface")) + self.println(2, "") -class pyLoadCli: - menu_items = [] - - def __init__(self, stdscr, server_url): - self.stdscr = stdscr - self.lock = RLock() - self.lock.acquire() - self.stop = False - - self.download_win = None - self.collectorbox = None - self.add_win = None - self.proxy = None - - self.downloads = [] - self.tmp_bind = [] - self.current_dwin_rows = 0 - self.lock.release() - - self.connect(server_url) - - self.lock.acquire() - - curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) - curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE ) - - self.screen = self.stdscr.subwin(23, 79, 0, 0) - self.screen.box() - self.screen.addstr(1, 48, "py", curses.color_pair(1)) - self.screen.addstr(1, 50, "Load", curses.color_pair(2)) - self.screen.addstr(1, 55, "Command Line Interface") - self.lock.release() - - self.add_menu("Status", "s", None) - self.add_menu("Collector", "c", self.collector_menu) - self.add_menu("Add-Link", "l", self.show_addl_box) - self.add_menu("New-Package", "p", self.show_newp_box) - self.add_menu("Quit", "q", self.exit) - - self.init_download_win() - self.update_downloads() - - def connect(self, server_url): - self.lock.acquire() - self.proxy = xmlrpclib.ServerProxy(server_url, allow_none=True) - server_version = self.proxy.get_server_version() - self.lock.release() - if not server_version == SERVER_VERSION: - raise Exception("server is version %s client accepts version %s" % (server_version, SERVER_VERSION)) - - def refresh(self): - self.lock.acquire() - self.screen.refresh() - self.lock.release() - - def init_download_win(self): - self.lock.acquire() - rows = 2 - if self.current_dwin_rows != 0: - rows = self.current_dwin_rows*3 + 1 - self.download_win = self.screen.subwin(rows, 75, 3, 2) - self.download_win.box() - self.lock.release() - - def adjust_download_win_size(self, down_num, force=False): - if self.current_dwin_rows != down_num or force: - self.lock.acquire() - self.download_win.erase() - self.current_dwin_rows = down_num - self.lock.release() - self.init_download_win() - self.screen.redrawwin() - - def update_downloads(self): - self.lock.acquire() - self.downloads = self.proxy.status_downloads() - self.lock.release() - self.adjust_download_win_size(len(self.downloads)) - self.show_downloads() - - def show_downloads(self): - self.lock.acquire() - self.download_win.redrawwin() - for r, d in enumerate(self.downloads): - r = r*3+1 - if d["status"] == "downloading": - self.download_win.addstr(r, 2, d["name"], curses.color_pair(4)) - self.download_win.addstr(r, 35, "[", curses.color_pair(1)) - self.download_win.addstr(r, 36, "#" * (int(d["percent"])/4), curses.color_pair(2)) - self.download_win.addstr(r, 61, "]", curses.color_pair(1)) - self.download_win.addstr(r, 63, "%s%%" % d["percent"], curses.color_pair(3)) - self.download_win.addstr(r+1, 8, "Speed:", curses.color_pair(0)) - self.download_win.addstr(r+1, 15, "%s kb/s" % int(d["speed"]), curses.color_pair(3)) - self.download_win.addstr(r+1, 25, "Size:", curses.color_pair(0)) - self.download_win.addstr(r+1, 31, self.format_size(d["size"]), curses.color_pair(3)) - self.download_win.addstr(r+1, 38, "ETA:", curses.color_pair(0)) - self.download_win.addstr(r+1, 43, self.format_time(d['eta']), curses.color_pair(3)) - self.download_win.addstr(r+1, 52, "ID:", curses.color_pair(0)) - self.download_win.addstr(r+1, 55, str(d["id"]), curses.color_pair(3)) - elif d["status"] == "waiting": - self.download_win.addstr(r, 2, d["name"], curses.color_pair(4)) - self.download_win.addstr(r+1, 4, "waiting: " + self.format_time(d["wait_until"]- time()), curses.color_pair(3)) - self.lock.release() - self.refresh() - - def show_addl_box(self): - self.lock.acquire() - curses.echo() - box = self.screen.subwin(4, 75, 18, 2) - box.box() - self.lock.release() - box.addstr(1, 2, "URL: (type 'END' if done)") - rows = [] + + self.file_list = {} + + self.thread = RefreshThread(self) + self.thread.start() + + self.start() + + def start(self): while True: - box.move(2, 2) - s = box.getstr() - if s == "END": - break + #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.print_input() + elif ord(inp) == 127: + self.input = self.input[:-1] #backspace + self.print_input() + elif ord(inp) == 27: #ugly symbol + pass else: - rows.append(s) - box.addstr(2, 2, " "*72) - box.erase() - self.lock.acquire() - curses.noecho() - for row in rows: - if row[:7] == "http://" or self.proxy.file_exists(row): - self.proxy.add_urls([row]) - self.lock.release() - - def show_newp_box(self): - self.lock.acquire() - curses.echo() - box = self.screen.subwin(4, 75, 18, 2) - box.box() - self.lock.release() - box.addstr(1, 2, "Package Name:") - box.move(2, 2) - s = box.getstr() - box.erase() - self.lock.acquire() - curses.noecho() - id = self.proxy.new_package(s) - self.lock.release() - self.show_package_edit(id) - - def show_package_edit(self, id): - self.lock.acquire() - self.tmp_bind = [] - data = self.proxy.get_package_data(id) - pfiles = self.proxy.get_package_files(id) - box = self.screen.subwin(7+len(pfiles[0:5]), 71, 4, 4) - box.box() - box.bkgdset(" ", curses.color_pair(0)) - self.lock.release() - box.addstr(1, 2, "ID: %(id)s" % data) - box.addstr(2, 2, "Name: %(package_name)s" % data) - box.addstr(3, 2, "Folder: %(folder)s" % data) - box.addstr(4, 2, "Files in Package:") - for r, fid in enumerate(pfiles[0:5]): - data = self.proxy.get_file_info(fid) - box.addstr(5+r, 2, "#%(id)d - %(url)s" % data) - box.move(len(pfiles[0:5])+5, 2) - self.show_link_collector() - curses.echo() - fid = box.getstr() - curses.noecho() - self.proxy.move_file_2_package(int(fid), id) - box.erase() - self.hide_collector() - self.redraw() - - def show_link_collector(self): - self.lock.acquire() - cfiles = self.proxy.get_collector_files() - self.collectorbox = self.screen.subwin(len(cfiles[0:5])+2, 71, 14, 4) - self.collectorbox.box() - for r, fid in enumerate(cfiles[0:5]): - data = self.proxy.get_file_info(fid) - self.collectorbox.addstr(r+1, 2, "#%(id)d - %(url)s" % data) - self.lock.release() - - def show_package_collector(self): - show = True - page = 0 - rows_pp = 6 - while show: - self.lock.acquire() - cpack = self.proxy.get_collector_packages() - self.collectorbox = self.screen.subwin(2+len(cpack[rows_pp*page:rows_pp*(page+1)]), 71, 14, 4) - self.collectorbox.box() - for r, data in enumerate(cpack[rows_pp*page:rows_pp*(page+1)]): - self.collectorbox.addstr(r+1, 2, "#%(id)d - %(package_name)s" % data) - self.lock.release() - self.refresh() - c = self.collectorbox.getch() - if c == ord("n"): - if page <= float(len(cpack))/float(rows_pp)-1: - page = page+1 - elif c == ord("p"): - page = page-1 - if page < 0: - page = 0 - elif c == ord("d"): - curses.echo() - id = self.collectorbox.getstr() - curses.noecho() - self.proxy.push_package_2_queue(int(id)) - else: - show = False - self.hide_collector() - - def hide_collector(self): - self.lock.acquire() - self.collectorbox.erase() - self.lock.release() - - def collector_menu(self): - menu = self.screen.subwin(4, 12, 2, 10) - menu.box() - menu.addstr(1, 1, " inks ") - menu.addstr(2, 1, " ackages ") - menu.addstr(1, 2, "L", curses.A_BOLD | curses.A_UNDERLINE) - menu.addstr(2, 2, "P", curses.A_BOLD | curses.A_UNDERLINE) - c = menu.getch() - menu.erase() - self.redraw() - if c == ord("l"): - return - elif c == ord("p"): - self.show_package_collector() - - def update_status(self): - self.update_downloads() - + self.input += inp + self.print_input() + def format_time(self, seconds): seconds = int(seconds) @@ -277,86 +91,261 @@ class pyLoadCli: return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) def format_size(self, size): - return str(size / 1024) + " MB" - - def add_menu(self, name, key, func): - self.lock.acquire() - left = 2 - for item in self.menu_items: - left += len(item[0]) + 1 - self.menu_items.append((name, key.lower(), func)) - self.screen.addstr(1, left, name) - p = name.lower().find(key.lower()) - if not p == -1: - self.screen.addstr(1, left+p, name[p], curses.A_BOLD | curses.A_UNDERLINE) - self.lock.release() - - def get_menu_func(self, key): - for item in self.menu_items: - if ord(item[1]) == key: - return item[2] - return None - - def get_tmp_func(self, key): - for item in self.tmp_bind: - if item[0] == key: - return item[1] - return None - - def get_command(self): - c = self.screen.getch() - if c == curses.KEY_END: - self.exit() + return str(size / 1024) + " MiB" + + def println(self, line, content): + 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, white(" Input: ") + self.input) + self.println(self.inputline + 1, "") + self.println(self.inputline + 2, "") + self.println(self.inputline + 3, "") + self.println(self.inputline + 4, "") + + def refresh(self): + """Handle incoming data""" + data = self.core.status_downloads() + #print updated information + print "\033[J" #clear screen + self.println(1, blue("py") + yellow("Load") + white(" Command Line Interface")) + self.println(2, "") + self.println(3, white("%s Downloads:" % (len(data)))) + line = 4 + speed = 0 + for download in data: + if download["status"] == "downloading": + percent = download["percent"] + z = percent / 4 + speed += download['speed'] + self.println(line, cyan(download["name"])) + line += 1 + self.println(line, blue("[") + yellow(z * "#" + (25-z) * " ") + blue("] ") + green(str(percent) + "%") + " Speed: " + green(str(int(download['speed'])) + " kb/s") + " Size: " + green(self.format_size(download['size'])) + " Finished in: " + green(self.format_time(download['eta'])) + " ID: " + green(str(download['id']))) + line += 1 + if download["status"] == "waiting": + self.println(line, cyan(download["name"])) + line += 1 + self.println(line, "waiting: " + green(self.format_time(download["wait_until"]- time.time()))) + line += 1 + self.println(line, "") + line += 1 + status = self.core.status_server() + if status['pause']: + self.println(line, "Status: " + red("paused") + " total Speed: " + red(str(int(speed)) + " kb/s") + " Files in queue: " + red(str(status["queue"]))) else: - f = self.get_menu_func(c) - if not f: - f = self.get_tmp_func(c) - if f: - f() - self.refresh() - - def redraw(self): - self.adjust_download_win_size(len(self.downloads), force=True) - - def exit(self): - self.stop = True - -class LoopThread(Thread): - def __init__(self, func, ret_func=None, sleep_time=None): - self.func = func - self.ret_func = ret_func - self.sleep_time = sleep_time - self.running = True - Thread.__init__(self) + self.println(line, "Status: " + red("running") + " total Speed: " + red(str(int(speed)) + " kb/s") + " Files in queue: " + red(str(status["queue"]))) + line += 1 + self.println(line, "") + line += 1 + self.menuline = line + + self.build_menu() + # + self.file_list = data + + def build_menu(self): + line = self.menuline + self.println(line, white("Menu:")) + line += 1 + if self.pos[0] == 0:# main menu + self.println(line, "") + line += 1 + self.println(line, mag("1.") + " Add Links") + line += 1 + self.println(line, mag("2.") + " Remove Links") + line += 1 + self.println(line, mag("3.") + " (Un)Pause Server") + line += 1 + self.println(line, mag("4.") + " Kill Server") + line += 1 + self.println(line, mag("5.") + " Quit") + line += 1 + self.println(line, "") + line += 1 + self.println(line, "") + elif self.pos[0] == 1:#add links + self.println(line, "Parse the links you want to add.") + line += 1 + self.println(line, "") + line += 1 + self.println(line, "") + line += 1 + self.println(line, "Links added: " + mag(str(self.links_added))) + line += 1 + self.println(line, "") + line += 1 + self.println(line, "") + line += 1 + self.println(line, mag("0.") + " back to main menu") + line += 1 + self.println(line, "") + elif self.pos[0] == 2:#remove links + self.println(line, "Type the number of the link you want to delete.") + line += 1 + i = 0 + for id in range(self.pos[1], self.pos[1] + 5): + if id < 0 or id >= len(self.file_list['order']): + continue + item = self.file_list['order'][id] + self.println(line, mag(str(item)) + ": " + self.file_list[item].url) + line += 1 + i += 1 + for x in range(5-i): + self.println(line, "") + line += 1 + + self.println(line, mag("p") + " - previous" + " | " + mag("n") + " - next") + line += 1 + self.println(line, mag("0.") + " back to main menu") + + self.inputline = line + 1 + self.print_input() + + def handle_input(self): + inp = self.input.strip() + if inp == "0": + self.pos = [0, 0] + self.build_menu() + return True + + if self.pos[0] == 0: + if inp == "1": + self.links_added = 0 + self.pos[0] = 1 + elif inp == "2": + self.pos[0] = 2 + self.pos[1] = 0 + elif inp == "3": + self.core.toggle_pause() + elif inp == "4": + self.core.kill() + sys.exit() + elif inp == "5": + os.system('clear') + sys.exit() + elif self.pos[0] == 1: #add links + if inp[:7] == "http://" or os.path.exists(inp): + self.thread.push_exec("add_links", [(inp, None)]) + self.links_added += 1 + elif self.pos[0] == 2: #remove links + if inp == "p": + self.pos[1] -= 5 + elif inp == "n": + self.pos[1] += 5 + else: + self.thread.push_exec("remove_links", [[inp]]) + + self.build_menu() + +class RefreshThread(threading.Thread): + def __init__(self, cli): + threading.Thread.__init__(self) + self.cli = cli def run(self): - while self.running: - if self.sleep_time: - sleep(self.sleep_time) - ret = self.func() - if self.ret_func: - self.ret_func(ret) - - def stop(self): - self.running = False - -server_url = "" -def main(stdscr): - global server_url - cli = pyLoadCli(stdscr, server_url) - refresh_loop = LoopThread(cli.update_status, sleep_time=1) - refresh_loop.start() - getch_loop = LoopThread(cli.get_command) - getch_loop.start() - try: - while not cli.stop: + while True: + self.cli.refresh() sleep(1) - finally: - getch_loop.stop() - refresh_loop.stop() - return + + + + +class _Getch: + """ + Gets a single character from standard input. Does not echo to + the screen. + """ + def __init__(self): + try: + self.impl = _GetchWindows() + except ImportError: + try: + self.impl = _GetchMacCarbon() + except(AttributeError, ImportError): + self.impl = _GetchUnix() + + def __call__(self): return self.impl() + + +class _GetchUnix: + def __init__(self): + import tty + import sys + + def __call__(self): + import sys + import tty + import termios + + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + ch = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + return ch + + +class _GetchWindows: + def __init__(self): + import msvcrt + + def __call__(self): + import msvcrt + return msvcrt.getch() + +class _GetchMacCarbon: + """ + A function which returns the current ASCII key that is down; + if no ASCII key is down, the null string is returned. The + page http://www.mactech.com/macintosh-c/chap02-1.html was + very helpful in figuring out how to do this. + """ + def __init__(self): + import Carbon + Carbon.Evt #see if it has this (in Unix, it doesn't) + + def __call__(self): + import Carbon + if Carbon.Evt.EventAvail(0x0008)[0] == 0: # 0x0008 is the keyDownMask + return '' + else: + # + # The event contains the following info: + # (what,msg,when,where,mod)=Carbon.Evt.GetNextEvent(0x0008)[1] + # + # The message (msg) contains the ASCII char which is + # extracted with the 0x000000FF charCodeMask; this + # number is converted to an ASCII character with chr() and + # returned + # + (what, msg, when, where, mod) = Carbon.Evt.GetNextEvent(0x0008)[1] + return chr(msg) + +def blue(string): + return "\033[1;34m" + string + "\033[0m" + +def green(string): + return "\033[1;32m" + string + "\033[0m" + +def yellow(string): + return "\033[1;33m" + string + "\033[0m" + +def red(string): + return "\033[1;31m" + string + "\033[0m" + +def cyan(string): + return "\033[1;36m" + string + "\033[0m" + +def mag(string): + return "\033[1;35m" + string + "\033[0m" + +def white(string): + return "\033[1;37m" + string + "\033[0m" + +if __name__ == "__main__": -if __name__=='__main__': if len(sys.argv) > 1: shortOptions = 'l' @@ -365,26 +354,44 @@ if __name__=='__main__': opts, extraparams = __import__("getopt").getopt(sys.argv[1:], shortOptions, longOptions) for option, params in opts: if option in ("-l", "--local"): - chdir(dirname(abspath(__file__)) + sep) - config = ConfigParser.SafeConfigParser() - config.read('config') - ssl = "" - if config.get("ssl", "activated") == "True": + xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)),"module","config","core.xml")) + config = xmlconfig.getConfig() + + ssl= "" + if config['ssl']['activated'] == "True": ssl = "s" + server_url = "http%s://%s:%s@%s:%s/" % ( - ssl, - config.get("remote", "username"), - config.get("remote", "password"), - config.get("remote", "listenaddr"), - config.get("remote", "port") - ) + ssl, + config['remote']['username'], + config['remote']['password'], + config['remote']['listenaddr'], + config['remote']['port'] + ) - if len(extraparams) == 1: - server_url = sys.argv[1] + if len(extraparams) == 4: + username, address, port, password = sys.argv[1:5] + + server_url = "http://%s:%s@%s:%s/" % ( + username, + adress, + port, + passwort + ) + else: - print "URL scheme: http[s]://user:password@host:port/" - server_url = raw_input("URL: ") + username = raw_input("Username:") + address = raw_input("Adress:") + port = raw_input("Port:") + password = raw_input("Password:") + + server_url = "http://%s:%s@%s:%s/" % ( + username, + adress, + port, + passwort + ) - curses.wrapper(main) - sys.exit() + + cli = pyLoadCli(server_url) \ No newline at end of file -- cgit v1.2.3 From 3e52baca1b622694e072eff87be825770ff9760f Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 20 Dec 2009 19:09:48 +0100 Subject: new cli working --- pyLoadCli.py | 130 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 94 insertions(+), 36 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index d5e214ca4..8a0bd2b3f 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -39,10 +39,12 @@ class pyLoadCli: self.core = xmlrpclib.ServerProxy(server_url, allow_none=True) self.getch = _Getch() self.input = "" - self.pos = [0, 0] + self.pos = [0, 0, 0] self.inputline = 0 self.menuline = 0 + self.new_package = {} + try: self.core.get_server_version() except: @@ -164,36 +166,74 @@ class pyLoadCli: line += 1 self.println(line, "") elif self.pos[0] == 1:#add links - self.println(line, "Parse the links you want to add.") - line += 1 - self.println(line, "") - line += 1 - self.println(line, "") - line += 1 - self.println(line, "Links added: " + mag(str(self.links_added))) - line += 1 - self.println(line, "") - line += 1 - self.println(line, "") - line += 1 - self.println(line, mag("0.") + " back to main menu") - line += 1 - self.println(line, "") - elif self.pos[0] == 2:#remove links - self.println(line, "Type the number of the link you want to delete.") - line += 1 - i = 0 - for id in range(self.pos[1], self.pos[1] + 5): - if id < 0 or id >= len(self.file_list['order']): - continue - item = self.file_list['order'][id] - self.println(line, mag(str(item)) + ": " + self.file_list[item].url) + + if self.pos[1] == 0: + self.println(line, "") + line += 1 + self.println(line, "Name your package.") line += 1 - i += 1 - for x in range(5-i): self.println(line, "") line += 1 - + self.println(line, "") + line += 1 + self.println(line, "") + line += 1 + self.println(line, "") + line += 1 + self.println(line, mag("0.") + " back to main menu") + line += 1 + self.println(line, "") + + else: + self.println(line, "Package: %s" % self.new_package['name']) + line += 1 + self.println(line, "Parse the links you want to add.") + line += 1 + self.println(line, "Type END when done.") + line += 1 + self.println(line, "Links added: " + mag(str(self.links_added))) + line += 1 + self.println(line, "") + line += 1 + self.println(line, "") + line += 1 + self.println(line, mag("0.") + " back to main menu") + line += 1 + self.println(line, "") + elif self.pos[0] == 2:#remove links + if self.pos[1] == 0: + pack = self.core.get_queue() + self.println(line, "Type d(number of package) to delete a package, or w/o d to look into it.") + line += 1 + i = 0 + for id in range(self.pos[2], self.pos[2] + 5): + try: + self.println(line, mag(str(pack[id]['id'])) + ": " + pack[id]['package_name']) + line += 1 + i += 1 + except Exception, e: + pass + for x in range(5-i): + self.println(line, "") + line += 1 + + else: + links = self.core.get_package_files(self.pos[1]) + self.println(line, "Type the number of the link you want to delete.") + line += 1 + i = 0 + for id in range(self.pos[2], self.pos[2] + 5): + try: + link = self.core.get_file_info(links[id]) + self.println(line, mag(str(link['id'])) + ": " + link['url']) + line += 1 + i += 1 + except Exception, e: + pass + for x in range(5-i): + self.println(line, "") + line += 1 + self.println(line, mag("p") + " - previous" + " | " + mag("n") + " - next") line += 1 self.println(line, mag("0.") + " back to main menu") @@ -204,7 +244,7 @@ class pyLoadCli: def handle_input(self): inp = self.input.strip() if inp == "0": - self.pos = [0, 0] + self.pos = [0, 0, 0] self.build_menu() return True @@ -223,17 +263,35 @@ class pyLoadCli: elif inp == "5": os.system('clear') sys.exit() + elif self.pos[0] == 1: #add links - if inp[:7] == "http://" or os.path.exists(inp): - self.thread.push_exec("add_links", [(inp, None)]) - self.links_added += 1 + if self.pos[1] == 0: + self.new_package['name'] = inp + self.new_package['links'] = [] + self.pos[1] = 1 + else: + if inp == "END": + self.core.add_package(self.new_package['name'], self.new_package['links']) # add package + self.pos = [0, 0, 0] + self.links_added = 0 + else: #@TODO validation + self.new_package['links'].append(inp) + self.links_added += 1 + elif self.pos[0] == 2: #remove links + if self.pos[1] == 0: + if inp.startswith("d"): + self.core.del_packages([int(inp[1:])]) + elif inp != "p" and inp != "n": + self.pos[1] = int(inp) + self.pos[2] = 0 + elif inp != "p" and inp != "n": + self.core.del_links([int(inp)]) + if inp == "p": - self.pos[1] -= 5 + self.pos[2] -= 5 elif inp == "n": - self.pos[1] += 5 - else: - self.thread.push_exec("remove_links", [[inp]]) + self.pos[2] += 5 self.build_menu() -- cgit v1.2.3 From 62965d0668e81fc801c4be2d61c1a0b64b0edca8 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 20 Dec 2009 23:43:21 +0100 Subject: cli + web fixes --- pyLoadCli.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 8a0bd2b3f..061c366af 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -73,7 +73,10 @@ class pyLoadCli: os.system("clear") sys.exit() # ctrl + c elif ord(inp) == 13: - self.handle_input() + try: + self.handle_input() + except Exception, e: + self.println(2, red(str(e))) self.input = "" #enter self.print_input() elif ord(inp) == 127: @@ -189,7 +192,7 @@ class pyLoadCli: line += 1 self.println(line, "Parse the links you want to add.") line += 1 - self.println(line, "Type END when done.") + self.println(line, "Type "+mag("END")+" when done.") line += 1 self.println(line, "Links added: " + mag(str(self.links_added))) line += 1 -- cgit v1.2.3 From 9453269684b8d17411d8bbc4ecd0c7958670ff42 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 21 Dec 2009 19:59:59 +0100 Subject: log view, progressbar test --- pyLoadCli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 061c366af..44592d555 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -305,7 +305,11 @@ class RefreshThread(threading.Thread): def run(self): while True: - self.cli.refresh() + try: + self.cli.refresh() + except: + self.cli.pos[1] = 0 + self.cli.pos[2] = 0 sleep(1) -- cgit v1.2.3 From 69746896671494ab0169ac74fc316b5fce02cd95 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 2 Jan 2010 12:42:53 +0100 Subject: new cli functions --- pyLoadCli.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 44592d555..87d7fc240 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -157,7 +157,7 @@ class pyLoadCli: line += 1 self.println(line, mag("1.") + " Add Links") line += 1 - self.println(line, mag("2.") + " Remove Links") + self.println(line, mag("2.") + " Manage Links") line += 1 self.println(line, mag("3.") + " (Un)Pause Server") line += 1 @@ -222,15 +222,20 @@ class pyLoadCli: else: links = self.core.get_package_files(self.pos[1]) - self.println(line, "Type the number of the link you want to delete.") + self.println(line, "Type the number of the link you want to delete or r(number) to restart.") line += 1 i = 0 for id in range(self.pos[2], self.pos[2] + 5): try: link = self.core.get_file_info(links[id]) - self.println(line, mag(str(link['id'])) + ": " + link['url']) - line += 1 + + if not link['status_filename']: + self.println(line, mag(str(link['id'])) + ": " + link['url']) + else: + self.println(line, mag(str(link['id'])) + ": %s | %s | %s" % (link['filename'],link['status_type'],link['plugin'])) + line += 1 i += 1 + except Exception, e: pass for x in range(5-i): @@ -288,6 +293,8 @@ class pyLoadCli: elif inp != "p" and inp != "n": self.pos[1] = int(inp) self.pos[2] = 0 + elif inp.startswith('r'): + self.core.restart_file(int(inp[1:])) elif inp != "p" and inp != "n": self.core.del_links([int(inp)]) @@ -305,12 +312,14 @@ class RefreshThread(threading.Thread): def run(self): while True: + sleep(1) try: self.cli.refresh() - except: + except Exception, e: + self.cli.println(2, red(str(e))) self.cli.pos[1] = 0 self.cli.pos[2] = 0 - sleep(1) + -- cgit v1.2.3 From 8e9353a2e42a2e98d93618af1b6435568c44fa0f Mon Sep 17 00:00:00 2001 From: spoob Date: Tue, 5 Jan 2010 23:18:53 +0100 Subject: fixed rapidshare slot wait --- pyLoadCli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 87d7fc240..30524cb9a 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -468,4 +468,4 @@ if __name__ == "__main__": ) - cli = pyLoadCli(server_url) \ No newline at end of file + cli = pyLoadCli(server_url) -- cgit v1.2.3 From fbee6325c4079768f330b51fa125411c8ab2967b Mon Sep 17 00:00:00 2001 From: spoob Date: Wed, 6 Jan 2010 00:13:08 +0100 Subject: fixed cli? --- pyLoadCli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 30524cb9a..e86098066 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -429,7 +429,7 @@ if __name__ == "__main__": for option, params in opts: if option in ("-l", "--local"): - xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)),"module","config","core.xml")) + xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)),"module","config","core.xml"), join(abspath(dirname(__file__)),"module","config","core_default.xml")) config = xmlconfig.getConfig() ssl= "" -- cgit v1.2.3 From 515b3a87636238271bf0bfb0472703bfcd10397e Mon Sep 17 00:00:00 2001 From: spoob Date: Wed, 6 Jan 2010 00:19:30 +0100 Subject: fixed cli --- pyLoadCli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index e86098066..b97a1c7eb 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -449,9 +449,9 @@ if __name__ == "__main__": server_url = "http://%s:%s@%s:%s/" % ( username, - adress, + password, + address, port, - passwort ) else: @@ -462,9 +462,9 @@ if __name__ == "__main__": server_url = "http://%s:%s@%s:%s/" % ( username, - adress, + password, + address, port, - passwort ) -- cgit v1.2.3 From d56dcab5d48c8c4ec05f200f92bd35a1f977cd4f Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 6 Jan 2010 17:38:53 +0100 Subject: cli fix, webinterface db check --- pyLoadCli.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index b97a1c7eb..18efa7272 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -455,12 +455,20 @@ if __name__ == "__main__": ) else: - username = raw_input("Username:") - address = raw_input("Adress:") - port = raw_input("Port:") - password = raw_input("Password:") + username = raw_input("Username: ") + address = raw_input("Adress: ") + port = raw_input("Port: ") + ssl = raw_input("Use SSL? (y/[n])") + if ssl == "y": + ssl = "s" + else: + ssl = "" + + from getpass import getpass + password = getpass("Password: ") - server_url = "http://%s:%s@%s:%s/" % ( + server_url = "http%s://%s:%s@%s:%s/" % ( + ssl, username, password, address, -- cgit v1.2.3 From d2aa3fceb9f896343b128d40f20a0465cf69efca Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 6 Jan 2010 22:11:24 +0100 Subject: small fixes, new hook stuff --- pyLoadCli.py | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 18efa7272..42ee5fbab 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -443,37 +443,20 @@ if __name__ == "__main__": config['remote']['listenaddr'], config['remote']['port'] ) - - if len(extraparams) == 4: - username, address, port, password = sys.argv[1:5] - - server_url = "http://%s:%s@%s:%s/" % ( - username, - password, - address, - port, - ) - + if len(extraparams) == 1: + server_url = sys.argv[1] else: username = raw_input("Username: ") address = raw_input("Adress: ") - port = raw_input("Port: ") - ssl = raw_input("Use SSL? (y/[n])") - if ssl == "y": + ssl = raw_input("Use SSL? ([y]/n): ") + if ssl == "y" or ssl == "": ssl = "s" else: ssl = "" - + port = raw_input("Port: ") from getpass import getpass password = getpass("Password: ") - server_url = "http%s://%s:%s@%s:%s/" % ( - ssl, - username, - password, - address, - port, - ) - - + server_url = "http%s://%s:%s@%s:%s/" % (ssl, username, password, address, port) + print server_url cli = pyLoadCli(server_url) -- cgit v1.2.3 From 82a6f5b10a1e738b5b9ab5c68ab07f7fc57b0cc7 Mon Sep 17 00:00:00 2001 From: spoob Date: Fri, 8 Jan 2010 14:07:14 +0100 Subject: Fixed pyLoadCli -l --- pyLoadCli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 42ee5fbab..fd8a1f590 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -429,7 +429,7 @@ if __name__ == "__main__": for option, params in opts: if option in ("-l", "--local"): - xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)),"module","config","core.xml"), join(abspath(dirname(__file__)),"module","config","core_default.xml")) + xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)),"module","config","core.xml")) config = xmlconfig.getConfig() ssl= "" -- cgit v1.2.3 From 3d655ddbfbd96abecb9a9c9bebf6e43eb710ab12 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 10 Jan 2010 16:20:31 +0100 Subject: fixed manage.py, addBox working, some code formatted and cleaned --- pyLoadCli.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index fd8a1f590..1ebf5d943 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -17,19 +17,15 @@ # along with this program; if not, see . # ### -import ConfigParser -import subprocess import os import os.path -from os import chdir -from os.path import join from os.path import abspath from os.path import dirname -from os import sep -from time import sleep +from os.path import join import sys -import time import threading +import time +from time import sleep import xmlrpclib from module.XMLConfigParser import XMLConfigParser @@ -192,7 +188,7 @@ class pyLoadCli: line += 1 self.println(line, "Parse the links you want to add.") line += 1 - self.println(line, "Type "+mag("END")+" when done.") + self.println(line, "Type " + mag("END") + " when done.") line += 1 self.println(line, "Links added: " + mag(str(self.links_added))) line += 1 @@ -232,7 +228,7 @@ class pyLoadCli: if not link['status_filename']: self.println(line, mag(str(link['id'])) + ": " + link['url']) else: - self.println(line, mag(str(link['id'])) + ": %s | %s | %s" % (link['filename'],link['status_type'],link['plugin'])) + self.println(line, mag(str(link['id'])) + ": %s | %s | %s" % (link['filename'], link['status_type'], link['plugin'])) line += 1 i += 1 @@ -429,20 +425,20 @@ if __name__ == "__main__": for option, params in opts: if option in ("-l", "--local"): - xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)),"module","config","core.xml")) + xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)), "module", "config", "core.xml")) config = xmlconfig.getConfig() - ssl= "" + ssl = "" if config['ssl']['activated'] == "True": ssl = "s" server_url = "http%s://%s:%s@%s:%s/" % ( - ssl, - config['remote']['username'], - config['remote']['password'], - config['remote']['listenaddr'], - config['remote']['port'] - ) + ssl, + config['remote']['username'], + config['remote']['password'], + config['remote']['listenaddr'], + config['remote']['port'] + ) if len(extraparams) == 1: server_url = sys.argv[1] else: -- cgit v1.2.3 From 6583802517f87f65fb1efd24707c23d6323783c9 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 21 Jan 2010 22:40:15 +0100 Subject: some new CLi functions --- pyLoadCli.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'pyLoadCli.py') diff --git a/pyLoadCli.py b/pyLoadCli.py index 1ebf5d943..18c3b98bc 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -202,7 +202,7 @@ class pyLoadCli: elif self.pos[0] == 2:#remove links if self.pos[1] == 0: pack = self.core.get_queue() - self.println(line, "Type d(number of package) to delete a package, or w/o d to look into it.") + self.println(line, "Type d(number of package) to delete a package, r to restart, or w/o d,r to look into it.") line += 1 i = 0 for id in range(self.pos[2], self.pos[2] + 5): @@ -218,7 +218,7 @@ class pyLoadCli: else: links = self.core.get_package_files(self.pos[1]) - self.println(line, "Type the number of the link you want to delete or r(number) to restart.") + self.println(line, "Type d(number) of the link you want to delete or r(number) to restart.") line += 1 i = 0 for id in range(self.pos[2], self.pos[2] + 5): @@ -285,15 +285,25 @@ class pyLoadCli: elif self.pos[0] == 2: #remove links if self.pos[1] == 0: if inp.startswith("d"): - self.core.del_packages([int(inp[1:])]) + if inp.find("-") > -1: + self.core.del_packages(range(*map(int, inp[1:].split("-")))) + else: + self.core.del_packages([int(inp[1:])]) + if inp.startswith("r"): + self.core.restart_package(int(inp[1:])) elif inp != "p" and inp != "n": self.pos[1] = int(inp) self.pos[2] = 0 elif inp.startswith('r'): - self.core.restart_file(int(inp[1:])) - elif inp != "p" and inp != "n": - self.core.del_links([int(inp)]) - + if inp.find("-") > -1: + map(self.core.restart_file, range(*map(int, inp[1:].split("-")))) + else: + self.core.restart_file(int(inp[1:])) + elif inp.startswith('d') and inp != "p" and inp != "n": + if inp.find("-") > -1: + self.core.del_links(range(*map(int, inp[1:].split("-")))) + else: + self.core.del_links([int(inp[1:])]) if inp == "p": self.pos[2] -= 5 elif inp == "n": -- cgit v1.2.3