cmd.py part 3 refactor
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from clan_cli.cmd import run
|
||||
from clan_cli.dirs import machine_settings_file, nixpkgs_source, specific_machine_dir
|
||||
from clan_cli.errors import ClanError, ClanHttpError
|
||||
from clan_cli.git import commit_file
|
||||
@@ -60,11 +60,9 @@ def verify_machine_config(
|
||||
""",
|
||||
],
|
||||
)
|
||||
# repro_env_break(work_dir=flake, env=env, cmd=cmd)
|
||||
proc = subprocess.run(
|
||||
|
||||
proc = run(
|
||||
cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=flake,
|
||||
env=env,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import argparse
|
||||
import shlex
|
||||
import subprocess
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from ..cmd import run
|
||||
from ..dirs import specific_groot_dir
|
||||
from ..errors import ClanError
|
||||
from ..machines.list import list_machines
|
||||
@@ -26,18 +25,7 @@ class FlakeConfig:
|
||||
|
||||
|
||||
def run_cmd(cmd: list[str]) -> str:
|
||||
proc = subprocess.run(cmd, text=True, stdout=subprocess.PIPE)
|
||||
assert proc.stdout is not None
|
||||
if proc.returncode != 0:
|
||||
raise ClanError(
|
||||
f"""
|
||||
command: {shlex.join(cmd)}
|
||||
exit code: {proc.returncode}
|
||||
stdout:
|
||||
{proc.stdout}
|
||||
"""
|
||||
)
|
||||
|
||||
proc = run(cmd)
|
||||
return proc.stdout.strip()
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import shlex
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
# from clan_cli.dirs import find_git_repo_root
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.errors import ClanCmdError, ClanError
|
||||
from clan_cli.nix import nix_shell
|
||||
|
||||
from .cmd import run
|
||||
|
||||
|
||||
# generic vcs agnostic commit function
|
||||
def commit_file(
|
||||
@@ -43,10 +43,10 @@ def _commit_file_to_git(repo_dir: Path, file_path: Path, commit_message: str) ->
|
||||
)
|
||||
# add the file to the git index
|
||||
try:
|
||||
subprocess.run(cmd, check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
run(cmd)
|
||||
except ClanCmdError as e:
|
||||
raise ClanError(
|
||||
f"Failed to add {file_path} to git repository {repo_dir}:\n{shlex.join(cmd)}\n exited with {e.returncode}"
|
||||
f"Failed to add {file_path} to git repository {repo_dir}:\n{e.cmd.command}\n exited with {e.cmd.returncode}"
|
||||
) from e
|
||||
|
||||
# check if there is a diff
|
||||
@@ -54,7 +54,7 @@ def _commit_file_to_git(repo_dir: Path, file_path: Path, commit_message: str) ->
|
||||
["nixpkgs#git"],
|
||||
["git", "-C", str(repo_dir), "diff", "--cached", "--exit-code", str(file_path)],
|
||||
)
|
||||
result = subprocess.run(cmd, cwd=repo_dir)
|
||||
result = run(cmd, cwd=repo_dir)
|
||||
# if there is no diff, return
|
||||
if result.returncode == 0:
|
||||
return
|
||||
@@ -73,11 +73,10 @@ def _commit_file_to_git(repo_dir: Path, file_path: Path, commit_message: str) ->
|
||||
],
|
||||
)
|
||||
try:
|
||||
subprocess.run(
|
||||
run(
|
||||
cmd,
|
||||
check=True,
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
except ClanCmdError as e:
|
||||
raise ClanError(
|
||||
f"Failed to commit {file_path} to git repository {repo_dir}:\n{shlex.join(cmd)}\n exited with {e.returncode}"
|
||||
f"Failed to commit {file_path} to git repository {repo_dir}:\n{e.cmd.command}\n exited with {e.cmd.returncode}"
|
||||
) from e
|
||||
|
||||
Reference in New Issue
Block a user