diff options
author | Kevron Rees <tripzero.kev@gmail.com> | 2015-01-09 15:08:11 -0800 |
---|---|---|
committer | Kevron Rees <tripzero.kev@gmail.com> | 2015-01-09 15:08:11 -0800 |
commit | e323a2ef450740142d9c167f09bd171d6d27c355 (patch) | |
tree | 4a3aef350f73e8dbf708d32689b1a61dbfa55eae | |
parent | a4390c9b7f9677dde98fe101a16dce975b1f7565 (diff) | |
download | automotive-message-broker-e323a2ef450740142d9c167f09bd171d6d27c355.tar.gz |
[ambctl] - renamed enablePlugin command to 'plugin'. fixed truncate issues
-rw-r--r-- | plugins/examplesource.in.json | 8 | ||||
-rw-r--r-- | tools/ambctl.py | 74 |
2 files changed, 53 insertions, 29 deletions
diff --git a/plugins/examplesource.in.json b/plugins/examplesource.in.json index 5a9680ae..b221fbab 100644 --- a/plugins/examplesource.in.json +++ b/plugins/examplesource.in.json @@ -1,6 +1,6 @@ { - "name" : "ExampleSouce", - "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so", - "delay" : "6", - "enabled" : true + "name" : "ExampleSource", + "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so", + "delay" : "6", + "enabled" : true } diff --git a/tools/ambctl.py b/tools/ambctl.py index 0de96a17..0a84d26c 100644 --- a/tools/ambctl.py +++ b/tools/ambctl.py @@ -35,13 +35,13 @@ class Autocomplete: def __init__(self): self.commands = [] - self.commands.append(Autocomplete.Cmd('help', 'Prints help data')) + self.commands.append(Autocomplete.Cmd('help', 'Prints help data (also see COMMAND help)')) self.commands.append(Autocomplete.Cmd('list', 'List supported ObjectNames')) self.commands.append(Autocomplete.Cmd('get', 'Get properties from an ObjectName')) self.commands.append(Autocomplete.Cmd('listen', 'Listen for changes on an ObjectName')) self.commands.append(Autocomplete.Cmd('set', 'Set a property for an ObjectName')) self.commands.append(Autocomplete.Cmd('getHistory', 'Get logged data within a time range')) - self.commands.append(Autocomplete.Cmd('enablePlugin', 'Get logged data within a time range')) + self.commands.append(Autocomplete.Cmd('plugin', 'enable, disable and get info on a plugin')) self.commands.append(Autocomplete.Cmd('quit', 'Exit ambctl')) bus = dbus.SystemBus() @@ -91,35 +91,36 @@ def changed(interface, properties, invalidated): print json.dumps(properties, indent=2) def listPlugins(): - list = {} + list = [] for root, dirs, files in os.walk('@PLUGIN_SEGMENT_INSTALL_PATH@'): for file in files: fullpath = root + "/" + file; pluginFile = open(fullpath) data = json.load(pluginFile) + data['segmentPath'] = fullpath pluginFile.close() - list.update({data["name"]:fullpath}) - + list.append(data) return list def enablePlugin(pluginName, enabled): list = listPlugins() - if pluginName not in list: - return false - - path = list[pluginName] - try : - file = open(path, 'rw+') - data = json.load(file) - data["enabled"] = enabled; - fixedData = json.JSONEncoder().encode(data) - file.truncate(0) - file.write(fixedData) - file.close() - except IOError, error: - print error - except: - print "Unknown error" + + for plugin in list: + if plugin["name"] == pluginName: + try : + plugin["enabled"] = enabled + file = open(plugin["segmentPath"], 'rw+') + plugin.pop('segmentPath', None) + fixedData = json.dumps(plugin, separators=(', ', ' : '), indent=4) + file.truncate() + file.write(fixedData) + file.close() + return True + except IOError, error: + print error + return False + return False + def processCommand(command, commandArgs, noMain=True): @@ -222,20 +223,43 @@ def processCommand(command, commandArgs, noMain=True): object = managerInterface.FindObjectForZone(objectName, zone); propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", object),"org.automotive."+objectName) print json.dumps(propertiesInterface.GetHistory(start, end), indent=2) - elif command == "enablePlugin": + elif command == "plugin": if len(commandArgs) == 0: commandArgs = ['help'] if commandArgs[0] == 'help': print "[list] [pluginName] [on/off]" return 1 elif commandArgs[0] == 'list': - for name, path in listPlugins(): - print name + for plugin in listPlugins(): + print plugin['name'] return 1 + elif len(commandArgs) == 1: + for plugin in listPlugins(): + if plugin['name'] == commandArgs[0]: + print json.dumps(plugin, indent=4) + return 1 + else: + print "name: " + plugin['name'] + "==?" + commandArgs[0] + print "plugin not found: ", commandArgs[0] + return 0 else: if len(commandArgs) < 2: return 1 - enablePlugin(commandArgs[0], commandArgs[1] == "on") + enArg = commandArgs[1] + if not enArg == "on" and not enArg == "off": + print "please use 'on' or 'off' to enable/disable the plugin" + return 1 + plugin = commandArgs[0] + enabled = enArg == "on" + enStr = "disabled" + if enablePlugin(plugin, enabled): + if enabled: + enStr = "enabled" + else: + print "Error could not enable", plugin + + print plugin, enStr + return 1 else: |