Commit 94a66476f87bc469f950b0fdfbc5863107f57737
1 parent
3317581a
Exists in
rhitier-dev
Add dry_run option to hp_cmd
Showing
1 changed file
with
20 additions
and
5 deletions
Show diff stats
web/hp_cmd.py
1 | -from run import generate_csv_file_if_needed, init_console_logger | |
1 | +import sys | |
2 | + | |
3 | +from run import generate_csv_file_if_needed, init_console_logger, config | |
2 | 4 | from datetime import datetime |
3 | 5 | import argparse |
4 | 6 | |
... | ... | @@ -7,12 +9,13 @@ if __name__ == "__main__": |
7 | 9 | description='description') |
8 | 10 | |
9 | 11 | hp_parser.add_argument('-clog', '--console-log', action='store_true') |
12 | + hp_parser.add_argument('-s', '--dry-run', action='store_true') | |
10 | 13 | |
11 | 14 | subparsers = hp_parser.add_subparsers(dest='hpcmd_name') |
12 | 15 | |
13 | 16 | csvgen_parser = subparsers.add_parser('csv_gen', |
14 | 17 | help='csv-gen help') |
15 | - csvgen_parser.add_argument('-a', '--all') | |
18 | + csvgen_parser.add_argument('-a', '--all', action='store_true') | |
16 | 19 | csvgen_parser.add_argument('-t', '--target') |
17 | 20 | csvgen_parser.add_argument('-i', '--input') |
18 | 21 | csvgen_parser.add_argument('-b', '--begin') |
... | ... | @@ -22,10 +25,22 @@ if __name__ == "__main__": |
22 | 25 | |
23 | 26 | if args.console_log: |
24 | 27 | _logger = init_console_logger() |
25 | - _logger.info("This is info") | |
26 | 28 | |
27 | 29 | if args.hpcmd_name == 'csv_gen': |
30 | + # todo: build default dates in not -b or -e | |
28 | 31 | start_date = datetime.strptime(args.begin, '%Y%m%d') |
29 | 32 | stop_date = datetime.strptime(args.end, '%Y%m%d') |
30 | - generate_csv_file_if_needed(args.target, args.input, start_date, stop_date) | |
31 | - | |
33 | + if args.all: | |
34 | + # build the {target_slug: [input list]} dictionnary from config.yaml | |
35 | + targets = {t['slug']: list(t['models'].keys()) for t in config['targets']} | |
36 | + else: | |
37 | + # todo: check -i an -t | |
38 | + targets = {args.target: [args.input]} | |
39 | + | |
40 | + for _t, _i_list in targets.items(): | |
41 | + # print(_t, _i_list) | |
42 | + for _i in _i_list: | |
43 | + print(f"generating csv for {_t}/ {_i}") | |
44 | + if args.dry_run: | |
45 | + continue | |
46 | + generate_csv_file_if_needed(_t, _i, start_date, stop_date) | ... | ... |