|
26 | 26 |
|
27 | 27 | class PsUtilProcessProxy: |
28 | 28 | def __init__(self, ssh, pid): |
| 29 | + assert isinstance(ssh, RemoteOperations) |
| 30 | + assert type(pid) == int # noqa: E721 |
29 | 31 | self.ssh = ssh |
30 | 32 | self.pid = pid |
31 | 33 |
|
32 | 34 | def kill(self): |
33 | | - command = "kill {}".format(self.pid) |
34 | | - self.ssh.exec_command(command) |
| 35 | + assert isinstance(self.ssh, RemoteOperations) |
| 36 | + assert type(self.pid) == int # noqa: E721 |
| 37 | + command = ["kill", str(self.pid)] |
| 38 | + self.ssh.exec_command(command, encoding=get_default_encoding()) |
35 | 39 |
|
36 | 40 | def cmdline(self): |
37 | | - command = "ps -p {} -o cmd --no-headers".format(self.pid) |
38 | | - stdin, stdout, stderr = self.ssh.exec_command(command, verbose=True, encoding=get_default_encoding()) |
39 | | - cmdline = stdout.strip() |
| 41 | + assert isinstance(self.ssh, RemoteOperations) |
| 42 | + assert type(self.pid) == int # noqa: E721 |
| 43 | + command = ["ps", "-p", str(self.pid), "-o", "cmd", "--no-headers"] |
| 44 | + output = self.ssh.exec_command(command, encoding=get_default_encoding()) |
| 45 | + assert type(output) == str # noqa: E721 |
| 46 | + cmdline = output.strip() |
| 47 | + # TODO: This code work wrong if command line contains quoted values. Yes? |
40 | 48 | return cmdline.split() |
41 | 49 |
|
42 | 50 |
|
|
0 commit comments