diff --git a/lib/platformDep.py b/lib/platformDep.py index 655c27c..0a47b0d 100644 --- a/lib/platformDep.py +++ b/lib/platformDep.py @@ -1,5 +1,6 @@ import os import platform +import stat def getNamecoinDir(): if platform.system() == "Darwin": diff --git a/lib/plugin.py b/lib/plugin.py index 2db67ab..ae0b1b5 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -20,7 +20,7 @@ class PluginThread(threading.Thread): desc = None running = False threadRunning = False - options = {} + options = [] helps = {} depends = {} services = {} @@ -34,6 +34,7 @@ def __init__(self, mode = 'plugin'): self.nameclass = self.mode + self.name.capitalize() self.parser = app['parser'] self.conf = {} + self._initconfig() self._loadconfig() threading.Thread.__init__(self) @@ -88,7 +89,7 @@ def reload(self, arg = []): def pReload(self, arg = []): if app['debug']: print "Plugin %s parent reload" %(self.name) - self.loadconfig() + self._loadconfig() return True def restart(self, arg = []): @@ -142,7 +143,10 @@ def _getPluginMethods(self): methods.sort() return methods - def _loadconfig(self, arg = []): + def _getUserConfFile(self): + return app['path']['conf'] + self.nameconf + + def _initconfig(self, arg = []): # manage services for service, value in self.services.iteritems(): if self.name not in app['services'][service].services: @@ -152,11 +156,7 @@ def _loadconfig(self, arg = []): # add command line args to the program options + build default configuration data defaultConf = '[' + self.name + ']\n' group = OptionGroup(app['parser'], self.name.capitalize() + " Options", self.desc) - if self.options.__class__ is dict: - tmp = [] - for option, value in self.options.items(): - tmp.append({option: value}) - self.options = tmp + #for option, value in self.options.items(): for option in self.options: option, value = option.items()[0] @@ -176,7 +176,7 @@ def _loadconfig(self, arg = []): app['parser'].add_option_group(group) # create default config if none - userConfFile = app['path']['conf'] + self.nameconf + userConfFile = self._getUserConfFile() if not os.path.exists(userConfFile): if not os.path.exists(app['path']['conf']): # TODO: Note that with Python 3.2+ we can compress this to os.makedirs(app['path']['conf'], exist_ok=True), see http://stackoverflow.com/a/5032238 os.makedirs(app['path']['conf']) @@ -184,6 +184,9 @@ def _loadconfig(self, arg = []): fp.write(defaultConf) fp.close() + def _loadconfig(self, arg = []): + userConfFile = self._getUserConfFile() + # read user config fileconf = SafeConfigParser() fileconf.read(userConfFile) diff --git a/nmcontrol.py b/nmcontrol.py index 2f380fe..08d2bef 100755 --- a/nmcontrol.py +++ b/nmcontrol.py @@ -4,14 +4,12 @@ import os import sys -import inspect import optparse import ConfigParser app = {} def main(): # init app config - global app app['conf'] = ConfigParser.SafeConfigParser() app['path'] = {} app['path']['app'] = os.path.dirname(os.path.realpath(__file__)) + os.sep diff --git a/plugin/pluginData.py b/plugin/pluginData.py index 33a5c9b..e8fddd8 100644 --- a/plugin/pluginData.py +++ b/plugin/pluginData.py @@ -45,7 +45,7 @@ class pluginData(plugin.PluginThread): def pLoadconfig(self): # convert string interval to a number of seconds for key, value in self.conf.items(): - if '.freq' in key: + if '.freq' in key and type(self.conf[key]) != int: if value[-1] == 's': self.conf[key] = int(value[0:-1]) elif value[-1] == 'm': diff --git a/plugin/pluginDns.py b/plugin/pluginDns.py index 6817c52..cf70bf3 100644 --- a/plugin/pluginDns.py +++ b/plugin/pluginDns.py @@ -43,13 +43,13 @@ def toJsonForRPC(self): class pluginDns(plugin.PluginThread): name = 'dns' - options = { - 'start': ['Launch at startup', 1], - 'disable_ns_lookups': ['Disable remote lookups for NS records','0'], - #'host': ['Listen on ip', '127.0.0.1'], - #'port': ['Listen on port', 53], - #'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4'], - } + options = [ + {'start': ['Launch at startup', 1]}, + {'disable_ns_lookups': ['Disable remote lookups for NS records','0']}, + #{'host': ['Listen on ip', '127.0.0.1']}, + #{'port': ['Listen on port', 53]}, + #{'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4']}, + ] helps = { 'getIp4': [1, 1, '', 'Get a list of IPv4 for the domain'], 'getIp6': [1, 1, '', 'Get a list of IPv6 for the domain'], diff --git a/plugin/pluginHttp.py b/plugin/pluginHttp.py index b863d0f..6ad8d0a 100644 --- a/plugin/pluginHttp.py +++ b/plugin/pluginHttp.py @@ -56,7 +56,7 @@ def call_plugin(plugin, method, args): # can't call private/protected methods if method[0] == '_': - if app['debug']: print "RPC - forbidden cmd :", "/" + "/".join([plugin, method, arg1]) + ".json" + if app['debug']: print "RPC - forbidden cmd :", "/" + "/".join([plugin, method, args]) + ".json" raise Exception('Method "' + method + '" not allowed') """ @@ -104,12 +104,12 @@ def call_plugin(plugin, method, args): class pluginHttp(plugin.PluginThread): name = 'http' - options = { - 'start': ['Launch at startup', 1], - 'host': ['Listen on ip', '127.0.0.2', ''], - 'port': ['Listen on port', '8080', ''], + options = [ + {'start': ['Launch at startup', 1]}, + {'host': ['Listen on ip', '127.0.0.2', '']}, + {'port': ['Listen on port', '8080', '']}, # TODO: Figure out what the defaults should be for IP/port - } + ] systrayEntry = ('httpGui', None, launch_httpGui) # menu icons should somehow be possible via the middle option def pStatus(self): diff --git a/plugin/pluginMain.py b/plugin/pluginMain.py index 96243bd..8f4e9e8 100644 --- a/plugin/pluginMain.py +++ b/plugin/pluginMain.py @@ -4,13 +4,13 @@ class pluginMain(plugin.PluginThread): name = 'main' - options = { - 'start': ['Launch at startup', (1, 0)[platform.system() == 'Windows']], - 'debug': ['Debug mode', 0, '<0|1>'], - 'daemon': ['Background mode', 1, '<0|1>'], - 'confdir': ['Configuration file directory', ""], - #'plugins': ['Load only those plugins', 'main,data,rpc'], - } + options = [ + {'start': ['Launch at startup', (1, 0)[platform.system() == 'Windows']]}, + {'debug': ['Debug mode', 0, '<0|1>']}, + {'daemon': ['Background mode', 1, '<0|1>']}, + {'confdir': ['Configuration file directory', ""]}, + #{'plugins': ['Load only those plugins', 'main,data,rpc']}, + ] def pStart(self): app['plugins']['rpc'].start2() diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index f3a0010..4d4392e 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -5,10 +5,10 @@ class pluginNamespaceDomain(plugin.PluginThread): name = 'domain' - options = { - 'start': ['Launch at startup', 1], - #'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4'], - } + options = [ + {'start': ['Launch at startup', 1]}, + #{'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4']}, + ] depends = {'plugins': ['data', 'dns'],'services': ['dns']} filters = {'dns': '.bit$|.tor$'} handle = ['dns'] diff --git a/plugin/pluginRpc.py b/plugin/pluginRpc.py index 2edbcbc..e339604 100644 --- a/plugin/pluginRpc.py +++ b/plugin/pluginRpc.py @@ -5,11 +5,11 @@ class pluginRpc(plugin.PluginThread): name = 'rpc' - options = { - 'start': ['Launch at startup', 1], - 'host': ['Listen on ip', '127.0.0.1', ''], - 'port': ['Listen on port', 9000, ''], - } + options = [ + {'start': ['Launch at startup', 1]}, + {'host': ['Listen on ip', '127.0.0.1', '']}, + {'port': ['Listen on port', 9000, '']}, + ] def pStatus(self): if self.running: diff --git a/plugin/pluginSystray.py b/plugin/pluginSystray.py index 8c426f3..3cb0d98 100644 --- a/plugin/pluginSystray.py +++ b/plugin/pluginSystray.py @@ -11,9 +11,9 @@ class pluginSystray(plugin.PluginThread): name = 'systray' - options = { - 'start': ['Launch at startup', 1], - } + options = [ + {'start': ['Launch at startup', 1]}, + ] sti = None def gather_entries(self): diff --git a/service/serviceDNS.py b/service/serviceDNS.py index d03ebb1..357e730 100644 --- a/service/serviceDNS.py +++ b/service/serviceDNS.py @@ -6,13 +6,13 @@ class serviceDNS(plugin.PluginThread): name = 'dns' - options = { - 'start': ['Launch at startup', 1], - 'host': ['Listen on ip', '127.0.0.1'], - 'port': ['Listen on port', 53], - 'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4'], - 'disable_standard_lookups': ['Disable lookups for standard domains','1'] - } + options = [ + {'start': ['Launch at startup', 1]}, + {'host': ['Listen on ip', '127.0.0.1']}, + {'port': ['Listen on port', 53]}, + {'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4']}, + {'disable_standard_lookups': ['Disable lookups for standard domains','1']}, + ] srv = None def pStart(self):