Skip to content

Commit

Permalink
Merge pull request #11 from YunoHost/actions/black
Browse files Browse the repository at this point in the history
Format Python code with Black
  • Loading branch information
alexAubin authored Nov 5, 2024
2 parents 28a0972 + 5f5864c commit 5d0fd2e
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ def _run(self, *args: str, **kwargs) -> str:
def _run_logged_prefixed(self, *args: str, prefix: str = "", **kwargs) -> None:
command = ["incus"] + [*args]

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs)
process = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs
)
assert process.stdout
with process.stdout:
for line in iter(process.stdout.readline, b''): # b'\n'-separated lines
for line in iter(process.stdout.readline, b""): # b'\n'-separated lines
logging.debug("%s%s", prefix, line.decode("utf-8").rstrip("\n"))
exitcode = process.wait() # 0 means success
exitcode = process.wait() # 0 means success
if exitcode:
raise RuntimeError(f"Could not run {' '.join(command)}")

Expand Down Expand Up @@ -72,15 +74,19 @@ def push_file(self, instance_name: str, file: Path, target: str) -> None:
os.sync()

def execute(self, instance_name: str, *args: str) -> None:
self._run_logged_prefixed("exec", instance_name, "--", *args, prefix=" In container |\t")
self._run_logged_prefixed(
"exec", instance_name, "--", *args, prefix=" In container |\t"
)

def publish(
self, instance_name: str, image_alias: str, properties: dict[str, str]
) -> None:
properties_list = [f"{key}={value}" for key, value in properties.items()]
self._run("publish", instance_name, "--alias", image_alias, *properties_list)

def image_export(self, image_alias: str, image_target: str, target_dir: Path) -> None:
def image_export(
self, image_alias: str, image_target: str, target_dir: Path
) -> None:
self._run("image", "export", image_alias, image_target, cwd=target_dir)

def image_exists(self, alias: str) -> bool:
Expand All @@ -96,7 +102,9 @@ def image_delete(self, alias: str) -> None:


class ImageBuilder:
def __init__(self, debian_version: str, distribution: str, ss_repo: Path, log: Optional[Path]) -> None:
def __init__(
self, debian_version: str, distribution: str, ss_repo: Path, log: Optional[Path]
) -> None:
self.debian_version = debian_version
self.distribution = distribution
self.instance_name = f"ynh-builder-{self.debian_version}-{self.distribution}"
Expand Down Expand Up @@ -187,7 +195,7 @@ def run_script(self, name: str) -> None:
f"DEBIAN_VERSION={self.debian_version}",
f"gitbranch={gitbranch}",
"/root/recipes",
name
name,
]
logging.info("Running: %s...", " ".join(command))
incus.execute(self.instance_name, *command)
Expand All @@ -209,15 +217,17 @@ def main():
"--log",
type=Path,
required=False,
help="If passed, logs will be printed to this file"
help="If passed, logs will be printed to this file",
)

parser.add_argument("debian_version", type=str, choices=["bullseye", "bookworm"])
parser.add_argument(
"distribution", type=str, choices=["stable", "testing", "unstable"]
)
parser.add_argument(
"variants", type=str, choices=["build-and-lint", "before-install", "appci-only", "all"]
"variants",
type=str,
choices=["build-and-lint", "before-install", "appci-only", "all"],
)
args = parser.parse_args()

Expand All @@ -235,7 +245,9 @@ def main():

logging.debug("Starting at %s", datetime.now())

builder = ImageBuilder(args.debian_version, args.distribution, args.output, args.log)
builder = ImageBuilder(
args.debian_version, args.distribution, args.output, args.log
)

if args.variants == "build-and-lint":
builder.start()
Expand Down

0 comments on commit 5d0fd2e

Please sign in to comment.