Skip to content

Commit

Permalink
Check kicad-cli before run
Browse files Browse the repository at this point in the history
  • Loading branch information
IoannisP-ITENG committed Jul 5, 2024
1 parent 7b4ef8a commit 55d5ec4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/kicadcliwrapper/generated/kicad_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from subprocess import check_output

from kicadcliwrapper.generated.kicad_cli_l2 import kicad_cli_l2
from kicadcliwrapper.lib import make_command
from kicadcliwrapper.lib import run_command


@dataclass
Expand Down Expand Up @@ -950,4 +950,4 @@ class version:
help: bool = False

def exec(self):
return check_output(make_command(kicad_cli_l2, self))
return run_command(kicad_cli_l2, self)
16 changes: 16 additions & 0 deletions src/kicadcliwrapper/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
# SPDX-License-Identifier: MIT


import logging
import re
import subprocess
from dataclasses import dataclass
from subprocess import check_output

logger = logging.getLogger(__name__)


class ParserL1:
Expand Down Expand Up @@ -85,3 +90,14 @@ def make_command(l2_root: ParserL2.Command, cmd) -> list[str]:
out.extend(sub)

return out


def run_command(l2_root: ParserL2.Command, cmd) -> str:
try:
version = check_output(["kicad-cli", "--version"]).decode("utf-8")
except subprocess.CalledProcessError:
raise Exception("kicad-cli is not installed")

logger.debug(f"Found kicad-cli version: {version}")

return check_output(make_command(l2_root, cmd)).decode("utf-8")
5 changes: 2 additions & 3 deletions src/kicadcliwrapper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ def main(out_dir: Path = Path(__file__).parent / Path("generated")):
+ "from subprocess import check_output\n"
+ "\n"
+ "from kicadcliwrapper.generated.kicad_cli_l2 import kicad_cli_l2\n"
+ "from kicadcliwrapper.lib import make_command\n"
+ "from kicadcliwrapper.lib import run_command\n"
)
trailer_l3 = (
" def exec(self):\n"
+ " return check_output(make_command(kicad_cli_l2, self))\n"
" def exec(self):\n" + " return run_command(kicad_cli_l2, self)\n"
)
out.write_text(
black.format_str(
Expand Down

0 comments on commit 55d5ec4

Please sign in to comment.