Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 1 | import os |
| 2 | |
| 3 | import comparer |
| 4 | import validator |
| 5 | |
| 6 | from cfg_checker.common import logger_cli |
| 7 | from cfg_checker.helpers import args_utils |
| 8 | from cfg_checker.reports import reporter |
| 9 | |
| 10 | |
| 11 | def do_list(args): |
| 12 | logger_cli.info("# Reclass list") |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 13 | _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 Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 16 | |
| 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 | |
| 41 | def do_diff(args): |
Alex | b8af13a | 2019-04-16 18:38:12 -0500 | [diff] [blame^] | 42 | logger_cli.info("# Reclass comparer (HTML report)") |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 43 | _filename = args_utils.get_arg(args, 'html') |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 44 | # 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 | }) |