blob: 2546ec37371ab9e2af0ca6af073642d9022085b8 [file] [log] [blame]
Alex Savatieievc9055712019-03-01 14:43:56 -06001import os
2
3import comparer
4import validator
5
6from cfg_checker.common import logger_cli
7from cfg_checker.helpers import args_utils
8from cfg_checker.reports import reporter
9
10
11def do_list(args):
12 logger_cli.info("# Reclass list")
Alex41485522019-04-12 17:26:18 -050013 _arg_path = args_utils.get_arg(args, 'models_path')
14 logger_cli.info("-> Current path is: {}".format(_arg_path))
15 _path = args_utils.get_path_arg(_arg_path)
Alex Savatieievc9055712019-03-01 14:43:56 -060016
17 logger_cli.info("# ...models path is '{}'".format(args.models_path))
18
19 models = {}
20 for _folder in os.listdir(args.models_path):
21 # validate item as a model
22 _model_path = os.path.join(
23 args.models_path,
24 _folder
25 )
26 _validated = validator.basic_model_validation_by_path(_model_path)
27
28 if not _validated:
29 logger_cli.info("-> '{}' not a valid model".format(_folder))
30 continue
31 else:
32 models[_folder] = _model_path
33
34 logger_cli.info("-> '{}' at '{}'".format(_folder, _model_path))
35
36 # TODO: collect info about the model
37
38 return
39
40
41def do_diff(args):
Alexb8af13a2019-04-16 18:38:12 -050042 logger_cli.info("# Reclass comparer (HTML report)")
Alex41485522019-04-12 17:26:18 -050043 _filename = args_utils.get_arg(args, 'html')
Alex Savatieievc9055712019-03-01 14:43:56 -060044 # checking folder params
45 _model1 = args_utils.get_path_arg(args.model1)
46 _model2 = args_utils.get_path_arg(args.model2)
47
48 # Do actual compare using hardcoded model names
49 mComparer = comparer.ModelComparer()
50
51 mComparer.model_name_1 = os.path.split(_model1)[1]
52 mComparer.model_path_1 = _model1
53 mComparer.model_name_2 = os.path.split(_model2)[1]
54 mComparer.model_path_2 = _model2
55
56 mComparer.load_model_tree(
57 mComparer.model_name_1,
58 mComparer.model_path_1
59 )
60 mComparer.load_model_tree(
61 mComparer.model_name_2,
62 mComparer.model_path_2
63 )
64
65 diffs = mComparer.generate_model_report_tree()
66
67 report = reporter.ReportToFile(
68 reporter.HTMLModelCompare(),
69 _filename
70 )
71 logger_cli.info("# Generating report to {}".format(_filename))
72 report({
73 "nodes": {},
74 "diffs": diffs
75 })