Skip to content

Commit e5a8e7f

Browse files
allow generating generic pifaces for many pifaces
1 parent 487e833 commit e5a8e7f

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

looper/utils.py

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,29 @@ def _get_subcommand_args(subcommand_name, parser_args):
404404
return args
405405

406406

407-
def init_generic_pipeline():
407+
def init_generic_pipeline(pipelinepath: Optional[str] = None):
408408
"""
409409
Create generic pipeline interface
410410
"""
411411
console = Console()
412412

413-
try:
414-
os.makedirs("pipeline")
415-
except FileExistsError:
416-
pass
417-
418413
# Destination one level down from CWD in pipeline folder
419-
dest_file = os.path.join(os.getcwd(), "pipeline", LOOPER_GENERIC_PIPELINE)
414+
if not pipelinepath:
415+
try:
416+
os.makedirs("pipeline")
417+
except FileExistsError:
418+
pass
419+
420+
dest_file = os.path.join(os.getcwd(), "pipeline", LOOPER_GENERIC_PIPELINE)
421+
else:
422+
if os.path.isabs(pipelinepath):
423+
dest_file = pipelinepath
424+
else:
425+
dest_file = os.path.join(os.getcwd(), os.path.relpath(pipelinepath))
426+
try:
427+
os.makedirs(os.path.dirname(dest_file))
428+
except FileExistsError:
429+
pass
420430

421431
# Create Generic Pipeline Interface
422432
generic_pipeline_dict = {
@@ -433,18 +443,27 @@ def init_generic_pipeline():
433443
# Write file
434444
if not os.path.exists(dest_file):
435445
pprint(generic_pipeline_dict, expand_all=True)
446+
436447
with open(dest_file, "w") as file:
437448
yaml.dump(generic_pipeline_dict, file)
449+
438450
console.print(
439451
f"Pipeline interface successfully created at: [yellow]{dest_file}[/yellow]"
440452
)
453+
441454
else:
442455
console.print(
443456
f"Pipeline interface file already exists [yellow]`{dest_file}`[/yellow]. Skipping creation.."
444457
)
445458

446459
# Create Generic Output Schema
447-
dest_file = os.path.join(os.getcwd(), "pipeline", LOOPER_GENERIC_OUTPUT_SCHEMA)
460+
if not pipelinepath:
461+
dest_file = os.path.join(os.getcwd(), "pipeline", LOOPER_GENERIC_OUTPUT_SCHEMA)
462+
else:
463+
dest_file = os.path.join(
464+
os.path.dirname(dest_file), LOOPER_GENERIC_OUTPUT_SCHEMA
465+
)
466+
448467
generic_output_schema_dict = {
449468
"pipeline_name": "default_pipeline_name",
450469
"samples": {
@@ -471,7 +490,12 @@ def init_generic_pipeline():
471490

472491
console.rule(f"\n[magenta]Example Pipeline Shell Script[/magenta]")
473492
# Create Generic countlines.sh
474-
dest_file = os.path.join(os.getcwd(), "pipeline", LOOPER_GENERIC_COUNT_LINES)
493+
494+
if not pipelinepath:
495+
dest_file = os.path.join(os.getcwd(), "pipeline", LOOPER_GENERIC_COUNT_LINES)
496+
else:
497+
dest_file = os.path.join(os.path.dirname(dest_file), LOOPER_GENERIC_COUNT_LINES)
498+
475499
shell_code = """#!/bin/bash
476500
linecount=`wc -l $1 | sed -E 's/^[[:space:]]+//' | cut -f1 -d' '`
477501
pipestat report -r $2 -i 'number_of_lines' -v $linecount -c $3
@@ -680,22 +704,23 @@ def looper_config_tutorial():
680704
if selection == "y":
681705
creating = False
682706

683-
if not os.path.exists(piface_paths[0]):
684-
console.print(
685-
f"[bold red]Warning:[/bold red] File does not exist at [yellow]{piface_paths[0]}[/yellow]"
686-
)
687-
console.print(
688-
"Do you wish to initialize a generic pipeline interface? [bold green]Y[/bold green]/[red]n[/red]..."
689-
)
690-
selection = None
691-
while selection not in ["y", "n"]:
692-
selection = console.input("\nSelection: ").lower().strip()
693-
if selection == "n":
707+
for piface_path in piface_paths:
708+
if not os.path.exists(piface_path):
694709
console.print(
695-
"Use command [yellow]`looper init_piface`[/yellow] to create a generic pipeline interface."
710+
f"[bold red]Warning:[/bold red] File does not exist at [yellow]{piface_path}[/yellow]"
696711
)
697-
if selection == "y":
698-
init_generic_pipeline()
712+
console.print(
713+
"Do you wish to initialize a generic pipeline interface? [bold green]Y[/bold green]/[red]n[/red]..."
714+
)
715+
selection = None
716+
while selection not in ["y", "n"]:
717+
selection = console.input("\nSelection: ").lower().strip()
718+
if selection == "n":
719+
console.print(
720+
"Use command [yellow]`looper init_piface`[/yellow] to create a generic pipeline interface."
721+
)
722+
if selection == "y":
723+
init_generic_pipeline(pipelinepath=piface_path)
699724

700725
console.print(f"Writing config file to [yellow]{looper_cfg_path}[/yellow]")
701726

0 commit comments

Comments
 (0)