summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--patternutils/commands/targs.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py
index 04c286d..6478377 100644
--- a/patternutils/commands/targs.py
+++ b/patternutils/commands/targs.py
@@ -12,16 +12,11 @@ from .. import config, template, utils
def run_command(
- data: Dict[str, str],
+ command: str,
run: Callable[..., None],
shell: bool,
) -> None:
- if not shell:
- prepared_command = shlex.split(c) # type: Union[str, List[str]]
- else:
- prepared_command = c
-
- run(prepared_command)
+ run(shlex.split(command) if not shell else command)
@click.command(context_settings={"help_option_names": ("-h", "--help", "-?")})
@@ -89,7 +84,7 @@ def targs(
if not stream:
data = json.load(read_from) # type: ignore
else:
- data = [json.loads(line) for line in read_from]
+ data = [json.loads(line) for line in read_from] # type: ignore
except json.JSONDecodeError:
click.secho("JSON not valid!", fg="red", err=True)
raise SystemExit
@@ -110,17 +105,15 @@ def targs(
click.secho("jinja2 not installed!", fg="red", err=True)
raise SystemExit
- commands = [render(r) for r in data]
+ commands = {r: render(r) for r in data}
if editor:
try:
commands = utils.edit(commands)
- except RuntimeErro:
+ except RuntimeError:
click.secho("Your edit is not parseable!", fg="red", err=True)
raise SystemExit
- max_procs = utils.max_procs() if max_procs == 0 else max_procs
-
stdout = subprocess.DEVNULL if redirect_stdout else None
stderr = subprocess.DEVNULL if redirect_stderr else None
patched_subprocess = functools.partial(
@@ -134,12 +127,15 @@ def targs(
run=patched_subprocess,
shell=shell,
)
+
+ max_procs = utils.max_procs() if max_procs == 0 else max_procs
+
if max_procs == 1:
for r in commands:
patched_run_command(r)
else:
with multiprocessing.Pool(max_procs) as p:
- p.map(patched_run_command, commands)
+ p.map(patched_run_command, commands.values())
if __name__ == "__main__":