diff options
Diffstat (limited to 'Core.py')
-rw-r--r-- | Core.py | 78 |
1 files changed, 55 insertions, 23 deletions
@@ -21,19 +21,22 @@ CURRENT_VERSION = '0.1' #python imports import ConfigParser -from glob import glob -from os import sep, mkdir -from os.path import exists, basename -from sys import path, exit, stdout -import urllib2 -import re -from time import sleep, time import logging import logging.handlers +import time +import urllib2 +from glob import glob +from os import mkdir +from os import sep +from os.path import basename +from os.path import exists +from sys import exit +from sys import path +from sys import stdout +from time import sleep -#my imports -from module.thread_list import Thread_List from module.Py_Load_File import PyLoadFile +from module.thread_list import Thread_List class Core(object): """ pyLoad main @@ -42,14 +45,15 @@ class Core(object): self.check_update() self.config = {} - - self.plugins_folder = "Plugins" + + self.config['plugin_folder'] = "Plugins" self.config['link_file'] = "links.txt" self.plugins_avaible = {} self.search_updates = False self.read_config() - + print self.is_dltime # debug only + self.thread_list = Thread_List(self) self.check_create(self.config['download_folder'], "Ordner für Downloads") @@ -58,26 +62,34 @@ class Core(object): self.init_logger(logging.DEBUG) # logging level - path.append(self.plugins_folder) + path.append(self.config['plugin_folder']) self.create_plugin_index() def read_config(self): """ read config and sets preferences """ - config = ConfigParser.ConfigParser() + + config = ConfigParser.SafeConfigParser() config.read('config') + + for section in config.sections(): + for option in config.options(section): + self.config[option] = config.get(section, option) + 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['search_updates'] = config.getboolean('updates', 'searchUpdates') self.config['log_folder'] = config.get('log', 'logFolder') + self.config['reconnectMethod'] = config.get('general', 'reconnectMethod') + def create_plugin_index(self): - for file_handler in glob(self.plugins_folder + sep + '*.py'): - if file_handler != self.plugins_folder + sep + "Plugin.py": + for file_handler in glob(self.config['plugin_folder'] + sep + '*.py'): + if file_handler != self.config['plugin_folder'] + sep + "Plugin.py": plugin_pattern = "" plugin_file = basename(file_handler).replace('.py', '') for line in open(file_handler, "r").readlines(): - if "plugin_config['pattern']" in line: + if "props['pattern']" in line: plugin_pattern = line.split("r\"")[1].split("\"")[0] if plugin_pattern != "": self.plugins_avaible[plugin_file] = plugin_pattern @@ -134,7 +146,7 @@ class Core(object): else: print "Beta Version " + CURRENT_VERSION + " in benutzung" #using beta version - def check_create(self, check_name, legend, folder = True): + def check_create(self, check_name, legend, folder=True): if not exists(check_name): try: if folder: @@ -166,7 +178,7 @@ class Core(object): return True def init_logger(self, level): - handler = logging.handlers.RotatingFileHandler(self.config['log_folder'] + sep + 'log.txt', maxBytes = 12800 , backupCount = 10) #100 kb + handler = logging.handlers.RotatingFileHandler(self.config['log_folder'] + sep + 'log.txt', maxBytes=12800, backupCount=10) #100 kb console = logging.StreamHandler(stdout) #handler = logging.FileHandler('Logs/log.txt') frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S") @@ -178,15 +190,35 @@ class Core(object): self.logger.addHandler(console) #if console logging self.logger.setLevel(level) + + def is_dltime(self): + start_h, start_m = self.config['start'].split(":") + end_h, end_m = self.config['end'].split(":") + + #@todo: doesnt work at the moment + hour, minute = time.localtime()[3:5] + + print start_h, start_m, end_h, end_m + print hour, minute + + if hour > start_h and hour < end_h: + return True + elif hour == start_h and minute >= start_m: + return True + elif hour == end_h and minute <= end_m: + return True + else: + return False + def _test_print_status(self): if self.thread_list.py_downloading: for pyfile in self.thread_list.py_downloading: if pyfile.status.type == 'downloading': - print pyfile.status.filename + ": speed is" ,int(pyfile.status.get_speed()) ,"kb/s" - print pyfile.status.filename + ": arraives in" ,int(pyfile.status.get_ETA()) ,"seconds" + print pyfile.status.filename + ": speed is", int(pyfile.status.get_speed()), "kb/s" + print pyfile.status.filename + ": arraives in", int(pyfile.status.get_ETA()), "seconds" elif pyfile.status.type == 'waiting': - print pyfile.status.filename + ": wait", int(pyfile.status.waituntil -time()) , "seconds" + print pyfile.status.filename + ": wait", int(pyfile.status.waituntil -time.time()), "seconds" def start(self): """ starts the machine |