]>
Commit | Line | Data |
---|---|---|
d6df53bf | 1 | #!@PYTHON@ |
940227cb | 2 | |
c5ddbd67 | 3 | import sys |
940227cb | 4 | import tornado.ioloop |
a2e77efa | 5 | import tornado.options |
940227cb | 6 | |
c5ddbd67 | 7 | import ipfire |
940227cb | 8 | |
c5ddbd67 MT |
9 | class TaskRunner(object): |
10 | def __init__(self, *args, **kwargs): | |
11 | self.backend = ipfire.Backend(*args, **kwargs) | |
940227cb | 12 | |
c5ddbd67 MT |
13 | # Create an IOLoop |
14 | self.ioloop = tornado.ioloop.IOLoop.current() | |
9068dba1 | 15 | |
c5ddbd67 | 16 | def run_task(self, name, *args, **kwargs): |
940227cb | 17 | """ |
c5ddbd67 MT |
18 | This method runs the task with the given name and |
19 | arguments asynchronically and exits the program in | |
20 | case on a non-zero exit code | |
940227cb | 21 | """ |
9fdf4fb7 MT |
22 | async def task(): |
23 | await self.backend.run_task(name, *args, **kwargs) | |
940227cb | 24 | |
c5ddbd67 | 25 | return self.ioloop.run_sync(task) |
940227cb | 26 | |
3c4f2edc | 27 | |
c5ddbd67 MT |
28 | def main(): |
29 | z = TaskRunner("@configsdir@/@PACKAGE_NAME@.conf") | |
3c4f2edc | 30 | |
c5ddbd67 MT |
31 | if len(sys.argv) < 2: |
32 | sys.stderr.write("Argument needed\n") | |
33 | sys.exit(1) | |
3c4f2edc | 34 | |
a2e77efa MT |
35 | # Parse command line arguments |
36 | args = tornado.options.parse_command_line() | |
3c4f2edc | 37 | |
c5ddbd67 | 38 | # Run the task |
a2e77efa | 39 | z.run_task(*args) |
940227cb | 40 | |
c5ddbd67 | 41 | main() |