Skip to content

Commit 590c6b2

Browse files
committed
changed directory management
1 parent 93980c6 commit 590c6b2

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
run={
2-
"hello_world":{}
2+
"hello_world":{"directory":"hello_world", "restart":True}
33
}

manager.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@
66
#
77
import logging as log
88
from importlib import import_module
9-
import services
109
import config
1110

12-
1311
LOG_FILENAME = 'python_manager.log'
14-
dynamic_imports = []
1512
worker = Worker()
1613

1714
def __init__():
1815
i = 0
1916
global dynamic_imports
2017
log.basicConfig(filename=LOG_FILENAME,level=log.DEBUG)
21-
for service in config.run.keys():
22-
dynamic_imports.append(import_module('services.%s' %service))
2318
for service_name in config.run.keys():
24-
worker.add(Service(service_name, i))
19+
worker.add(Service(service_name, config.run[service_name]['directory'], i))
2520
i += 1
2621

2722
def handle_input(command):

modules/service.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import services
1+
from importlib import import_module
2+
import run
23

34
class Service():
4-
def __init__(self, name, id):
5+
def __init__(self, name, directory, id):
56
self.name = name
7+
self.directory = directory
68
self.id = id
79

810
def run(self):
911
self.start()
1012

1113
def start(self):
12-
eval("services.%s.main()" %self.name)
14+
import_module("run.%s.%s" %(self.directory, self.name))
15+
command = "run.%s.%s.main()" %(self.directory, self.name)
16+
eval(command)
1317

modules/worker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from threading import Thread
2-
import services
32

43
class Worker():
54
def __init__(self):

run/hello_world/hello_world.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/python
2+
3+
def main(args=None):
4+
print("hello world")
5+
return 0
6+
7+
if __name__ == "__main__":
8+
main()

0 commit comments

Comments
 (0)