]> git.ipfire.org Git - ipfire.org.git/blob - src/scripts/ipfire.org.in
Merge branch 'community'
[ipfire.org.git] / src / scripts / ipfire.org.in
1 #!@PYTHON@
2
3 import sys
4 import tornado.ioloop
5 import tornado.options
6
7 import ipfire
8
9 class TaskRunner(object):
10 def __init__(self, *args, **kwargs):
11 self.backend = ipfire.Backend(*args, **kwargs)
12
13 # Create an IOLoop
14 self.ioloop = tornado.ioloop.IOLoop.current()
15
16 def run_task(self, name, *args, **kwargs):
17 """
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
21 """
22 async def task():
23 await self.backend.run_task(name, *args, **kwargs)
24
25 return self.ioloop.run_sync(task)
26
27
28 def main():
29 z = TaskRunner("@configsdir@/@PACKAGE_NAME@.conf")
30
31 if len(sys.argv) < 2:
32 sys.stderr.write("Argument needed\n")
33 sys.exit(1)
34
35 # Parse command line arguments
36 args = tornado.options.parse_command_line()
37
38 # Run the task
39 z.run_task(*args)
40
41 main()