Skip to content

Commit

Permalink
[clean] Shared 'utils.py'
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Nov 20, 2023
1 parent 827d270 commit a68781c
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 73 deletions.
2 changes: 1 addition & 1 deletion scripts/build_and_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from build_and_test.test_app import test_all_devices
from build_and_test.scan_app import scan_all_devices
from build_and_test.device import Devices
from build_and_test.utils import git_setup, merge_json
from utils import git_setup, merge_json

SDK_NAME = "sdk"
SDK_URL = "https://github.com/LedgerHQ/ledger-secure-sdk.git"
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_and_test/build_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

from build_and_test.device import Devices, Device
from build_and_test.utils import run_cmd
from utils import run_cmd


def build_variant(target: str,
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_and_test/scan_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from build_and_test.device import Devices, Device
from build_and_test.utils import run_cmd
from utils import run_cmd


def scan_variant(target: str,
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_and_test/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from build_and_test.device import Devices, Device
from build_and_test.build_app import build_variant
from build_and_test.utils import run_cmd
from utils import run_cmd


def test(model: str, app_test_path: Path, app_build_path: Path, test_params: str) -> Tuple[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion scripts/create_app_list/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from create_app_list.parse_github import parse_github
from create_app_list.gen_variant import gen_variant
from create_app_list.utils import git_setup, merge_json
from utils import git_setup, merge_json


def main(args: Namespace) -> None:
Expand Down
4 changes: 2 additions & 2 deletions scripts/create_app_list/makefile_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from pathlib import Path
from typing import Tuple, List

from create_app_list.utils import run_cmd
from utils import run_cmd


def get_app_listvariants(app_build_path: Path,
sdk: str = "$NANOS_SDK",
allow_failure: bool = False) -> Tuple[str, List[str]]:
# Using listvariants Makefile target
listvariants = run_cmd(f"make BOLOS_SDK={sdk} listvariants", cwd=app_build_path, no_throw=allow_failure)
_, listvariants = run_cmd(f"make BOLOS_SDK={sdk} listvariants", cwd=app_build_path, no_throw=allow_failure)
if "VARIANTS" not in listvariants:
raise ValueError(f"Invalid variants retrieved: {listvariants}")

Expand Down
53 changes: 0 additions & 53 deletions scripts/create_app_list/utils.py

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from argparse import ArgumentParser, Namespace
from pathlib import Path

sys.path.insert(1, Path(__file__).resolve().parent)
sys.path.insert(1, str(Path(__file__).resolve().parent))


def parse_args() -> Namespace:
Expand Down Expand Up @@ -33,7 +33,7 @@ def parse_args() -> Namespace:
subparser.add_argument("--input_file", required=False, type=Path, default=Path("input_files/test_input.json"))
subparser.add_argument("--output_file", required=False, type=Path, default=Path("output_files/output.json"))
subparser.add_argument("--logs_file", required=False, type=Path,
default=Path("output_files/error_logs.txt"))
default=Path("output_files/error_logs.txt"))
subparser.add_argument("--workdir", required=False, type=str, default="workdir")

subparser.add_argument("--use_sha1_from_live", required=False, action='store_true')
Expand Down
20 changes: 9 additions & 11 deletions scripts/build_and_test/utils.py → scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,31 @@ def run_cmd(cmd: str,
cwd: Path,
print_output: bool = True,
no_throw: bool = False) -> Tuple[int, str]:
error_log = ""
stdout = ""
print(f"[run_cmd] Running: {cmd} from {cwd}")

ret = subprocess.run(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
cwd=cwd)
if no_throw is False and ret.returncode:
print(f"[run_cmd] Error {ret.returncode} raised while running cmd: {cmd}")
print("[run_cmd] Output was:")
print(ret.stdout)
raise ValueError()
cwd=cwd,
check=not no_throw)

if ret.returncode:
print(f"[run_cmd] Output:\n{ret.stdout}")

error_log = f'''
stdout = f'''
###############################################################################
[run_cmd] Running: {cmd} from {cwd}"
###############################################################################
''' + ret.stdout
return ret.returncode, error_log
else:
stdout = ret.stdout.strip()

return ret.returncode, stdout


def git_setup(repo_name: str, repo_ref: str, repo_url: str, workdir: Path):
def git_setup(repo_name: str, repo_ref: str, repo_url: str, workdir: Path) -> None:
# Force clone in https over SSH
GIT_CONFIG = ' -c url."https://github.com/".insteadOf="[email protected]:" -c url."https://".insteadOf="git://"'

Expand Down

0 comments on commit a68781c

Please sign in to comment.