1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>'
19
20 from elisa.base_components.action import Action
21
22 from twisted.internet import defer, protocol, reactor
23
24 import os
25
36
37
39 """
40 This Action starts and spawns a process
41
42 @ivar executable: the executable
43 @type executable: unicode
44 @ivar running: is the program running?
45 @type running: bool
46 @ivar args: the arguments to start the process with
47 @type args: tuple
48 @ivar deferred: the deferred that will be called after the process
49 endet
50 """
51
59
62
64 if not self._running:
65 self._exec = exec_string
66
67
70
72 if not self._running:
73 self._path = path
74
75
78
80 if not self._running:
81 self._args = args
82
83
86
89
91
92 exc = self._exec
93
94 args = []
95
96 if ' ' in exc:
97 args = exc.split(' ')
98 exc = args[0]
99 else:
100 args.append(exc)
101
102 if exc[0] != '/':
103 pathes = os.environ.get('PATH')
104 for path in pathes.split(':'):
105 test_path = "%s/%s" % (path, exc)
106 if os.path.exists(test_path):
107 exc = test_path
108 break
109
110 path = self._path
111
112 self._protocol.reset()
113 process = reactor.spawnProcess(self._protocol,
114 exc,
115 path=path,
116 args=args,
117 env=None)
118 self._pid = process.pid
119 self.debug('called %s. Pid:%s' % (exc, self._pid))
120