forked from IdentityPython/pyFF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd.py
79 lines (67 loc) · 1.97 KB
/
md.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
pyFF is the SAML metadata aggregator
Usage: [-h|--help]
[-R]
[--loglevel=<level>]
[--logfile=<file>]
[--version]
"""
import getopt
import importlib
import logging
import sys
import traceback
from . import __version__
from .mdrepo import MDRepository
from .pipes import plumbing
from .constants import config
def main():
"""
The main entrypoint for the pyFF cmdline tool.
"""
opts = None
args = None
try:
opts, args = getopt.getopt(sys.argv[1:], 'hRm', ['help', 'loglevel=', 'logfile=', 'version', 'module'])
except getopt.error as msg:
print(msg)
print(__doc__)
sys.exit(2)
if config.loglevel is None:
config.loglevel = logging.WARN
if config.modules is None:
config.modules = []
for o, a in opts:
if o in ('-h', '--help'):
print(__doc__)
sys.exit(0)
elif o in '--loglevel':
config.loglevel = getattr(logging, a.upper(), None)
if not isinstance(config.loglevel, int):
raise ValueError('Invalid log level: %s' % a)
elif o in '--logfile':
config.logfile = a
elif o in ('-m', '--module'):
config.modules.append(a)
elif o in '--version':
print("pyff version {}".format(__version__))
sys.exit(0)
log_args = {'level': config.loglevel}
if config.logfile is not None:
log_args['filename'] = config.logfile
logging.basicConfig(**log_args)
config.modules.append('pyff.builtins')
for mn in config.modules:
importlib.import_module(mn)
try:
md = MDRepository()
for p in args:
plumbing(p).process(md, state={'batch': True, 'stats': {}})
sys.exit(0)
except Exception as ex:
if logging.getLogger().isEnabledFor(logging.DEBUG):
traceback.print_exc()
logging.error(ex)
sys.exit(-1)
if __name__ == "__main__": # pragma: no cover
main()