Skip to content

Commit ab0250e

Browse files
committed
cli: Refactor cloe_utils into binutils and procutils
1 parent 479e618 commit ab0250e

File tree

4 files changed

+328
-314
lines changed

4 files changed

+328
-314
lines changed

cli/cloe_launch/__main__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
remove this script.
88
99
Commands:
10-
exec Run cloe-engine with the given arguments.
11-
show Show default/specified profile.
12-
list List the currently available profiles.
13-
add Add a profile with the given name.
14-
edit Edit the default/specified profile with $EDITOR.
15-
remove Remove the specified profile.
16-
default Get or set the default profile.
10+
activate Launch shell with the correct environment from a profile.
11+
clean Clean launcher profile cache.
12+
deploy Deploy environment for selected profile.
13+
exec Launch cloe-engine with a profile.
14+
prepare Prepare environment for selected profile.
15+
profile Manage launcher profiles.
16+
shell Launch shell with the correct environment from a profile.
1717
1818
"""
1919

cli/cloe_launch/utility.py renamed to cli/cloe_launch/binutils.py

+4-28
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,9 @@
33
import platform
44

55
from pathlib import Path
6-
from typing import Dict, List, Optional
6+
from typing import List, Optional
77

8-
9-
def run_cmd(
10-
cmd: List[str],
11-
env: Optional[Dict[str, str]] = None,
12-
must_succeed: bool = True,
13-
capture_output: bool = True,
14-
) -> subprocess.CompletedProcess:
15-
"""Run a command quietly, only printing stderr if the command fails."""
16-
17-
logging.info(f"Exec: {' '.join(cmd)}")
18-
result = subprocess.run(
19-
cmd,
20-
check=False,
21-
stdout=subprocess.PIPE if capture_output else None,
22-
stderr=subprocess.STDOUT if capture_output else None,
23-
universal_newlines=True,
24-
env=env,
25-
)
26-
if result.returncode != 0:
27-
logging.error(f"Error running: {' '.join(cmd)}")
28-
if result.stdout is not None:
29-
logging.error(result.stdout)
30-
if must_succeed:
31-
raise ChildProcessError()
32-
return result
8+
from cloe_launch import procutils
339

3410

3511
def patch_rpath(file: Path, rpath: List[str]) -> Optional[subprocess.CompletedProcess]:
@@ -58,14 +34,14 @@ def patch_rpath(file: Path, rpath: List[str]) -> Optional[subprocess.CompletedPr
5834
file_arg = str(file)
5935
rpath_arg = ":".join(rpath)
6036
logging.debug(f"Setting RPATH: {file_arg} -> {rpath_arg}")
61-
return run_cmd(["patchelf", "--set-rpath", rpath_arg, file_arg], must_succeed=False)
37+
return procutils.system(["patchelf", "--set-rpath", rpath_arg, file_arg], must_succeed=False)
6238

6339

6440
def find_binary_files(cwd: Optional[Path] = None) -> List[Path]:
6541
"""Return a list of all file paths that are of the binary type."""
6642
assert platform.system() != "Windows"
6743
result = subprocess.run(
68-
"""find -type f -exec sh -c "file -i '{}' | grep -q '; charset=binary'" \; -print""",
44+
"""find -type f -exec sh -c "file -i '{}' | grep -q '; charset=binary'" \\; -print""",
6945
shell=True,
7046
stdout=subprocess.PIPE,
7147
check=True,

0 commit comments

Comments
 (0)