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") |
| 13 | _path = args_utils.get_path_arg(args.models_path) |
| 14 | |
| 15 | logger_cli.info("# ...models path is '{}'".format(args.models_path)) |
| 16 | |
| 17 | models = {} |
| 18 | for _folder in os.listdir(args.models_path): |
| 19 | # validate item as a model |
| 20 | _model_path = os.path.join( |
| 21 | args.models_path, |
| 22 | _folder |
| 23 | ) |
| 24 | _validated = validator.basic_model_validation_by_path(_model_path) |
| 25 | |
| 26 | if not _validated: |
| 27 | logger_cli.info("-> '{}' not a valid model".format(_folder)) |
| 28 | continue |
| 29 | else: |
| 30 | models[_folder] = _model_path |
| 31 | |
| 32 | logger_cli.info("-> '{}' at '{}'".format(_folder, _model_path)) |
| 33 | |
| 34 | # TODO: collect info about the model |
| 35 | |
| 36 | return |
| 37 | |
| 38 | |
| 39 | def do_diff(args): |
Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 40 | logger_cli.info("# Reclass comparer (HTML report: '{}'".format(args.file)) |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 41 | _filename = args_utils.get_file_arg(args) |
| 42 | |
| 43 | # checking folder params |
| 44 | _model1 = args_utils.get_path_arg(args.model1) |
| 45 | _model2 = args_utils.get_path_arg(args.model2) |
| 46 | |
| 47 | # Do actual compare using hardcoded model names |
| 48 | mComparer = comparer.ModelComparer() |
| 49 | |
| 50 | mComparer.model_name_1 = os.path.split(_model1)[1] |
| 51 | mComparer.model_path_1 = _model1 |
| 52 | mComparer.model_name_2 = os.path.split(_model2)[1] |
| 53 | mComparer.model_path_2 = _model2 |
| 54 | |
| 55 | mComparer.load_model_tree( |
| 56 | mComparer.model_name_1, |
| 57 | mComparer.model_path_1 |
| 58 | ) |
| 59 | mComparer.load_model_tree( |
| 60 | mComparer.model_name_2, |
| 61 | mComparer.model_path_2 |
| 62 | ) |
| 63 | |
| 64 | diffs = mComparer.generate_model_report_tree() |
| 65 | |
| 66 | report = reporter.ReportToFile( |
| 67 | reporter.HTMLModelCompare(), |
| 68 | _filename |
| 69 | ) |
| 70 | logger_cli.info("# Generating report to {}".format(_filename)) |
| 71 | report({ |
| 72 | "nodes": {}, |
| 73 | "diffs": diffs |
| 74 | }) |