Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/platformDep.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import platform
import stat

def getNamecoinDir():
if platform.system() == "Darwin":
Expand Down
21 changes: 12 additions & 9 deletions lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PluginThread(threading.Thread):
desc = None
running = False
threadRunning = False
options = {}
options = []
helps = {}
depends = {}
services = {}
Expand All @@ -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)

Expand Down Expand Up @@ -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 = []):
Expand Down Expand Up @@ -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:
Expand All @@ -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]
Expand All @@ -176,14 +176,17 @@ 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'])
fp = open(userConfFile, 'w')
fp.write(defaultConf)
fp.close()

def _loadconfig(self, arg = []):
userConfFile = self._getUserConfFile()

# read user config
fileconf = SafeConfigParser()
fileconf.read(userConfFile)
Expand Down
2 changes: 0 additions & 2 deletions nmcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not remove this, it helps readability. As long as we don't remove this global we should at least be explicit about it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never write to app; PyLint therefore complains that we shouldn't declare it as a global, since the only reason to declare as a global is so that you can write to it. I don't think it makes things more readable either (and it makes the code less readable to PyLint).

app['path']['app'] = os.path.dirname(os.path.realpath(__file__)) + os.sep
Expand Down
2 changes: 1 addition & 1 deletion plugin/pluginData.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
14 changes: 7 additions & 7 deletions plugin/pluginDns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<domain>', 'Get a list of IPv4 for the domain'],
'getIp6': [1, 1, '<domain>', 'Get a list of IPv6 for the domain'],
Expand Down
12 changes: 6 additions & 6 deletions plugin/pluginHttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

"""
Expand Down Expand Up @@ -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', '<ip>'],
'port': ['Listen on port', '8080', '<port>'],
options = [
{'start': ['Launch at startup', 1]},
{'host': ['Listen on ip', '127.0.0.2', '<ip>']},
{'port': ['Listen on port', '8080', '<port>']},
# 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):
Expand Down
14 changes: 7 additions & 7 deletions plugin/pluginMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', "<system conf dir>"],
#'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', "<system conf dir>"]},
#{'plugins': ['Load only those plugins', 'main,data,rpc']},
]

def pStart(self):
app['plugins']['rpc'].start2()
Expand Down
8 changes: 4 additions & 4 deletions plugin/pluginNamespaceDomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
10 changes: 5 additions & 5 deletions plugin/pluginRpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

class pluginRpc(plugin.PluginThread):
name = 'rpc'
options = {
'start': ['Launch at startup', 1],
'host': ['Listen on ip', '127.0.0.1', '<ip>'],
'port': ['Listen on port', 9000, '<port>'],
}
options = [
{'start': ['Launch at startup', 1]},
{'host': ['Listen on ip', '127.0.0.1', '<ip>']},
{'port': ['Listen on port', 9000, '<port>']},
]

def pStatus(self):
if self.running:
Expand Down
6 changes: 3 additions & 3 deletions plugin/pluginSystray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions service/serviceDNS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down