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 --- module/XMLConfigParser.py | 92 +++++++++++++++++++++++++++++++++++++++++++ module/config/core.xml | 58 +++++++++++++++++++++++++++ module/config/gui_default.xml | 7 ++++ module/web/settings.py | 9 +++-- 4 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 module/XMLConfigParser.py create mode 100644 module/config/core.xml create mode 100644 module/config/gui_default.xml (limited to 'module') 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' -- cgit v1.2.3