-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmd_factory.py
More file actions
29 lines (24 loc) · 853 Bytes
/
cmd_factory.py
File metadata and controls
29 lines (24 loc) · 853 Bytes
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
import sys
from pathlib import Path
class CMDFactory:
@staticmethod
def make(base_params, params):
if sys.platform == "linux":
envkw = "export"
separator = ";"
encloser = "'"
elif sys.platform == "win32":
envkw = "set"
separator = "&"
encloser = ""
else:
raise ValueError(f"Unsupported platform: {sys.platform}")
set_env = (
lambda varname, var: f"{envkw} {varname}={encloser}{var}{encloser} {separator} "
)
working_dir = Path(__file__).parent
cmd = f'cd "{working_dir}" {separator} '
cmd += set_env("BASE_PARAMS", f"{base_params.json()}")
cmd += set_env("PARAMS", f"{params.json() if params is not None else {}}")
cmd += f"node ./build/imx.js"
return cmd