diff options
-rw-r--r-- | Core.py | 36 | ||||
-rw-r--r-- | module/Py_Load_File.py | 1 | ||||
-rw-r--r-- | module/download_thread.py | 36 | ||||
-rwxr-xr-x | module/network/Request.py | 5 | ||||
-rw-r--r-- | module/thread_list.py | 9 |
5 files changed, 45 insertions, 42 deletions
@@ -22,9 +22,8 @@ CURRENT_VERSION = '0.1' #python imports import ConfigParser from glob import glob -from string import find, split -from os import sep, chdir, mkdir, curdir, name, system, remove -from os.path import exists, abspath, dirname, basename +from os import sep, mkdir +from os.path import exists, basename from sys import path, exit, stdout import urllib2 import re @@ -33,7 +32,6 @@ import logging import logging.handlers #my imports -from module.download_thread import Download_Thread from module.thread_list import Thread_List from module.Py_Load_File import PyLoadFile @@ -43,20 +41,20 @@ class Core(object): def __init__(self): self.check_update() - self.download_folder = "" - self.log_folder = "" + self.config = {} + self.plugins_folder = "Plugins" - self.link_file = "links.txt" + self.config['link_file'] = "links.txt" self.plugins_avaible = {} self.search_updates = False - + self.read_config() self.thread_list = Thread_List(self) - self.check_create(self.download_folder, "Ordner für Downloads", True) - self.check_create(self.log_folder, "Ordner für Logs", True) - self.check_create(self.link_file, "Datei für Links", False) + self.check_create(self.config['download_folder'], "Ordner für Downloads") + self.check_create(self.config['log_folder'], "Ordner für Logs") + self.check_create(self.config['link_file'], "Datei für Links", False) self.init_logger(logging.DEBUG) # logging level @@ -68,10 +66,10 @@ class Core(object): """ config = ConfigParser.ConfigParser() config.read('config') - self.download_folder = config.get('general', 'downloadFolder') - self.link_file = config.get('general', 'linkFile') - self.search_updates = config.get('updates', 'searchUpdates') - self.log_folder = config.get('log', 'logFolder') + self.config['download_folder'] = config.get('general', 'downloadFolder') + self.config['link_file'] = config.get('general', 'linkFile') + self.config['search_updates'] = config.get('updates', 'searchUpdates') + self.config['log_folder'] = config.get('log', 'logFolder') def create_plugin_index(self): for file_handler in glob(self.plugins_folder + sep + '*.py'): @@ -140,7 +138,7 @@ class Core(object): else: print "Beta Version " + CURRENT_VERSION + " in benutzung" #using beta version - def check_create(self, check_name, legend, folder): + def check_create(self, check_name, legend, folder = True): if not exists(check_name): try: if folder: @@ -167,7 +165,7 @@ class Core(object): def __new_py_load_file(self, url): new_file = PyLoadFile(self, url) - new_file.download_folder = self.download_folder + new_file.download_folder = self.config['download_folder'] self.thread_list.append_py_load_file(new_file) return True @@ -179,7 +177,7 @@ class Core(object): "%d.%m.%Y %H:%M:%S") handler.setFormatter(frm) console.setFormatter(frm) - + self.logger = logging.getLogger() # settable in config self.logger.addHandler(handler) self.logger.addHandler(console) #if console logging @@ -209,7 +207,7 @@ class Core(object): def start(self): """ starts the machine """ - self._get_links(self.link_file) + self._get_links(self.config['link_file']) while True: #self.thread_list.status() self._test_print_status() diff --git a/module/Py_Load_File.py b/module/Py_Load_File.py index ce2a10924..ecfded6fd 100644 --- a/module/Py_Load_File.py +++ b/module/Py_Load_File.py @@ -13,7 +13,6 @@ class PyLoadFile: self.modul = __import__(self._get_my_plugin()) #maybe replace to prepare download pluginClass = getattr(self.modul, self.modul.__name__) self.plugin = pluginClass(self) - self.download_folder = "" self.status = Status(self) def _get_my_plugin(self): diff --git a/module/download_thread.py b/module/download_thread.py index 96bc4dd34..8e90fb51f 100644 --- a/module/download_thread.py +++ b/module/download_thread.py @@ -21,7 +21,6 @@ import threading from time import time, sleep from copy import copy -import urllib class Status(object): @@ -41,22 +40,22 @@ class Status(object): self.waituntil = None self.want_reconnect = None - def __call__(self, blocks_read, block_size, total_size): - if self.status_queue == None: - return False - self.start = time() - self.last_status = time() - self.total_kb = total_size / 1024 - self.downloaded_kb = (blocks_read * block_size) / 1024 - elapsed_time = time() - self.start - if elapsed_time != 0: - self.rate = self.downloaded_kb / elapsed_time - if self.rate != 0: - self.expected_time = self.downloaded_kb / self.rate - if self.last_status+0.2 < time(): - self.status_queue.put(copy(self)) - self.last_status = time() - +# def __call__(self, blocks_read, block_size, total_size): +# if self.status_queue == None: +# return False +# self.start = time() +# self.last_status = time() +# self.total_kb = total_size / 1024 +# self.downloaded_kb = (blocks_read * block_size) / 1024 +# elapsed_time = time() - self.start +# if elapsed_time != 0: +# self.rate = self.downloaded_kb / elapsed_time +# if self.rate != 0: +# self.expected_time = self.downloaded_kb / self.rate +# if self.last_status+0.2 < time(): +# self.status_queue.put(copy(self)) +# self.last_status = time() +# def set_status_queue(self, queue): self.status_queue = queue @@ -106,6 +105,9 @@ class Download_Thread(threading.Thread): print "handle reconnect" while (time() < status.waituntil): + if status.want_reconnect and self.reconnected: + status = "reconnected" + return False status.type = "waiting" sleep(1) #eventuell auf genaue zeit warten diff --git a/module/network/Request.py b/module/network/Request.py index 1b94ed13f..07c1769ec 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -6,7 +6,6 @@ authored by: RaNaN import urllib import urllib2 import cookielib -import Keepalive import base64 import time @@ -112,13 +111,13 @@ class Request: try: return (self.dl_arrived / ((time.time() if self.dl else self.dl_finished) - self.dl_time )) / 1024 except: - return "No Download" + return 0 def get_ETA(self): try: return (self.dl_size - self.dl_arrived) / (self.dl_arrived / (time.time() - self.dl_time)) except: - return "No Download" + return 0 def kB_left(self): return (self.dl_size - self.dl_arrived) / 1024 diff --git a/module/thread_list.py b/module/thread_list.py index 065318a56..7031b166e 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -18,6 +18,10 @@ # ### #python +import time +import urllib2 +import re +import subprocess from Queue import Queue from threading import Lock #my @@ -111,8 +115,9 @@ class Thread_List(object): self.f_relation[1] += 1 self.select_thread() - def reconnect(): - reconn = subprocess.Popen(reconnectMethod) + def reconnect(self): + self.parent.logger.debug("reconnect") + reconn = subprocess.Popen(self.parent.config['reconnectMethod']) reconn.wait() ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1) #versuchen neue ip aus zu lesen while ip == "": #solange versuch bis neue ip ausgelesen |