Skip to content
Merged
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
18 changes: 6 additions & 12 deletions lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,8 @@ 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]
value = self.options[option]
if len(value) == 3:
help = value[0] + " " + value[2] + ""
defaultConf += '; ' + value[0] + ' - choices: ' + value[2] + '\n'
Expand Down Expand Up @@ -203,18 +197,18 @@ def _rpc(self, method, *args, **kwargs): #, module = None):
# self = __import__(module)
#elif module is not None:
# self = module

func = getattr(self, method)

if "api_user" not in kwargs:
api_user = "public"
else:
api_user = kwargs["api_user"]

if app["debug"]:
print method, "public function?", hasattr(func, "rpc_public")

if api_user != "admin" and not hasattr(func, "rpc_public"):
raise Exception('Method "' + method + '" not allowed')

return func(*args)
4 changes: 4 additions & 0 deletions nmcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import inspect
import optparse
import ConfigParser
import traceback

app = {}
def main():
Expand Down Expand Up @@ -62,12 +63,15 @@ def main():
module = re.sub(r'\.py$', '', module)
modulename = re.sub(r'^'+modType, '', module).lower()
try:
if app["debug"]:
print "launching", modType, module
importedModule = __import__(module)
importedClass = getattr(importedModule, module)
app[modType+'s'][importedClass.name] = importedClass(modType)
importedClass.app = app
except Exception as e:
print "Exception when loading "+modType, module, ":", e
traceback.print_exc()

# parse command line options
# Note: There should not be plugins and services with the same name
Expand Down
36 changes: 18 additions & 18 deletions plugin/pluginData.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@

class pluginData(plugin.PluginThread):
name = 'data'
options = [
{'start': ['launch at startup', 1]},
{'import.mode': ['Import data at launch', 'none', '<none|all>']},
{'import.from': ['Import data from', 'namecoin', '<namecoin|file>']},
{'import.file': ['Import data from file ', 'data' + os.sep + 'namecoin.dat']},
{'import.namecoin': ['Path of namecoin.conf', platformDep.getNamecoinDir() + os.sep + 'namecoin.conf']},

{'update.mode': ['Update mode', 'ondemand', '<none|all|ondemand>']},
{'update.from': ['Update data from', 'namecoin', '<namecoin|url|file>']},
{'update.freq': ['Update data if older than', '30m', '<number>[h|m|s]']},
{'update.file': ['Update data from file ', 'data' + os.sep + 'namecoin.dat']},
{'update.namecoin': ['Path of namecoin.conf', platformDep.getNamecoinDir() + os.sep + 'namecoin.conf']},

{'export.mode': ['Export mode', 'none', '<none|all>']},
{'export.to': ['Export data to', 'file']},
{'export.freq': ['Export data frequency', '1h', '<number>[h|m|s]']},
{'export.file': ['Export data to file ', 'data' + os.sep + 'namecoin.dat']},
]
options = {
'start': ['launch at startup', 1],
'import.mode': ['Import data at launch', 'none', '<none|all>'],
'import.from': ['Import data from', 'namecoin', '<namecoin|file>'],
'import.file': ['Import data from file ', 'data' + os.sep + 'namecoin.dat'],
'import.namecoin': ['Path of namecoin.conf', platformDep.getNamecoinDir() + os.sep + 'namecoin.conf'],

'update.mode': ['Update mode', 'ondemand', '<none|all|ondemand>'],
'update.from': ['Update data from', 'namecoin', '<namecoin|url|file>'],
'update.freq': ['Update data if older than', '30m', '<number>[h|m|s]'],
'update.file': ['Update data from file ', 'data' + os.sep + 'namecoin.dat'],
'update.namecoin': ['Path of namecoin.conf', platformDep.getNamecoinDir() + os.sep + 'namecoin.conf'],

'export.mode': ['Export mode', 'none', '<none|all>'],
'export.to': ['Export data to', 'file'],
'export.freq': ['Export data frequency', '1h', '<number>[h|m|s]'],
'export.file': ['Export data to file ', 'data' + os.sep + 'namecoin.dat'],
}
helps = {
'getData': [1, 1, '<name>', 'Get raw data of a name'],
'getValue': [1, 1, '<name>', 'Get raw value of a name'],
Expand Down