diff options
author | mkaay <mkaay@mkaay.de> | 2009-12-17 21:33:13 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2009-12-17 21:33:13 +0100 |
commit | d08271cbb66f3ccbd8f3c5cf707008388ff4297e (patch) | |
tree | edd2c3ebad7c066ab96a6a13ddaacb5c96292b4b /module | |
parent | better Megaupload captcha detection, fixed #38 (diff) | |
download | pyload-d08271cbb66f3ccbd8f3c5cf707008388ff4297e.tar.xz |
new xml config for core
Diffstat (limited to 'module')
-rw-r--r-- | module/XMLConfigParser.py | 92 | ||||
-rw-r--r-- | module/config/core.xml | 58 | ||||
-rw-r--r-- | module/config/gui_default.xml | 7 | ||||
-rw-r--r-- | module/web/settings.py | 9 |
4 files changed, 162 insertions, 4 deletions
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 <http://www.gnu.org/licenses/>. + + @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 @@ +<config> + <remote> + <port>7227</port> + <listenaddr>0.0.0.0</listenaddr> + <username>admin</username> + <password>pwhere</password> + </remote> + <ssl> + <activated>False</activated> + <cert>ssl.srt</cert> + <key>ssl.key</key> + </ssl> + <webinterface> + <activated>True</activated> + <host>127.0.0.1</host> + <port>8000</port> + <template>default</template> + <local>True</local> + <ssl>None</ssl> + <username>None</username> + <adress>None</adress> + <extport>None</extport> + <pw>None</pw> + </webinterface> + <log> + <file_log>True</file_log> + <log_folder>Logs</log_folder> + <log_count>5</log_count> + </log> + <general> + <language>de</language> + <download_folder>Downloads</download_folder> + <max_downloads>3</max_downloads> + <use_reconnect>False</use_reconnect> + <link_file>links.txt</link_file> + <failed_file>failed_links.txt</failed_file> + <reconnect_method>reconnect_method</reconnect_method> + <debug_mode>False</debug_mode> + <max_download_time>5</max_download_time> + </general> + <updates> + <search_updates>True</search_updates> + <install_updates>False</install_updates> + </updates> + <reconnectTime> + <start>0:00</start> + <end>0:00</end> + </reconnectTime> + <downloadTime> + <start>0:00</start> + <end>0:00</end> + </downloadTime> + <proxy> + <activated>False</activated> + <adress>http://localhost:8080</adress> + <protocol>http</protocol> + </proxy> +</config> 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 @@ +<root> + <connections> + <connection default="True" type="local" id="33965310e19b4a869112c43b39a16440"> + <name>Local</name> + </connection> + </connections> +</root> 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' |