diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-01-02 12:42:53 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-01-02 12:42:53 +0100 |
commit | 69746896671494ab0169ac74fc316b5fce02cd95 (patch) | |
tree | dbddebff085aa64e75750bde04a067a47f3b594e | |
parent | fixed netload.in premium (diff) | |
download | pyload-69746896671494ab0169ac74fc316b5fce02cd95.tar.xz |
new cli functions
-rwxr-xr-x | pyLoadCli.py | 21 | ||||
-rwxr-xr-x | pyLoadCore.py | 246 |
2 files changed, 138 insertions, 129 deletions
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) + diff --git a/pyLoadCore.py b/pyLoadCore.py index 4ca81efed..bdf4e1e40 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -35,30 +35,30 @@ from os.path import basename from os.path import abspath
from os.path import dirname
from os.path import exists
-from os.path import join +from os.path import join
from os import execv
from re import sub
import subprocess
from sys import argv
from sys import exit
from sys import path
-from sys import stdout +from sys import stdout
from sys import executable
import thread
import time
-from time import sleep -from shutil import copyfile +from time import sleep
+from shutil import copyfile
from tempfile import NamedTemporaryFile
from module.network.Request import Request
import module.remote.SecureXMLRPCServer as Server
-from module.XMLConfigParser import XMLConfigParser +from module.XMLConfigParser import XMLConfigParser
from module.file_list import File_List
from module.thread_list import Thread_List
from module.web.ServerThread import WebServer
-from module.CaptchaManager import CaptchaManager - +from module.CaptchaManager import CaptchaManager
+
from xmlrpclib import Binary
class Core(object):
@@ -113,8 +113,8 @@ class Core(object): if self.config['ssl']['activated']:
self.check_install("OpenSSL", "OpenSSL for secure connection", True)
self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True)
- self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) - + self.check_file(self.config['ssl']['key'], _("ssl key"), False, True)
+
self.downloadSpeedLimit = int(self.xmlconfig.get("general", "download_speed_limit", 0))
if self.config['general']['debug_mode']:
@@ -125,15 +125,15 @@ class Core(object): self.init_scripts()
path.append(self.plugin_folder)
self.create_plugin_index()
- - self.lastGuiConnected = 0 +
+ self.lastGuiConnected = 0
self.server_methods = ServerMethods(self)
self.file_list = File_List(self)
- self.thread_list = Thread_List(self) + self.thread_list = Thread_List(self)
self.captchaManager = CaptchaManager(self)
- - self.last_update_check = 0 +
+ self.last_update_check = 0
self.update_check_interval = 1800
self.update_available = self.check_update()
@@ -159,19 +159,19 @@ class Core(object): pid = found
lid = self.file_list.collector.addLink(linkFile)
self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid))
- self.file_list.packager.pushPackage2Queue(pid) - + self.file_list.packager.pushPackage2Queue(pid)
+
self.file_list.continueAborted()
while True:
sleep(2)
- if self.do_restart: - self.logger.info("restarting pyLoad") + if self.do_restart:
+ self.logger.info("restarting pyLoad")
self.restart()
- if self.do_kill: + if self.do_kill:
self.shutdown()
self.logger.info("pyLoad quits")
- exit() + exit()
if self.last_update_check + self.update_check_interval <= time.time():
self.update_available = self.check_update()
@@ -196,10 +196,10 @@ class Core(object): traceback.print_exc()
- def init_webserver(self): - pyloadDBFile = join(self.path, "module", "web", "pyload.db") - pyloadDefaultDBFile = join(self.path, "module", "web", "pyload_default.db") - if not exists(pyloadDBFile): + def init_webserver(self):
+ pyloadDBFile = join(self.path, "module", "web", "pyload.db")
+ pyloadDefaultDBFile = join(self.path, "module", "web", "pyload_default.db")
+ if not exists(pyloadDBFile):
copyfile(pyloadDefaultDBFile, pyloadDBFile)
if self.config['webinterface']['activated']:
self.webserver = WebServer(self)
@@ -280,12 +280,12 @@ class Core(object): print _("could not create %s: %s") % (description, tmp_name)
if essential:
exit()
- - def isGUIConnected(self): - return self.lastGuiConnected+10 > time.time() +
+ def isGUIConnected(self):
+ return self.lastGuiConnected+10 > time.time()
def restart(self):
- self.shutdown() + self.shutdown()
execv(executable, [executable, "pyLoadCore.py"])
#~ def update(self, file_update=None):
@@ -298,10 +298,10 @@ class Core(object): #~ except:
#~ self.logger.info("Error on updating pyLoad")
- def create_plugin_index(self): - plugins = glob(join(self.plugin_folder, "hoster", "*.py")) - plugins += glob(join(self.plugin_folder, "decrypter", "*.py")) - plugins += glob(join(self.plugin_folder, "container", "*.py")) + def create_plugin_index(self):
+ plugins = glob(join(self.plugin_folder, "hoster", "*.py"))
+ plugins += glob(join(self.plugin_folder, "decrypter", "*.py"))
+ plugins += glob(join(self.plugin_folder, "container", "*.py"))
plugins += glob(join(self.plugin_folder, "container", "DLC.pyc"))
for file_handler in plugins:
plugin_pattern = ""
@@ -325,36 +325,36 @@ class Core(object): if start < now and end > now: return True
elif start > end and (now > start or now < end): return True
elif start < now and end < now and start > end: return True
- else: return False - - def getMaxSpeed(self): - return self.downloadSpeedLimit - - def shutdown(self): + else: return False
+
+ def getMaxSpeed(self):
+ return self.downloadSpeedLimit
+
+ def shutdown(self):
self.logger.info("shutting down...")
- if self.config['webinterface']['activated']: + if self.config['webinterface']['activated']:
self.webserver.quit()
- self.webserver.join() - for thread in self.thread_list.threads: - thread.shutdown = True - self.thread_list.stopAllDownloads() - for thread in self.thread_list.threads: - thread.join(15) + self.webserver.join()
+ for thread in self.thread_list.threads:
+ thread.shutdown = True
+ self.thread_list.stopAllDownloads()
+ for thread in self.thread_list.threads:
+ thread.join(15)
self.file_list.save()
- def check_update(self): + def check_update(self):
try:
if self.config['updates']['search_updates']:
version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" % (CURRENT_VERSION, False))
if version_check == "":
self.logger.info("No Updates for pyLoad")
- return False + return False
else:
self.logger.info("New pyLoad Version %s available" % version_check)
return True
else:
- return False - finally: + return False
+ finally:
self.last_update_check = time.time()
def install_update(self):
@@ -420,7 +420,7 @@ class ServerMethods(): if self.core.thread_list.pause:
self.core.thread_list.pause = False
else:
- self.core.thread_list.pause = True + self.core.thread_list.pause = True
return self.core.thread_list.pause
def status_server(self):
@@ -443,8 +443,8 @@ class ServerMethods(): return CURRENT_VERSION
def add_urls(self, links):
- for link in links: - link = link.strip() + for link in links:
+ link = link.strip()
if link.startswith("http") or exists(link):
self.core.file_list.collector.addLink(link)
self.core.file_list.save()
@@ -519,77 +519,77 @@ class ServerMethods(): self.core.file_list.collector.removeFile(fid)
def push_package_2_queue(self, id):
- self.core.file_list.packager.pushPackage2Queue(id) - - def restart_package(self, packid): - for id in self.core.file_list.packager.getPackageFiles(packid): - self.core.file_list.packager.resetFileStatus(id) - - def restart_file(self, fileid): - self.core.file_list.packager.resetFileStatus(fileid) - - def upload_container(self, filename, type, content): - th = NamedTemporaryFile(mode="w", suffix="."+type, delete=False) - th.write(content) - path = th.name - th.close() - pid = self.core.file_list.packager.addNewPackage(filename) - cid = self.core.file_list.collector.addLink(path) + self.core.file_list.packager.pushPackage2Queue(id)
+
+ def restart_package(self, packid):
+ for id in self.core.file_list.packager.getPackageFiles(packid):
+ self.core.file_list.packager.resetFileStatus(id)
+
+ def restart_file(self, fileid):
+ self.core.file_list.packager.resetFileStatus(fileid)
+
+ def upload_container(self, filename, type, content):
+ th = NamedTemporaryFile(mode="w", suffix="."+type, delete=False)
+ th.write(content)
+ path = th.name
+ th.close()
+ pid = self.core.file_list.packager.addNewPackage(filename)
+ cid = self.core.file_list.collector.addLink(path)
self.move_file_2_package(cid, pid)
- self.core.file_list.save() - - def get_log(self, offset=0): - filename = self.core.config['log']['log_folder'] + sep + 'log.txt' - fh = open(filename, "r") - content = fh.read() - fh.close() - lines = content.splitlines() - if offset >= len(lines): - return None - return lines[offset:] - - def stop_downloads(self): - self.core.thread_list.stopAllDownloads() - - def stop_download(self, type, id): - if type == "pack": - ids = self.core.file_list.getPackageFiles(id) - for fid in ids: - self.core.file_list.packager.abortFile(fid) - else: - self.core.file_list.packager.abortFile(id) - - def update_available(self): - return self.core.update_available - - def set_package_name(self, pid, name): - self.core.file_list.packager.setPackageData(pid, package_name=name) - - def pull_out_package(self, pid): - self.core.file_list.packager.pullOutPackage(pid) - - def is_captcha_waiting(self): - self.core.lastGuiConnected = time.time() - task = self.core.captchaManager.getTask() - return not task == None - - def get_captcha_task(self): - task = self.core.captchaManager.getTask() - if task: - task.setWatingForUser() - c = task.getCaptcha() - return str(task.getID()), Binary(c[0]), str(c[1]) - else: - return None, None, None - - def set_captcha_result(self, tid, result): - task = self.core.captchaManager.getTaskFromID(tid) - if task: - task.setResult(result) - task.setDone() - return True - else: - return False + self.core.file_list.save()
+
+ def get_log(self, offset=0):
+ filename = self.core.config['log']['log_folder'] + sep + 'log.txt'
+ fh = open(filename, "r")
+ content = fh.read()
+ fh.close()
+ lines = content.splitlines()
+ if offset >= len(lines):
+ return None
+ return lines[offset:]
+
+ def stop_downloads(self):
+ self.core.thread_list.stopAllDownloads()
+
+ def stop_download(self, type, id):
+ if type == "pack":
+ ids = self.core.file_list.getPackageFiles(id)
+ for fid in ids:
+ self.core.file_list.packager.abortFile(fid)
+ else:
+ self.core.file_list.packager.abortFile(id)
+
+ def update_available(self):
+ return self.core.update_available
+
+ def set_package_name(self, pid, name):
+ self.core.file_list.packager.setPackageData(pid, package_name=name)
+
+ def pull_out_package(self, pid):
+ self.core.file_list.packager.pullOutPackage(pid)
+
+ def is_captcha_waiting(self):
+ self.core.lastGuiConnected = time.time()
+ task = self.core.captchaManager.getTask()
+ return not task == None
+
+ def get_captcha_task(self):
+ task = self.core.captchaManager.getTask()
+ if task:
+ task.setWatingForUser()
+ c = task.getCaptcha()
+ return str(task.getID()), Binary(c[0]), str(c[1])
+ else:
+ return None, None, None
+
+ def set_captcha_result(self, tid, result):
+ task = self.core.captchaManager.getTaskFromID(tid)
+ if task:
+ task.setResult(result)
+ task.setDone()
+ return True
+ else:
+ return False
#def move_urls_up(self, ids):
# for id in ids:
@@ -615,7 +615,7 @@ if __name__ == "__main__": pyload_core = Core()
try:
pyload_core.start()
- except KeyboardInterrupt: + except KeyboardInterrupt:
pyload_core.shutdown()
pyload_core.logger.info("killed pyLoad from Terminal")
exit()
|