-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlitani
executable file
·116 lines (92 loc) · 3.09 KB
/
litani
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
import argparse
import asyncio
import importlib
import logging
import pkgutil
import sys
from lib import litani
import lib
VALIDATE_DATA = False
def add_subparsers(subparsers):
modules = list(pkgutil.iter_modules(
lib.__path__, prefix=f"{lib.__name__}."))
for module in modules:
imported_module = importlib.import_module(module.name)
if hasattr(imported_module, 'add_subparser'):
imported_module.add_subparser(subparsers)
def get_args():
description = "Incrementally build up a dependency graph of jobs to execute"
pars = argparse.ArgumentParser(description=description)
subs = pars.add_subparsers(
title="subcommands", dest="subcommand")
subs.required = True
for arg in [{
"flags": ["-v", "--verbose"],
"action": "store_true",
"help": "verbose output",
}, {
"flags": ["-w", "--very-verbose"],
"action": "store_true",
"help": "debug output",
}, {
"flags": ["-V", "--version"],
"action": "version",
"version": litani.VERSION,
"help": "print data format version and exit",
}]:
flags = arg.pop("flags")
pars.add_argument(*flags, **arg)
add_subparsers(subs)
all_args = sys.argv[1:]
wrapped_command = None
if "--" in all_args:
sep_idx = all_args.index("--")
arg_list = all_args[0:sep_idx]
wrapped_command = arg_list[sep_idx+1:]
all_args = arg_list
args = pars.parse_args(all_args)
if wrapped_command is not None:
args.command = wrapped_command
return args
def set_up_logging(args):
if args.very_verbose:
level = logging.DEBUG
elif args.verbose:
level = logging.INFO
else:
level = logging.WARNING
logging.basicConfig(
format="litani: %(message)s", level=level)
async def main():
# pylint: disable=global-statement
global VALIDATE_DATA
args = get_args()
set_up_logging(args)
try:
# pylint: disable=unused-import
import voluptuous
import voluptuous.humanize
VALIDATE_DATA = True
except ImportError:
logging.debug(
"Litani requires the python module 'voluptuous' to be installed "
"to validate data. Installing voluptuous with pip or your "
"system package manager is recommended. Continuing without data "
"validation.")
await args.func(args)
if __name__ == "__main__":
asyncio.run(main())