From 4d636386bf1368b8c227293b5886487f219fe7bc Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 9 Nov 2017 01:43:17 +0100 Subject: [PATCH] Doing things in a more sane way --- runbullet/__init__.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/runbullet/__init__.py b/runbullet/__init__.py index d5131d1b..f17a5df3 100644 --- a/runbullet/__init__.py +++ b/runbullet/__init__.py @@ -69,22 +69,23 @@ def _init_plugin(plugin_name, reload=False): return plugin -def _exec_func(body, retry=True): - args = {} +def _exec_func(args, retry=True): + args = json.loads(args) \ + if isinstance(args, str) \ + else args - if 'action' not in body: + if 'action' not in args: logging.warn('No action specified') return - action = body.pop('action') + if 'target' in args: + args.pop('target') + + action = args.pop('action') tokens = action.split('.') module_name = str.join('.', tokens[:-1]) method_name = tokens[-1:][0] - args = json.loads(body) \ - if isinstance(body, str) \ - else body - try: plugin = _init_plugin(module_name) except RuntimeError as e: # Module/class not found @@ -110,11 +111,11 @@ def _exec_func(body, retry=True): logging.exception(e) if retry: # Put the action back where it was before retrying - body['action'] = action + args['action'] = action logging.info('Reloading plugin {} and retrying'.format(module_name)) _init_plugin(module_name, reload=True) - _exec_func(body, retry=False) + _exec_func(args, retry=False) def _on_push(ws, data):