Remove match statement to support more interpreters

This commit is contained in:
Reid 'arrdem' McKenzie 2023-05-30 16:02:27 -06:00
parent 0562772dc8
commit 24f0338897

View file

@ -17,11 +17,14 @@ if sys.version_info <= (3, 9, 0):
Path.readlink = lambda p: Path(os.readlink(str(p))) Path.readlink = lambda p: Path(os.readlink(str(p)))
def sh(global_config, def sh(global_config, cmd: List[str], /, env: Optional[dict] = None):
cmd: List[str], /, shell = (
env: Optional[dict] = None): (global_config or {})
.get("cram", {})
shell = (global_config or {}).get("cram", {}).get("task", {}).get("apply", {}).get("shell", SHELL) .get("task", {})
.get("apply", {})
.get("shell", SHELL)
)
prefix = [] prefix = []
if env: if env:
@ -93,20 +96,19 @@ class Package(object):
def expandvars(s: str) -> str: def expandvars(s: str) -> str:
def _repl(m: re.Match) -> str: def _repl(m: re.Match) -> str:
var = m.group(0).lower() var = m.group(0).lower()
match var: if var == "${hostname}":
case "${hostname}":
return os.uname()[1].split(".")[0] return os.uname()[1].split(".")[0]
case "${fqdn}": elif var == "${fqdn}":
return os.uname()[1] return os.uname()[1]
case "${home}": elif var == "${home}":
return os.path.expanduser("~") return os.path.expanduser("~")
case "${uname}" | "${sysname}": elif var == "${uname}" | "${sysname}":
return platform.system().lower() return platform.system().lower()
case "${arch}": elif var == "${arch}":
return platform.machine() return platform.machine()
case "${release}": elif var == "${release}":
return platform.release() return platform.release()
case _: else:
return os.path.expandvars(m.group(0)) return os.path.expandvars(m.group(0))
s = re.sub(r"\${?([^\s}]+)}?", "${\\1}", s) s = re.sub(r"\${?([^\s}]+)}?", "${\\1}", s)