In pack_spark_sdk.py, the dotnet pack cmd is constructed with a dict of opts. If the value part is None, the opt should be formatted as a flag, "--key" instead of "--key None".
93 lines
2.1 KiB
Python
93 lines
2.1 KiB
Python
def fmt_dotnet_prop(k, v):
|
|
if not isinstance(k, str):
|
|
k = str(k)
|
|
if len(k) == 0:
|
|
raise ValueError("Prop key empty")
|
|
if isinstance(v, bool):
|
|
v = str(v).lower()
|
|
return f"-p:{k}={v}"
|
|
|
|
|
|
def fmt_dotnet_props(props: dict):
|
|
return " ".join(
|
|
map(lambda kv: fmt_dotnet_prop(kv[0], kv[1]), props.items()))
|
|
|
|
|
|
def fmt_dotnet_opt_key(k):
|
|
if not isinstance(k, str):
|
|
k = str(k)
|
|
if len(k) == 0:
|
|
raise ValueError("Option key empty")
|
|
if k.startswith("-") or k.startswith("/"):
|
|
return k
|
|
if len(k) == 1:
|
|
return f"-{k}"
|
|
return f"--{k}"
|
|
|
|
|
|
def fmt_dotnet_opts(opts: dict):
|
|
return " ".join(map(lambda kv: fmt_dotnet_opt(kv[0], kv[1]), opts.items()))
|
|
|
|
|
|
def fmt_dotnet_opt(k, v):
|
|
kstr = fmt_dotnet_opt_key(k)
|
|
if v is None:
|
|
return kstr
|
|
if isinstance(v, bool):
|
|
v = str(v).lower()
|
|
return f"{kstr} {v}"
|
|
|
|
|
|
def append_dotnet_props(cmd: str, props: dict):
|
|
if props:
|
|
cmd = f"{cmd} {fmt_dotnet_props(props)}"
|
|
return cmd
|
|
|
|
|
|
def append_dotnet_opts(cmd: str, opts: dict):
|
|
if opts:
|
|
cmd = f"{cmd} {fmt_dotnet_opts(opts)}"
|
|
return cmd
|
|
|
|
|
|
def dotnet_build_cmd(target, opts={}, props={}):
|
|
cmd = f"dotnet build {target}"
|
|
if opts:
|
|
cmd += " " + fmt_dotnet_opts(opts)
|
|
if props:
|
|
cmd = f"{cmd} {fmt_dotnet_props(props)}"
|
|
return f"dotnet build {target}"
|
|
|
|
|
|
class DotnetCommand:
|
|
def __init__(self, action):
|
|
self.cmd = f"dotnet {action}"
|
|
|
|
def add_opt(self, k, v):
|
|
self.cmd += fmt_dotnet_opt(k, v)
|
|
return self
|
|
|
|
def add_opts(self, opts: dict):
|
|
self.cmd = append_dotnet_opts(self.cmd, opts)
|
|
return self
|
|
|
|
def add_positional(self, arg):
|
|
self.cmd += f" {arg}"
|
|
return self
|
|
|
|
def add_prop(self, k, v):
|
|
self.cmd += fmt_dotnet_prop(k, v)
|
|
return self
|
|
|
|
def add_props(self, props: dict):
|
|
self.cmd = append_dotnet_props(self.cmd, props)
|
|
return self
|
|
|
|
def clone(self):
|
|
rv = DotnetCommand("")
|
|
rv.cmd = self.cmd
|
|
return rv
|
|
|
|
def __str__(self):
|
|
return self.cmd
|