POC for --dry-run param in run command

This commit is contained in:
Emmanuel Leblond 2023-11-18 13:44:30 +01:00
parent 2280645d0e
commit 455fc07ad9
No known key found for this signature in database
GPG key ID: C360860E645EFFC0
10 changed files with 40 additions and 10 deletions

View file

@ -134,6 +134,7 @@ def xargs(
varargs: Sequence[str],
*,
color: bool = False,
dry_run: bool = False,
target_concurrency: int = 1,
_max_length: int = _get_platform_max_length(),
**kwargs: Any,
@ -172,14 +173,19 @@ def xargs(
return cmd_fn(
*run_cmd, check=False, stderr=subprocess.STDOUT, **kwargs,
)
if dry_run:
for run_cmd in partitions:
print("DRY RUN EXEC: ", " ".join(run_cmd))
retcode = 0
stdout = b""
else:
threads = min(len(partitions), target_concurrency)
with _thread_mapper(threads) as thread_map:
results = thread_map(run_cmd_partition, partitions)
threads = min(len(partitions), target_concurrency)
with _thread_mapper(threads) as thread_map:
results = thread_map(run_cmd_partition, partitions)
for proc_retcode, proc_out, _ in results:
if abs(proc_retcode) > abs(retcode):
retcode = proc_retcode
stdout += proc_out
for proc_retcode, proc_out, _ in results:
if abs(proc_retcode) > abs(retcode):
retcode = proc_retcode
stdout += proc_out
return retcode, stdout