From d08271cbb66f3ccbd8f3c5cf707008388ff4297e Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 21:33:13 +0100 Subject: new xml config for core --- .hgignore | 2 +- config | 58 --------------------------- guiconfig_default.xml | 7 ---- module/XMLConfigParser.py | 92 +++++++++++++++++++++++++++++++++++++++++++ module/config/core.xml | 58 +++++++++++++++++++++++++++ module/config/gui_default.xml | 7 ++++ module/web/settings.py | 9 +++-- pyLoadCore.py | 25 ++---------- pyLoadGui.py | 2 +- 9 files changed, 168 insertions(+), 92 deletions(-) delete mode 100644 config delete mode 100644 guiconfig_default.xml create mode 100644 module/XMLConfigParser.py create mode 100644 module/config/core.xml create mode 100644 module/config/gui_default.xml diff --git a/.hgignore b/.hgignore index 44507b09a..47098d04c 100644 --- a/.hgignore +++ b/.hgignore @@ -12,7 +12,7 @@ Downloads/* Logs/* Plugins/DLC.py failed_links.txt -guiconfig.xml +module/config/gui.xml links.txt module/links.pkl module/cookies.txt diff --git a/config b/config deleted file mode 100644 index cc134aab3..000000000 --- a/config +++ /dev/null @@ -1,58 +0,0 @@ -[remote] -port = 7227 -listenaddr = 0.0.0.0 -username = admin -password = pwhere - -[ssl] -activated = False -cert = ssl.crt -key = ssl.key - -[webinterface] -activated = False -host = 127.0.0.1 -# 0.0.0.0 to make it accessible from everywhere -port = 8000 -template = default -local = True -#ONLY SPECIFY IF PYLOAD NOT RUN ON YOUR LOCALHOST -ssl = None -username = None -adress = None -extport = None -pw = None - -[log] -file_log = True -log_folder = Logs -log_count = 5 - -[general] -language = de -download_folder = Downloads -max_downloads = 3 -use_reconnect = False -link_file = links.txt -failed_file = failed_links.txt -reconnect_method = reconnect_method -debug_mode = True -#hours -max_download_time = 5 - -[updates] -search_updates = True -install_updates = False - -[reconnectTime] -start = 0:00 -end = 0:00 - -[downloadTime] -start = 0:00 -end = 0:00 - -[proxy] -activated = False -adress = http://localhost:8080 -protocol = http diff --git a/guiconfig_default.xml b/guiconfig_default.xml deleted file mode 100644 index af38eda4c..000000000 --- a/guiconfig_default.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Local - - - diff --git a/module/XMLConfigParser.py b/module/XMLConfigParser.py new file mode 100644 index 000000000..1bd5e3417 --- /dev/null +++ b/module/XMLConfigParser.py @@ -0,0 +1,92 @@ +# -*- 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 +""" + +from xml.dom.minidom import parse + +class XMLConfigParser(): + def __init__(self, data): + self.xml = None + self.file = data + self.config = {} + self.loadData() + self.root = None + + def loadData(self): + with open(self.file, 'r') as fh: + self.xml = parse(fh) + self._read_config() + + def saveData(self): + with open(self.file, 'w') as fh: + self.xml.writexml(fh) + + def _read_config(self): + def format(val): + if val.lower() == "true": + return True + elif val.lower() == "false": + return False + else: + return val + root = self.xml.documentElement + self.root = root + config = {} + for node in root.childNodes: + if node.nodeType == node.ELEMENT_NODE: + section = node.tagName + config[section] = {} + for opt in node.childNodes: + if opt.nodeType == opt.ELEMENT_NODE: + config[section][opt.tagName] = format(opt.firstChild.data) + self.config = config + + def get(self, section, option, default=None): + try: + return self.config[section][option] + except: + return default + + def getConfig(self): + return self.config + + def set(self, section, option, value): + root = self.root + replace = False + sectionNode = False + for node in root.childNodes: + if node.nodeType == node.ELEMENT_NODE: + if section == node.tagName: + sectionNode = node + for opt in node.childNodes: + if opt.nodeType == opt.ELEMENT_NODE: + if option == opt.tagName: + replace = opt + text = self.createTextNode(value) + if replace: + replace.replaceChild(text, replace.firstChild) + else: + newNode = self.createElement(option) + newNode.appendChild(text) + if sectionNode: + sectionNode.appendChild(newNode) + else: + newSection = self.createElement(section) + newSection.appendChild(newNode) + root.appendChild(newSection) + self.saveData() + self.loadData() diff --git a/module/config/core.xml b/module/config/core.xml new file mode 100644 index 000000000..891856c00 --- /dev/null +++ b/module/config/core.xml @@ -0,0 +1,58 @@ + + + 7227 + 0.0.0.0 + admin + pwhere + + + False + ssl.srt + ssl.key + + + True + 127.0.0.1 + 8000 + + True + None + None + None + None + None + + + True + Logs + 5 + + + de + Downloads + 3 + False + links.txt + failed_links.txt + reconnect_method + False + 5 + + + True + False + + + 0:00 + 0:00 + + + 0:00 + 0:00 + + + False + http://localhost:8080 + http + + diff --git a/module/config/gui_default.xml b/module/config/gui_default.xml new file mode 100644 index 000000000..af38eda4c --- /dev/null +++ b/module/config/gui_default.xml @@ -0,0 +1,7 @@ + + + + Local + + + diff --git a/module/web/settings.py b/module/web/settings.py index 2695b0648..2c7f4ecd8 100644 --- a/module/web/settings.py +++ b/module/web/settings.py @@ -4,8 +4,8 @@ DEBUG = True TEMPLATE_DEBUG = DEBUG -import ConfigParser import os.path +import sys from os import chdir from os.path import dirname from os.path import abspath @@ -17,11 +17,12 @@ SERVER_VERSION = "0.3" PROJECT_DIR = os.path.dirname(__file__) #chdir(dirname(abspath(__file__)) + sep) -config = ConfigParser.SafeConfigParser() PYLOAD_DIR = os.path.join(PROJECT_DIR,"..","..") -config.read(os.path.join(PYLOAD_DIR,"config")) +sys.path.append(os.path.join(PYLOAD_DIR, "module")) +from XMLConfigParser import XMLConfigParser +config = XMLConfigParser(os.path.join(PYLOAD_DIR,"module","config","core.xml")) ssl = "" @@ -132,4 +133,4 @@ INSTALLED_APPS = ( AUTH_PROFILE_MODULE = 'pyload.UserProfile' -LOGIN_URL = '/login' \ No newline at end of file +LOGIN_URL = '/login' diff --git a/pyLoadCore.py b/pyLoadCore.py index 371c0d8fb..7e1b9ebfc 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -23,7 +23,6 @@ """ CURRENT_VERSION = '0.3' -import ConfigParser import gettext from glob import glob from imp import find_module @@ -54,6 +53,7 @@ from module.network.Request import Request import module.remote.SecureXMLRPCServer as Server from module.thread_list import Thread_List from module.web.ServerThread import WebServer +from module.XMLConfigParser import XMLConfigParser class Core(object): """ pyLoad Core """ @@ -62,24 +62,6 @@ class Core(object): if argv[1] == "-v": print "pyLoad", CURRENT_VERSION exit() - - def read_config(self): - """ read config and sets preferences """ - self.configfile = ConfigParser.SafeConfigParser() - self.configfile.read(join(self.path,'config')) - for section in self.configfile.sections(): - self.config[section] = {} - for option in self.configfile.options(section): - self.config[section][option] = self.configfile.get(section, option) - self.config[section][option] = False if self.config[section][option].lower() == 'false' else self.config[section][option] - - def set_option(self, section, option, value): - self.config[option] = value - self.configfile.set(section, option, str(value)) - self.configfile.write(open(join(self.path,'config'), "wb")) - - def read_option(self): - return self.config def shutdown(self): "abort all downloads and exit" @@ -110,8 +92,9 @@ class Core(object): self.plugin_folder = join("module", "plugins") - self.read_config() - + self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml")) + self.config = self.xmlconfig.getConfig() + self.do_kill = False translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) diff --git a/pyLoadGui.py b/pyLoadGui.py index f8ba3efd3..3b8658e1b 100644 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -48,7 +48,7 @@ class main(QObject): self.connector = connector() self.mainloop = self.Loop(self) self.connectSignals() - self.parser = XMLParser("guiconfig.xml", "guiconfig_default.xml") + self.parser = XMLParser("module/config/gui.xml", "module/config/gui_default.xml") self.refreshConnections() self.connData = None -- cgit v1.2.3