7 from util.ProcessLogger import ProcessLogger |
7 from util.ProcessLogger import ProcessLogger |
8 from util.paths import Bpath |
8 from util.paths import Bpath |
9 |
9 |
10 class LocalRuntimeMixin(): |
10 class LocalRuntimeMixin(): |
11 |
11 |
12 def __init__(self, log): |
12 def __init__(self, log, use_gui=True): |
13 self.local_runtime_log = log |
13 self.local_runtime_log = log |
14 self.local_runtime = None |
14 self.local_runtime = None |
15 self.runtime_port = None |
15 self.runtime_port = None |
16 self.local_runtime_tmpdir = None |
16 self.local_runtime_tmpdir = None |
|
17 self.use_gui = use_gui |
17 |
18 |
18 def StartLocalRuntime(self, taskbaricon=True): |
19 def StartLocalRuntime(self): |
19 if (self.local_runtime is None) or (self.local_runtime.exitcode is not None): |
20 if (self.local_runtime is None) or (self.local_runtime.exitcode is not None): |
20 # create temporary directory for runtime working directory |
21 # create temporary directory for runtime working directory |
21 self.local_runtime_tmpdir = tempfile.mkdtemp() |
22 self.local_runtime_tmpdir = tempfile.mkdtemp() |
22 # choose an arbitrary random port for runtime |
23 # choose an arbitrary random port for runtime |
23 self.runtime_port = int(random.random() * 1000) + 61131 |
24 self.runtime_port = int(random.random() * 1000) + 61131 |
27 self.local_runtime_log, |
28 self.local_runtime_log, |
28 "\"%s\" \"%s\" -p %s -i localhost %s %s" % ( |
29 "\"%s\" \"%s\" -p %s -i localhost %s %s" % ( |
29 sys.executable, |
30 sys.executable, |
30 Bpath("Beremiz_service.py"), |
31 Bpath("Beremiz_service.py"), |
31 self.runtime_port, |
32 self.runtime_port, |
32 {False: "-x 0", True: "-x 1"}[taskbaricon], |
33 {False: "-x 0", True: "-x 1"}[self.use_gui], |
33 self.local_runtime_tmpdir), |
34 self.local_runtime_tmpdir), |
34 no_gui=False, |
35 no_gui=False, |
35 timeout=500, keyword=self.local_runtime_tmpdir, |
36 timeout=500, keyword=self.local_runtime_tmpdir, |
36 cwd=self.local_runtime_tmpdir) |
37 cwd=self.local_runtime_tmpdir) |
37 self.local_runtime.spin() |
38 self.local_runtime.spin() |