hp_cmd.py
1.67 KB
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
import sys
from run import generate_csv_file_if_needed, init_console_logger, config, get_default_sta_sto
from datetime import datetime
import argparse
if __name__ == "__main__":
hp_parser = argparse.ArgumentParser(prog='Descritpor',
description='description')
hp_parser.add_argument('-clog', '--console-log', action='store_true')
hp_parser.add_argument('-s', '--dry-run', action='store_true')
subparsers = hp_parser.add_subparsers(dest='hpcmd_name')
csvgen_parser = subparsers.add_parser('csv_gen',
help='csv-gen help')
csvgen_parser.add_argument('-a', '--all', action='store_true')
csvgen_parser.add_argument('-t', '--target')
csvgen_parser.add_argument('-i', '--input')
csvgen_parser.add_argument('-b', '--begin')
csvgen_parser.add_argument('-e', '--end')
args = hp_parser.parse_args()
if args.console_log:
_logger = init_console_logger()
if args.hpcmd_name == 'csv_gen':
# build default dates in not -b or not -e
sta, sto = get_default_sta_sto( args.begin, args.end)
if args.all:
# build the {target_slug: [input list]} dictionnary from config.yaml
targets = {t['slug']: list(t['models'].keys()) for t in config['targets']}
else:
# todo: check -i an -t
targets = {args.target: [args.input]}
for _t, _i_list in targets.items():
# print(_t, _i_list)
for _i in _i_list:
print(f"generating csv for {_t}/ {_i}")
if args.dry_run:
continue
generate_csv_file_if_needed(_t, _i, sta, sto)