Run AVR firmware in avr8js Docker container
| 19 | |
| 20 | |
| 21 | class DockerAVR8jsRunner: |
| 22 | """Run AVR firmware in avr8js Docker container""" |
| 23 | |
| 24 | def __init__( |
| 25 | self, |
| 26 | docker_image: str = "niteris/fastled-avr8js:latest", |
| 27 | ): |
| 28 | self.docker_image = docker_image |
| 29 | |
| 30 | def _convert_to_docker_volume_path(self, path: Path) -> str: |
| 31 | """ |
| 32 | Convert Windows path to Docker-compatible volume mount path. |
| 33 | |
| 34 | Windows: C:\\Users\\... -> /c/Users/... |
| 35 | Unix: /home/... -> /home/... |
| 36 | """ |
| 37 | if platform.system() == "Windows": |
| 38 | # Convert Windows path to MSYS2/Docker format |
| 39 | # C:\Users\... -> /c/Users/... |
| 40 | path_str = str(path).replace("\\", "/") |
| 41 | if len(path_str) >= 2 and path_str[1] == ":": |
| 42 | drive = path_str[0].lower() |
| 43 | rest = path_str[2:] |
| 44 | return f"/{drive}{rest}" |
| 45 | return path_str |
| 46 | else: |
| 47 | return str(path) |
| 48 | |
| 49 | def check_docker_available(self) -> bool: |
| 50 | """Check if Docker is available and running""" |
| 51 | try: |
| 52 | result = RunningProcess.run( |
| 53 | ["docker", "version"], cwd=None, check=False, timeout=5 |
| 54 | ) |
| 55 | return result.returncode == 0 |
| 56 | except (RuntimeError, FileNotFoundError): |
| 57 | return False |
| 58 | |
| 59 | def check_image_exists(self, image_name: str) -> bool: |
| 60 | """Check if Docker image exists locally""" |
| 61 | try: |
| 62 | result = RunningProcess.run( |
| 63 | ["docker", "images", "-q", image_name], |
| 64 | check=False, |
| 65 | timeout=10, |
| 66 | capture_output=True, |
| 67 | text=True, |
| 68 | ) |
| 69 | return bool(result.stdout.strip()) |
| 70 | except (RuntimeError, FileNotFoundError): |
| 71 | return False |
| 72 | |
| 73 | def pull_image(self) -> None: |
| 74 | """Pull Docker image from registry""" |
| 75 | subprocess.run(["docker", "pull", self.docker_image], check=True) |
| 76 | |
| 77 | def run( |
| 78 | self, |
no outgoing calls
no test coverage detected