]>
Commit | Line | Data |
---|---|---|
c5ddbd67 | 1 | #!/usr/bin/python3 |
940227cb | 2 | |
c5ddbd67 MT |
3 | import sys |
4 | import tornado.gen | |
940227cb MT |
5 | import tornado.ioloop |
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 | """ |
c5ddbd67 MT |
22 | @tornado.gen.coroutine |
23 | def task(): | |
24 | yield self.backend.run_task(name, *args, **kwargs) | |
940227cb | 25 | |
c5ddbd67 | 26 | return self.ioloop.run_sync(task) |
940227cb | 27 | |
3c4f2edc | 28 | |
c5ddbd67 MT |
29 | def main(): |
30 | z = TaskRunner("@configsdir@/@PACKAGE_NAME@.conf") | |
3c4f2edc | 31 | |
c5ddbd67 MT |
32 | if len(sys.argv) < 2: |
33 | sys.stderr.write("Argument needed\n") | |
34 | sys.exit(1) | |
3c4f2edc | 35 | |
c5ddbd67 MT |
36 | basename = sys.argv[0] |
37 | task = sys.argv[1] | |
38 | args = sys.argv[2:] | |
3c4f2edc | 39 | |
c5ddbd67 MT |
40 | # Run the task |
41 | z.run_task(task, *args) | |
940227cb | 42 | |
c5ddbd67 | 43 | main() |