-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnerd_converter.py
59 lines (49 loc) · 1.63 KB
/
nerd_converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Main Command-line script for the NERD Converter
"""
from collections import OrderedDict
from pathlib import Path
import click
from tools.recipe_filterer import filter_recipes
from tools.recipe_preprocessor import preprocess_recipes
steps_dict = OrderedDict(
[
("preprocess", preprocess_recipes),
("filter", filter_recipes),
]
)
@click.command()
@click.option("--data_dir", "-d", type=click.Path(exists=True), default="data")
@click.option("--output_dir", "-o", type=click.Path(), default="output")
@click.option(
"--steps",
"-s",
type=click.Choice(list(steps_dict.keys()) + ["all"], case_sensitive=False),
multiple=True,
default=["all"],
)
def cli(data_dir: str, output_dir: str, steps: list[str]):
"""Convert recipes to NERD format via a series of steps"""
print("Welcome to the NERD Converter!")
data_path = Path(data_dir)
# If data_path doesn't exist, we've got issues
if not data_path.exists():
click.echo(f"Data directory {data_path} not found")
return
output_path = Path(output_dir)
# We can create output directory if it doesn't exist
output_path.mkdir(parents=True, exist_ok=True)
if "all" in steps:
steps = list(steps_dict.keys())
for i, s in enumerate(steps):
print()
print(f"Running step {i+1}/{len(steps)}: {s}")
if s not in steps_dict:
click.echo(f"Step '{s}' not found")
return
if not steps_dict[s](data_path, output_path):
click.echo(f"Step '{s}' failed")
return
click.echo("All steps completed successfully!")
if __name__ == "__main__":
cli()