|
1 | 1 | #!/bin/python
|
| 2 | +#local imports |
| 3 | +import modules.commands as commands |
| 4 | +from modules.worker import Worker |
| 5 | +from modules.service import Service |
| 6 | +# |
2 | 7 | import logging as log
|
3 | 8 | from importlib import import_module
|
4 | 9 | import services
|
5 | 10 | import config
|
6 | | -frommodules.workerimportWorker |
| 11 | + |
7 | 12 |
|
8 | 13 | LOG_FILENAME = 'python_manager.log'
|
9 | 14 | dynamic_imports = []
|
10 | 15 | worker = Worker()
|
11 | 16 |
|
12 | | -class Service(): |
13 | | - def __init__(self, name): |
14 | | - self.name = name |
15 | | - |
16 | 17 | def __init__():
|
| 18 | + i = 0 |
17 | 19 | global dynamic_imports
|
18 | 20 | log.basicConfig(filename=LOG_FILENAME,level=log.DEBUG)
|
19 | 21 | for service in config.run.keys():
|
20 | | - dynamic_imports.append(import_module('services.%s' %service)) |
21 | | - |
| 22 | + dynamic_imports.append(import_module('services.%s' %service)) |
| 23 | + for service_name in config.run.keys(): |
| 24 | + worker.add(Service(service_name, i)) |
| 25 | + i += 1 |
| 26 | + |
| 27 | +def handle_input(command): |
| 28 | + command = command.strip() |
| 29 | + command = command.split(" ") |
| 30 | + if command[0] not in commands.commands: |
| 31 | + commands.help(worker, command) |
| 32 | + else: |
| 33 | + output = eval("commands.%s" %command[0])(worker, command) |
| 34 | + if output is not None: |
| 35 | + return False |
| 36 | + return True |
| 37 | + |
22 | 38 | def main():
|
23 | 39 | __init__()
|
24 | | - for service_name in config.run.keys(): |
25 | | - worker.add(Service(service_name)) |
26 | 40 | worker.start()
|
| 41 | + while handle_input(input()) is True: |
| 42 | + continue |
27 | 43 | log.info('All tasks done. Stopping')
|
28 | 44 | return 0
|
29 | 45 |
|
|
0 commit comments