dais-shell 0.1.9__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dais_shell-0.1.9 → dais_shell-0.2.0}/PKG-INFO +1 -1
- {dais_shell-0.1.9 → dais_shell-0.2.0}/pyproject.toml +1 -1
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/runtimes/BashRuntime.py +4 -11
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/runtimes/PowershellRuntime.py +6 -23
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/types/command_step.py +1 -1
- {dais_shell-0.1.9 → dais_shell-0.2.0}/README.md +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/__init__.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/constants.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/env_builder.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/iostream_reader.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/py.typed +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/runtimes/BaseShellRuntime.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/runtimes/__init__.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/types/__init__.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/types/exceptions.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/utils/__init__.py +0 -0
- {dais_shell-0.1.9 → dais_shell-0.2.0}/src/dais_shell/utils/env_expander.py +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import shlex
|
|
2
3
|
import shutil
|
|
3
4
|
from dataclasses import asdict, dataclass
|
|
4
5
|
|
|
@@ -15,7 +16,7 @@ class BashCommandStep(CommandStep):
|
|
|
15
16
|
return cls(**asdict(step))
|
|
16
17
|
|
|
17
18
|
def to_wrapper_script(self):
|
|
18
|
-
return
|
|
19
|
+
return f"exec {shlex.quote(self.command)} {self.args}"
|
|
19
20
|
|
|
20
21
|
# --- --- --- --- --- ---
|
|
21
22
|
|
|
@@ -36,21 +37,13 @@ class BashRuntime(BaseShellRuntime):
|
|
|
36
37
|
self._shell,
|
|
37
38
|
"-c",
|
|
38
39
|
step.to_wrapper_script(),
|
|
39
|
-
"--",
|
|
40
|
-
step.command,
|
|
41
|
-
*step.args
|
|
42
40
|
]
|
|
43
41
|
|
|
44
42
|
def _prepare_cmd(self, step: CommandStep) -> list[str]:
|
|
45
43
|
env_expander = EnvExpander(step.env or {})
|
|
46
|
-
step.args =
|
|
44
|
+
step.args = env_expander.expand(step.args)
|
|
47
45
|
step = BashCommandStep.from_command_step(step)
|
|
48
|
-
|
|
49
|
-
is_shell_command = resolved is None
|
|
50
|
-
if is_shell_command:
|
|
51
|
-
return self._make_bash_commands(step)
|
|
52
|
-
else:
|
|
53
|
-
return [resolved, *step.args]
|
|
46
|
+
return self._make_bash_commands(step)
|
|
54
47
|
|
|
55
48
|
def run_sync(self,
|
|
56
49
|
step: CommandStep,
|
|
@@ -20,25 +20,8 @@ class PowerShellCommandStep(CommandStep):
|
|
|
20
20
|
return cls(**asdict(step))
|
|
21
21
|
|
|
22
22
|
def to_wrapper_script(self):
|
|
23
|
-
def
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
cmd_json = json.dumps(self.command)
|
|
27
|
-
args_json = json.dumps(self.args)
|
|
28
|
-
|
|
29
|
-
if len(self.args) > 0:
|
|
30
|
-
# encode to base64 and decode in script to prevent single quotes in the args
|
|
31
|
-
args_b64 = ps_encode(args_json)
|
|
32
|
-
args_line = f"""\
|
|
33
|
-
$args_json = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('{args_b64}'))
|
|
34
|
-
$arguments = ,(ConvertFrom-Json $args_json)
|
|
35
|
-
"""
|
|
36
|
-
invoke_line = "& $command @arguments"
|
|
37
|
-
else:
|
|
38
|
-
# when no arguments, PowerShell ConvertFrom-Json will parse as null
|
|
39
|
-
# which will cause error for some commands.
|
|
40
|
-
args_line = ""
|
|
41
|
-
invoke_line = "& $command"
|
|
23
|
+
def ps_quote(s: str) -> str:
|
|
24
|
+
return "'" + s.replace("'", "''") + "'"
|
|
42
25
|
|
|
43
26
|
script = f"""
|
|
44
27
|
$ErrorActionPreference = "Stop"
|
|
@@ -49,10 +32,10 @@ $OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
49
32
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
50
33
|
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
|
51
34
|
|
|
52
|
-
$command
|
|
53
|
-
|
|
35
|
+
$command = {ps_quote(self.command)}
|
|
36
|
+
|
|
37
|
+
& $command {self.args}
|
|
54
38
|
|
|
55
|
-
{invoke_line}
|
|
56
39
|
exit $LASTEXITCODE"""
|
|
57
40
|
return script.strip()
|
|
58
41
|
|
|
@@ -121,7 +104,7 @@ class PowerShellRuntime(BaseShellRuntime):
|
|
|
121
104
|
|
|
122
105
|
def _prepare_cmd(self, step: CommandStep) -> list[str]:
|
|
123
106
|
env_expander = EnvExpander(step.env or {})
|
|
124
|
-
step.args =
|
|
107
|
+
step.args = env_expander.expand(step.args)
|
|
125
108
|
step = PowerShellCommandStep.from_command_step(step)
|
|
126
109
|
script = step.to_wrapper_script()
|
|
127
110
|
encoded = self._encode(script)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|