Launch 'self.executable'. We assume it is in the system PATH.
(self)
| 100 | self.kill() |
| 101 | |
| 102 | def launch(self): |
| 103 | """ |
| 104 | Launch 'self.executable'. We assume it is in the system PATH. |
| 105 | """ |
| 106 | if self.proc is not None: |
| 107 | raise CLIException("{name} already launched" |
| 108 | .format(name=self.name.capitalize())) |
| 109 | |
| 110 | if not os.path.exists(self.executable): |
| 111 | raise CLIException("{name} executable not found" |
| 112 | .format(name=self.name.capitalize())) |
| 113 | |
| 114 | try: |
| 115 | flags = ["--{key}={value}".format(key=key, value=value) |
| 116 | for key, value in dict(self.flags).items()] |
| 117 | |
| 118 | if self.shell: |
| 119 | cmd = ["/bin/sh", self.executable] + flags |
| 120 | else: |
| 121 | cmd = [self.executable] + flags |
| 122 | |
| 123 | proc = subprocess.Popen( |
| 124 | cmd, |
| 125 | stdin=subprocess.PIPE, |
| 126 | stdout=subprocess.PIPE, |
| 127 | stderr=subprocess.STDOUT) |
| 128 | except Exception as exception: |
| 129 | raise CLIException("Failed to launch '{executable}': {error}" |
| 130 | .format(executable=self.executable, |
| 131 | error=exception)) |
| 132 | |
| 133 | if proc.poll(): |
| 134 | raise CLIException("Failed to launch '{executable}': {error}" |
| 135 | .format(executable=self.executable, |
| 136 | error=proc.stdout.read())) |
| 137 | |
| 138 | self.proc = proc |
| 139 | |
| 140 | def kill(self): |
| 141 | """ |
nothing calls this directly
no test coverage detected