From 91835996641765b56442b33c795e4e6418058bf8 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 11 Dec 2017 01:23:03 +0100 Subject: [PATCH] Supporting multiple backends on pusher script --- runbullet/bin/pusher | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/runbullet/bin/pusher b/runbullet/bin/pusher index 2eebb3cf..91bb64f8 100755 --- a/runbullet/bin/pusher +++ b/runbullet/bin/pusher @@ -15,6 +15,7 @@ from runbullet.backend.kafka import KafkaBackend def print_usage(): print ('''Usage: {} [-h|--help] <-t|--target > <-a|--action > payload -h, --help:\t\tShow this help and exit + -b, --backend:\tBackend to deliver the message [pushbullet|kafka] (default: whatever specified in your config with pusher=True) -t, --target:\tName of the target device/host -a, --action\tAction to run, it includes both the package name and the method (e.g. shell.exec or music.mpd.play) payload:\t\tArguments to the action @@ -63,6 +64,11 @@ def main(): parser.add_argument('--action', '-a', dest='action', required=True, help="Action to execute, as package.method") + parser.add_argument('--backend', '-b', dest='backend', required=False, + help="Backend to deliver the message " + + "[pushbullet|kafka] (default: whatever specified " + + "in your config with pusher=True)") + opts, args = parser.parse_known_args(sys.argv[1:]) payload = {} @@ -70,6 +76,18 @@ def main(): raise RuntimeError('Odd number of key-value options passed: {}'. format(args)) + if opts.backend: + backend_cfg_name = 'backend.' + opts.backend + if backend_cfg_name not in config: + raise RuntimeError('{} backend specified, but no configuration ' + + 'for it available'.format(backend_cfg_name)) + + cfg = config[backend_cfg_name] + cfg['pusher'] = True + config = { backend_cfg_name: cfg } + + backend = get_backend(config) + for i in range(0, len(args), 2): payload[re.sub('^-+', '', args[i])] = args[i+1] @@ -81,7 +99,6 @@ def main(): print('msg: {}'.format(msg)) - backend = get_backend(config) if isinstance(backend, Pushbullet): send_pb_message(backend, config['backend.pushbullet']['device'], msg) elif isinstance(backend, KafkaBackend):