Skip to content
Snippets Groups Projects
Commit 9c435011 authored by Hendrik Buschmeier's avatar Hendrik Buschmeier
Browse files

Enable ipaaca-iu-injector to send structured payload data.

parent e7cbd3f4
No related branches found
No related tags found
No related merge requests found
......@@ -60,6 +60,11 @@ parser.add_argument(
metavar='SECONDS',
type=float,
help='set time in seconds to wait for potential IU updates (default: 3.0)')
parser.add_argument(
'-j', '--json-payload',
dest='json_payload',
action='store_true',
help='allow structured data to be sent (treats payload VALUE arguments as Python expressions)'))
parser.add_argument(
'-c', '--category',
dest='category',
......@@ -81,22 +86,27 @@ if __name__ == '__main__':
ob = ipaaca.OutputBuffer('IpaacaIUInjector')
ob.register_handler(iu_update_handler)
iu = ipaaca.Message(arguments.category) if arguments.iu_type == 'Message' else ipaaca.IU(arguments.category)
iu.payload = {k: v for (k, v) in itertools.izip_longest(arguments.payload[::2], arguments.payload[1::2])}
if arguments.json_payload:
# Treat payload values as Python expressions
iu.payload = {k: eval(v) for (k, v) in itertools.izip_longest(arguments.payload[::2], arguments.payload[1::2])}
else:
iu.payload = {k: v for (k, v) in itertools.izip_longest(arguments.payload[::2], arguments.payload[1::2])}
ob.add(iu)
print(
'Sent {iu_type} with category "{category}" and payload {{'.format(**vars(arguments)),
end='\n' if len(iu.payload) > 0 else '')
for k, v in iu.payload.items():
print(' "{key}": "{value}",'.format(key=k, value=v))
print(" '{key}': {value},".format(key=k, value=v))
print('}.')
# Wait for updates to the IU
try:
if arguments.iu_type == 'IU':
print('Waiting %s s for the IU to be updated.' % arguments.keep_alive)
time.sleep(arguments.keep_alive)
else:
time.sleep(0.1)
except KeyboardInterrupt:
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment