Coverage for subtractor/cli.py: 100.00%
32 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 22:33:07 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 22:33:07 +00:00
1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3# pylint: disable=line-too-long
4"""Build subtracted images from zipping streams."""
5import os
6import pathlib
7import sys
8import typing
10import subtractor.subtractor as diff
12DEBUG_VAR = 'SUBTRACTOR_DEBUG'
13DEBUG = bool(os.getenv(DEBUG_VAR))
15ABORT_VAR = 'SUBTRACTOR_ABORT'
16ABORT = bool(os.getenv(ABORT_VAR))
18THRESHOLD_VAR = 'SUBTRACTOR_THRESHOLD'
19THRESHOLD = float(os.getenv(THRESHOLD_VAR, '0.01'))
21DIFF_TEMPLATE_VAR = 'SUBTRACTOR_DIFF_TEMPLATE'
22DIFF_TEMPLATE = os.getenv(DIFF_TEMPLATE_VAR, '')
25# pylint: disable=expression-not-assigned
26@typing.no_type_check
27def main(argv=None, abort=None, debug=None, threshold=None, diff_template=''):
28 """Dispatch processing of the job.
29 This is the strings only command line interface.
30 For python API use interact with diff functions directly.
31 """
32 argv = sys.argv[1:] if argv is None else argv
33 debug = debug if debug else DEBUG
34 abort = abort if abort else ABORT
35 threshold = threshold if threshold else THRESHOLD
36 diff_template = diff_template if diff_template else DIFF_TEMPLATE
37 if diff_template:
38 if not all(['$ref' in diff_template, '$obs' in diff_template]):
39 print('ERROR: When using external diff tool, template requires mention of $ref and $obs.')
40 sys.exit(2)
42 unique_trees = {arg: None for arg in argv}
43 for tree_or_leaf in unique_trees:
44 if not pathlib.Path(tree_or_leaf).is_file() and not pathlib.Path(tree_or_leaf).is_dir():
45 print('ERROR: For now only existing paths accepted.')
46 sys.exit(2)
48 code, _ = diff.main(
49 list(unique_trees.keys()), abort=abort, debug=debug, threshold=threshold, diff_template=diff_template
50 )
51 return code