-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from SmithChart/cfi/review-feedback
Quality improvements and best current practices
- Loading branch information
Showing
19 changed files
with
487 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import re | ||
|
||
import labgrid.protocol | ||
|
||
|
||
class SystemdRun: | ||
""" | ||
Wrapper around `systemd-run` to run a command in the background. | ||
This wrapper is intended to be used as context manager: | ||
> with SystemdRun(command="sleep 30", shell=shell): | ||
> pass | ||
The output of the command is not collected. | ||
Neither is the exit code. | ||
This is a workaround until something like https://github.com/labgrid-project/labgrid/pull/835 is merged. | ||
""" | ||
|
||
_re_run = re.compile(r"^Running as unit: (run-\w+\.service);") | ||
|
||
def __init__(self, command: str, shell: labgrid.protocol.ConsoleProtocol): | ||
""" | ||
Run `command` in a transient unit using `systemd-run`. | ||
""" | ||
self._command = command | ||
self._shell = shell | ||
self._unit = None | ||
|
||
def __enter__(self) -> None: | ||
stdout = self._shell.run_check(f"systemd-run {self._command}") | ||
match = SystemdRun._re_run.match("".join(stdout)) | ||
if not match: | ||
raise ValueError(f"systemd-run returned not parseable output: {stdout}") | ||
self._unit = match[1] | ||
|
||
def __exit__(self, _type, _value, _traceback): | ||
self._shell.run(f"systemctl stop {self._unit}") |
Oops, something went wrong.