-
Notifications
You must be signed in to change notification settings - Fork 13
Adding Arch pakage manager support #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||||||||||||||||||
| from higher-level Python code. | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import shutil | ||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||
| import time | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -99,13 +100,37 @@ def get_can_adapter_serial(can_port: str) -> str | None: | |||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def _check_dependencies() -> None: | ||||||||||||||||||||||
| # Detect package manager | ||||||||||||||||||||||
| def _pacman_query(pkg: str) -> list[str]: | ||||||||||||||||||||||
| return ["pacman", "-Q", pkg] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def _dpkg_query(pkg: str) -> list[str]: | ||||||||||||||||||||||
| return ["dpkg", "-s", pkg] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if shutil.which("pacman"): | ||||||||||||||||||||||
| query_cmd = _pacman_query | ||||||||||||||||||||||
| install_cmd = "sudo pacman -S" | ||||||||||||||||||||||
| elif shutil.which("dpkg"): | ||||||||||||||||||||||
| query_cmd = _dpkg_query | ||||||||||||||||||||||
| install_cmd = "sudo apt install" | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| raise RuntimeError( | ||||||||||||||||||||||
| "Unsupported package manager. " | ||||||||||||||||||||||
| "Please ensure ethtool and can-utils are installed manually." | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| for pkg in ["ethtool", "can-utils"]: | ||||||||||||||||||||||
| try: | ||||||||||||||||||||||
| subprocess.run(["dpkg", "-s", pkg], check=True, stdout=subprocess.DEVNULL) | ||||||||||||||||||||||
| subprocess.run( | ||||||||||||||||||||||
| query_cmd(pkg), | ||||||||||||||||||||||
| check=True, | ||||||||||||||||||||||
| stdout=subprocess.DEVNULL, | ||||||||||||||||||||||
| stderr=subprocess.DEVNULL, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| except subprocess.CalledProcessError as exc: | ||||||||||||||||||||||
| raise RuntimeError( | ||||||||||||||||||||||
| f"Missing dependency: {pkg}. Please install with `sudo apt install " | ||||||||||||||||||||||
| f"{pkg}`." | ||||||||||||||||||||||
| f"Missing dependency: {pkg}. \ | ||||||||||||||||||||||
| Please install with `{install_cmd} {pkg}`." | ||||||||||||||||||||||
| ) from exc | ||||||||||||||||||||||
|
Comment on lines
131
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileNotFoundErrorfromsubprocess.runsubprocess.run()raisesFileNotFoundError(a subclass ofOSError, notCalledProcessError) when the executable itself cannot be found — e.g. ifpacmanordpkgdisappears between theshutil.which()call and thesubprocess.run()call, or ifPATHis altered by the time the process is spawned. This exception is not caught by the currentexcept subprocess.CalledProcessErrorhandler and will propagate as an unhandled error with a confusing message unrelated to the missing dependency.