diff options
author | mkaay <mkaay@mkaay.de> | 2009-11-30 19:24:07 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2009-11-30 19:24:07 +0100 |
commit | 0511d85691e8cf1c0c70045cf23e8abc6fc7cf40 (patch) | |
tree | 07701abaac3567175df64ef7d36d51585ff44253 | |
parent | added xmlrpc auth without ssl (diff) | |
download | pyload-0511d85691e8cf1c0c70045cf23e8abc6fc7cf40.tar.xz |
WIP: package system for cli
-rw-r--r-- | module/file_list.py | 52 | ||||
-rwxr-xr-x | pyLoadCli.py | 63 | ||||
-rwxr-xr-x | pyLoadCore.py | 22 |
3 files changed, 119 insertions, 18 deletions
diff --git a/module/file_list.py b/module/file_list.py index c95eefcec..1b9526eb8 100644 --- a/module/file_list.py +++ b/module/file_list.py @@ -132,6 +132,22 @@ class File_List(object): files.append(pyfile) return files + def getFileInfo(self, id): + try: + n, pyfile = self.collector._getFileFromID(id) + except NoSuchElementException: + key, n, pyfile, pypack, pid = self.packager._getFileFromID() + info = {} + info["id"] = pyfile.id + info["url"] = pyfile.url + info["folder"] = pyfile.folder + info["filename"] = pyfile.filename + info["status_type"] = pyfile.status.type + info["status_url"] = pyfile.status.url + info["status_filename"] = pyfile.status.filename + info["status_error"] = pyfile.status.error + return info + class pyLoadCollector(): def __init__(collector, file_list): collector.file_list = file_list @@ -151,7 +167,7 @@ class File_List(object): """ ids = [] for pypack in (collector.file_list.data["packages"] + collector.file_list.data["queue"]): - for pyf in pypack.links: + for pyf in pypack.files: ids.append(pyf.id) for pyfile in collector.file_list.data["collector"]: ids.append(pyfile.id) @@ -219,7 +235,7 @@ class File_List(object): """ ids = [] for pypack in (packager.file_list.data["packages"] + packager.file_list.data["queue"]): - ids.append(pypack.id) + ids.append(pypack.data["id"]) id = 1 while id in ids: id += 1 @@ -230,10 +246,10 @@ class File_List(object): returns PyLoadPackage instance and position with given id """ for n, pypack in enumerate(packager.file_list.data["packages"]): - if pypack.id == id: + if pypack.data["id"] == id: return ("packages", n, pypack) for n, pypack in enumerate(packager.file_list.data["queue"]): - if pypack.id == id: + if pypack.data["id"] == id: return ("queue", n, pypack) raise NoSuchElementException() @@ -253,11 +269,11 @@ class File_List(object): def addNewPackage(packager, package_name=None): pypack = PyLoadPackage() - pypack.id = packager._getFreeID() + pypack.data["id"] = packager._getFreeID() if package_name is not None: pypack.data["package_name"] = package_name packager.file_list.data["packages"].append(pypack) - return pypack.id + return pypack.data["id"] def removePackage(packager, id): packager.file_list.lock.acquire() @@ -310,6 +326,17 @@ class File_List(object): finally: packager.file_list.lock.release() + def getPackageData(packager, id): + key, n, pypack = packager._getPackageFromID(id) + return pypack.data + + def getPackageFiles(packager, id): + key, n, pypack = packager._getPackageFromID(id) + ids = [] + for pyfile in pypack: + ids.append(pyfile.id) + return ids + def addFileToPackage(packager, id, pyfile): key, n, pypack = packager._getPackageFromID(id) pyfile.package = pypack @@ -396,23 +423,24 @@ class PyLoadFileData(): def parsePackage(self, pack): if pack: - self.pack_id = pack.id + self.pack_id = pack.data["id"] class PyLoadPackageData(): def __init__(self): self.data = None - self.links = [] + self.files = [] def set(self, pypack): self.data = pypack.data - for pyfile in pypack.links: + for pyfile in pypack.files: fdata = PyLoadFileData() fdata.set(pyfile) - self.links.append(fdata) + self.files.append(fdata) def get(self, pypack): - for fdata in self.links: + pypack.data = self.data + for fdata in self.files: pyfile = PyLoadFile() fdata.get(pyfile) pyfile.package = pypack - pypack.links.append(pyfile) + pypack.files.append(pyfile) 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() diff --git a/pyLoadCore.py b/pyLoadCore.py index 1f048c268..6532e5b91 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -335,6 +335,20 @@ class ServerMethods(): self.core.file_list.collector.addLink(link) self.core.file_list.save() + def new_package(self, name): + id = self.core.file_list.packager.addNewPackage(name) + self.core.file_list.save() + return id + + def get_package_data(self, id): + return self.core.file_list.packager.getPackageData(id) + + def get_package_files(self, id): + return self.core.file_list.packager.getPackageFiles(id) + + def get_file_info(self, id): + return self.core.file_list.getFileInfo(id) + def del_links(self, ids): for id in ids: try: @@ -370,7 +384,7 @@ class ServerMethods(): data.append(ds) return data - def get_collector_packages(self): + def get_packages_collector(self): data = [] for q in self.core.file_list.data["packages"]: ds = { @@ -388,6 +402,12 @@ class ServerMethods(): data.append(ds) return data + def get_collector_files(self): + files = [] + for f in self.core.file_list.data["collector"]: + files.append(f.id) + return files + #def move_urls_up(self, ids): # for id in ids: # self.core.file_list.move(id) |