summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-01-02 15:32:29 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2010-01-02 15:32:29 +0100
commit4ead56475df252c3783701ddf27be9abbd410ad3 (patch)
tree4b81867d40eabdeb0d2722c3ed67884455f87e5e
parentnew cli functions (diff)
downloadpyload-4ead56475df252c3783701ddf27be9abbd410ad3.tar.xz
new xmlparser
-rw-r--r--module/XMLConfigParser.py36
-rw-r--r--module/config/core_default.xml82
2 files changed, 77 insertions, 41 deletions
diff --git a/module/XMLConfigParser.py b/module/XMLConfigParser.py
index eedc00b67..444d45928 100644
--- a/module/XMLConfigParser.py
+++ b/module/XMLConfigParser.py
@@ -27,6 +27,8 @@ class XMLConfigParser():
self.file = data
self.file_default = default_data
self.config = {}
+ self.data = {}
+ self.types = {}
self.loadData()
self.root = None
@@ -53,17 +55,27 @@ class XMLConfigParser():
root = self.xml.documentElement
self.root = root
config = {}
+ data = {}
for node in root.childNodes:
if node.nodeType == node.ELEMENT_NODE:
section = node.tagName
config[section] = {}
+ data[section] = {}
+ data[section]["options"] = {}
+ data[section]["name"] = node.getAttribute("name")
for opt in node.childNodes:
if opt.nodeType == opt.ELEMENT_NODE:
+ data[section]["options"][opt.tagName] = {}
try:
config[section][opt.tagName] = format(opt.firstChild.data)
+ data[section]["options"][opt.tagName]["value"] = format(opt.firstChild.data)
except:
config[section][opt.tagName] = ""
+ data[section]["options"][opt.tagName]["name"] = opt.getAttribute("name")
+ data[section]["options"][opt.tagName]["type"] = opt.getAttribute("type")
+ data[section]["options"][opt.tagName]["input"] = opt.getAttribute("input")
self.config = config
+ self.data = data
def get(self, section, option, default=None):
try:
@@ -100,3 +112,27 @@ class XMLConfigParser():
root.appendChild(newSection)
self.saveData()
self.loadData()
+
+ def getType(self, section, option):
+ try:
+ return self.data[section]["options"][option]["type"]
+ except:
+ return "str"
+
+ def getInputValues(self, section, option):
+ try:
+ return self.data[section]["options"][option]["input"].split(";")
+ except:
+ return []
+
+ def getDisplayName(self, section, option=None):
+ try:
+ if option:
+ return self.data[section]["options"][option]["name"]
+ else:
+ return self.data[section]["name"]
+ except:
+ if option:
+ return option
+ else:
+ return section
diff --git a/module/config/core_default.xml b/module/config/core_default.xml
index 7f503ce18..58e5d1be2 100644
--- a/module/config/core_default.xml
+++ b/module/config/core_default.xml
@@ -1,60 +1,60 @@
<config>
- <remote>
- <port>7227</port>
- <listenaddr>0.0.0.0</listenaddr>
- <username>admin</username>
- <password>pwhere</password>
+ <remote name="Remote">
+ <port type="int" name="Port">7227</port>
+ <listenaddr type="ip" name="Adress">0.0.0.0</listenaddr>
+ <username type="str" name="Username">admin</username>
+ <password type="str" name="Password">pwhere</password>
</remote>
<ssl>
- <activated>False</activated>
- <cert>ssl.srt</cert>
- <key>ssl.key</key>
+ <activated type="bool" name="">False</activated>
+ <cert type="str" name="Remote Port">ssl.srt</cert>
+ <key type="str" name="Remote Port">ssl.key</key>
</ssl>
<webinterface>
- <activated>True</activated>
- <host>0.0.0.0</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>
+ <activated type="bool">True</activated>
+ <host type="ip">0.0.0.0</host>
+ <port type="int">8000</port>
+ <template type="str">default</template>
+ <local type="bool">True</local>
+ <ssl type="bool">False</ssl>
+ <username type="str">None</username>
+ <adress type="ip">None</adress>
+ <extport type="int">None</extport>
+ <pw type="str">None</pw>
</webinterface>
<log>
- <file_log>True</file_log>
- <log_folder>Logs</log_folder>
- <log_count>5</log_count>
+ <file_log type="bool">True</file_log>
+ <log_folder type="str">Logs</log_folder>
+ <log_count type="int">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>
- <download_speed_limit>0</download_speed_limit>
- <checksum>True</checksum>
+ <language type="str" input="en;de;fr">de</language>
+ <download_folder type="str">Downloads</download_folder>
+ <max_downloads type="int">3</max_downloads>
+ <use_reconnect type="bool">False</use_reconnect>
+ <link_file type="str">links.txt</link_file>
+ <failed_file type="str">failed_links.txt</failed_file>
+ <reconnect_method type="str">None</reconnect_method>
+ <debug_mode type="bool">False</debug_mode>
+ <max_download_time type="int">5</max_download_time>
+ <download_speed_limit type="int">0</download_speed_limit>
+ <checksum type="bool">True</checksum>
</general>
<updates>
- <search_updates>True</search_updates>
- <install_updates>False</install_updates>
+ <search_updates type="bool">True</search_updates>
+ <install_updates type="bool">False</install_updates>
</updates>
<reconnectTime>
- <start>0:00</start>
- <end>0:00</end>
+ <start type="time">0:00</start>
+ <end type="time">0:00</end>
</reconnectTime>
<downloadTime>
- <start>0:00</start>
- <end>0:00</end>
+ <start type="time">0:00</start>
+ <end type="time">0:00</end>
</downloadTime>
<proxy>
- <activated>False</activated>
- <adress>http://localhost:8080</adress>
- <protocol>http</protocol>
+ <activated type="bool">False</activated>
+ <adress type="str">http://localhost:8080</adress>
+ <protocol type="str">http</protocol>
</proxy>
</config>