|
35 | 35 | from ..statistics import WithSamples
|
36 | 36 |
|
37 | 37 |
|
| 38 | +def expand_user(possible_path, shell_escape): |
| 39 | + something_changed = False |
| 40 | + |
| 41 | + # split will change the type of quotes, which may cause issues with shell variables |
| 42 | + parts = shlex.split(possible_path) |
| 43 | + for i, part in enumerate(parts): |
| 44 | + expanded = os.path.expanduser(part) |
| 45 | + if "~" in expanded and ":" in expanded: |
| 46 | + path_list = expanded.split(":") |
| 47 | + expanded = ":".join([os.path.expanduser(p) for p in path_list]) |
| 48 | + if parts[i] != expanded: |
| 49 | + something_changed = True |
| 50 | + parts[i] = expanded |
| 51 | + |
| 52 | + if something_changed: |
| 53 | + if shell_escape: |
| 54 | + return shlex.join(parts) |
| 55 | + return ' '.join(parts) |
| 56 | + |
| 57 | + return possible_path |
| 58 | + |
| 59 | + |
38 | 60 | class RunId(object):
|
39 | 61 | """
|
40 | 62 | A RunId is a concrete instantiation of the possible combinations of
|
@@ -111,7 +133,7 @@ def env(self):
|
111 | 133 |
|
112 | 134 | self._expandend_env = self.benchmark.run_details.env
|
113 | 135 | for key, value in self._expandend_env.items():
|
114 |
| - self._expandend_env[key] = self._expand_user(value) |
| 136 | + self._expandend_env[key] = expand_user(value, False) |
115 | 137 | return self._expandend_env
|
116 | 138 |
|
117 | 139 | @property
|
@@ -312,27 +334,10 @@ def cmdline(self):
|
312 | 334 | return self._cmdline
|
313 | 335 | return self._construct_cmdline()
|
314 | 336 |
|
315 |
| - def _expand_user(self, possible_path): |
316 |
| - something_changed = False |
317 |
| - |
318 |
| - # split will change the type of quotes, which may cause issues with shell variables |
319 |
| - parts = shlex.split(possible_path) |
320 |
| - for i, part in enumerate(parts): |
321 |
| - expanded = os.path.expanduser(part) |
322 |
| - if "~" in expanded and ":" in expanded: |
323 |
| - path_list = expanded.split(":") |
324 |
| - expanded = ":".join([os.path.expanduser(p) for p in path_list]) |
325 |
| - if parts[i] != expanded: |
326 |
| - something_changed = True |
327 |
| - parts[i] = expanded |
328 |
| - if something_changed: |
329 |
| - return shlex.join(parts) |
330 |
| - return possible_path |
331 |
| - |
332 | 337 | def cmdline_for_next_invocation(self):
|
333 | 338 | """Replace the invocation number in the command line"""
|
334 | 339 | cmdline = self.cmdline() % {"invocation": self.completed_invocations + 1}
|
335 |
| - cmdline = self._expand_user(cmdline) |
| 340 | + cmdline = expand_user(cmdline, True) |
336 | 341 | return cmdline
|
337 | 342 |
|
338 | 343 | def _construct_cmdline(self):
|
|
0 commit comments