-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon.py
More file actions
35 lines (29 loc) · 1.02 KB
/
common.py
File metadata and controls
35 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Baseline Slicer repository, change this when rebasing
GIT_URL = "https://github.com/Slicer/Slicer.git"
GIT_REVISION = "55f38b57fc9d9a80da0fce51aa12d82064c101cc"
# Directories used by the scripts
SLICER_DIR = "Slicer"
PATCH_DIR = "patch"
import subprocess
import os
def execute_process(cmd: str, cwd: str = ".") -> str:
"""Run a shell command and return the process standard output as a str.
Throws an exception with subprocess stderr if return code is not zero.
"""
try:
result = subprocess.run(
cmd,
cwd=cwd,
shell=True,
capture_output=True,
text=True,
check=True
)
return result.stdout
except subprocess.CalledProcessError as e:
raise Exception(f"Error running command: {cmd}\nError message:\n{e.stderr}\n")
def mkpath(file_path: str) -> None:
"""Create the directories tree for given file path"""
directory = os.path.dirname(file_path)
if directory:
os.makedirs(directory, exist_ok=True)