Remove match statement to support more interpreters
This commit is contained in:
parent
0562772dc8
commit
24f0338897
1 changed files with 22 additions and 20 deletions
|
@ -17,11 +17,14 @@ if sys.version_info <= (3, 9, 0):
|
|||
Path.readlink = lambda p: Path(os.readlink(str(p)))
|
||||
|
||||
|
||||
def sh(global_config,
|
||||
cmd: List[str], /,
|
||||
env: Optional[dict] = None):
|
||||
|
||||
shell = (global_config or {}).get("cram", {}).get("task", {}).get("apply", {}).get("shell", SHELL)
|
||||
def sh(global_config, cmd: List[str], /, env: Optional[dict] = None):
|
||||
shell = (
|
||||
(global_config or {})
|
||||
.get("cram", {})
|
||||
.get("task", {})
|
||||
.get("apply", {})
|
||||
.get("shell", SHELL)
|
||||
)
|
||||
|
||||
prefix = []
|
||||
if env:
|
||||
|
@ -93,21 +96,20 @@ class Package(object):
|
|||
def expandvars(s: str) -> str:
|
||||
def _repl(m: re.Match) -> str:
|
||||
var = m.group(0).lower()
|
||||
match var:
|
||||
case "${hostname}":
|
||||
return os.uname()[1].split(".")[0]
|
||||
case "${fqdn}":
|
||||
return os.uname()[1]
|
||||
case "${home}":
|
||||
return os.path.expanduser("~")
|
||||
case "${uname}" | "${sysname}":
|
||||
return platform.system().lower()
|
||||
case "${arch}":
|
||||
return platform.machine()
|
||||
case "${release}":
|
||||
return platform.release()
|
||||
case _:
|
||||
return os.path.expandvars(m.group(0))
|
||||
if var == "${hostname}":
|
||||
return os.uname()[1].split(".")[0]
|
||||
elif var == "${fqdn}":
|
||||
return os.uname()[1]
|
||||
elif var == "${home}":
|
||||
return os.path.expanduser("~")
|
||||
elif var == "${uname}" | "${sysname}":
|
||||
return platform.system().lower()
|
||||
elif var == "${arch}":
|
||||
return platform.machine()
|
||||
elif var == "${release}":
|
||||
return platform.release()
|
||||
else:
|
||||
return os.path.expandvars(m.group(0))
|
||||
|
||||
s = re.sub(r"\${?([^\s}]+)}?", "${\\1}", s)
|
||||
return re.sub(r"\$\{.*?\}", _repl, s)
|
||||
|
|
Loading…
Reference in a new issue