summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar spoob <spoob@gmx.de> 2010-01-07 19:05:42 +0100
committerGravatar spoob <spoob@gmx.de> 2010-01-07 19:05:42 +0100
commit205c200b94f3b4edf1220a9ffd5ebeab58aa098b (patch)
tree913097d568e2fcfcebfb0dc455ce936468a5c51b
parentBetter Rapidshare Slot Check thanks #66 (diff)
downloadpyload-205c200b94f3b4edf1220a9ffd5ebeab58aa098b.tar.xz
Better ConfigParser
-rw-r--r--module/Plugin.py2
-rw-r--r--module/XMLConfigParser.py34
-rw-r--r--module/config/core_default.xml2
-rw-r--r--module/config/plugin_default.xml2
-rw-r--r--module/plugins/hooks/Hook.py2
-rwxr-xr-xpyLoadCore.py2
6 files changed, 29 insertions, 15 deletions
diff --git a/module/Plugin.py b/module/Plugin.py
index 7854aa66d..45371c3af 100644
--- a/module/Plugin.py
+++ b/module/Plugin.py
@@ -31,7 +31,7 @@ from module.download_thread import CaptchaError
class Plugin():
def __init__(self, parent):
- self.configparser = XMLConfigParser(join("module","config","plugin.xml"), join("module","config","plugin_default.xml"))
+ self.configparser = XMLConfigParser(join("module","config","plugin.xml"))
self.config = {}
props = {}
props['name'] = "BasePlugin"
diff --git a/module/XMLConfigParser.py b/module/XMLConfigParser.py
index 5b1966152..8105eb929 100644
--- a/module/XMLConfigParser.py
+++ b/module/XMLConfigParser.py
@@ -13,7 +13,7 @@
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
+ @author: mkaay, spoob
"""
from __future__ import with_statement
@@ -21,11 +21,14 @@ from os.path import exists
from xml.dom.minidom import parse
+from shutil import copy
+
class XMLConfigParser():
- def __init__(self, data, default_data=None):
+ def __init__(self, data):
self.xml = None
+ self.version = "0.1"
self.file = data
- self.file_default = default_data
+ self.file_default = self.file.replace(".xml", "_default.xml")
self.config = {}
self.data = {}
self.types = {}
@@ -35,15 +38,29 @@ class XMLConfigParser():
def loadData(self):
file = self.file
if not exists(self.file):
- file = self.file_default
+ self._copyConfig()
with open(file, 'r') as fh:
self.xml = parse(fh)
+ if not self.xml.documentElement.getAttribute("version") == self.version:
+ self._copyConfig()
+ with open(file, 'r') as fh:
+ self.xml = parse(fh)
+ if not self.xml.documentElement.getAttribute("version") == self.version:
+ print "Cant Update %s" % self.file
+ exit() #ok?
self._read_config()
-
+
+ def _copyConfig(self):
+ try:
+ copy(self.file_default, self.file)
+ except:
+ print "%s not found" % self.file_default
+ exit() #ok?
+
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":
@@ -85,10 +102,7 @@ class XMLConfigParser():
def getConfig(self):
return self.config
-
- def getData(self):
- return self.data
-
+
def set(self, section, option, value):
root = self.root
replace = False
diff --git a/module/config/core_default.xml b/module/config/core_default.xml
index 366197a61..07d4ddc1c 100644
--- a/module/config/core_default.xml
+++ b/module/config/core_default.xml
@@ -1,4 +1,4 @@
-<config name="Configuration">
+<config name="Configuration" version="0.1">
<remote name="Remote">
<port type="int" name="Port">7227</port>
<listenaddr type="ip" name="Adress">0.0.0.0</listenaddr>
diff --git a/module/config/plugin_default.xml b/module/config/plugin_default.xml
index 1ad653251..3f033fc04 100644
--- a/module/config/plugin_default.xml
+++ b/module/config/plugin_default.xml
@@ -1,4 +1,4 @@
-<config>
+<config name="Configuration" version="0.1">
<RapidshareCom>
<server input=";Cogent;Deutsche Telekom;Level(3);Level(3) #2;GlobalCrossing;Level(3) #3;Teleglobe;GlobalCrossing #2;TeliaSonera #2;Teleglobe #2;TeliaSonera #3;TeliaSonera"></server>
<premium>False</premium>
diff --git a/module/plugins/hooks/Hook.py b/module/plugins/hooks/Hook.py
index 09b21ba49..739af3200 100644
--- a/module/plugins/hooks/Hook.py
+++ b/module/plugins/hooks/Hook.py
@@ -26,7 +26,7 @@ from module.XMLConfigParser import XMLConfigParser
class Hook():
def __init__(self, core):
self.logger = logging.getLogger("log")
- self.configParser = XMLConfigParser(join("module","config","plugin.xml"), join("module","config","plugin_default.xml"))
+ self.configParser = XMLConfigParser(join("module","config","plugin.xml"))
self.config = {}
props = {}
props['name'] = "Hook"
diff --git a/pyLoadCore.py b/pyLoadCore.py
index c43fac3c8..16c272d5e 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -90,7 +90,7 @@ class Core(object):
self.plugin_folder = join("module", "plugins")
- self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml"), join(self.path,"module","config","core_default.xml"))
+ self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml"))
self.config = self.xmlconfig.getConfig()
self.do_kill = False