diff options
| -rw-r--r-- | .hgignore | 2 | ||||
| -rw-r--r-- | config | 58 | ||||
| -rw-r--r-- | module/XMLConfigParser.py | 92 | ||||
| -rw-r--r-- | module/config/core.xml | 58 | ||||
| -rw-r--r-- | module/config/gui_default.xml (renamed from guiconfig_default.xml) | 0 | ||||
| -rw-r--r-- | module/web/settings.py | 9 | ||||
| -rwxr-xr-x | pyLoadCore.py | 25 | ||||
| -rw-r--r-- | pyLoadGui.py | 2 | 
8 files changed, 161 insertions, 85 deletions
| @@ -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/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/guiconfig_default.xml b/module/config/gui_default.xml index af38eda4c..af38eda4c 100644 --- a/guiconfig_default.xml +++ b/module/config/gui_default.xml 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 | 
