-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_catalogs.py
58 lines (48 loc) · 1.79 KB
/
run_catalogs.py
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
47
48
49
50
51
52
53
54
55
56
57
58
"""
Runner to add target catalog, if catalog info is missing. Print output.
"""
import argparse
import logging
from tendrils import api
from flows import download_catalog
def parse():
"""
# Parse command line arguments:
"""
parser = argparse.ArgumentParser(description='Run catalog.')
parser.add_argument('-d', '--debug', help='Print debug messages.', action='store_true')
parser.add_argument('-q', '--quiet', help='Only report warnings and errors.', action='store_true')
parser.add_argument('-t', '--target', type=str, help='Target to print catalog for.', nargs='?', default=None)
return parser.parse_args()
def set_logging_level(args):
# Set logging level:
logging_level = logging.INFO
if args.quiet:
logging_level = logging.WARNING
elif args.debug:
logging_level = logging.DEBUG
return logging_level
def main():
# Parse command line arguments:
args = parse()
# Setup logging:
logging_level = set_logging_level(args)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
console = logging.StreamHandler()
console.setFormatter(formatter)
logger = logging.getLogger('flows')
if not logger.hasHandlers():
logger.addHandler(console)
logger.setLevel(logging_level)
# Get missing
for target in api.get_catalog_missing():
logger.info("Downloading catalog for target=%s...", target)
download_catalog(target) # @TODO: refactor to Tendrils
# download target catalog for printing
if args.target is not None:
cat = api.get_catalog(args.target)
print(f"Target:{cat['target'].pprint_all()} "
f"\nReferences: {cat['references'].pprint_all()} "
f"\nAvoid:cat['avoid'].pprint_all()")
if __name__ == '__main__':
main()