forked from openrightsgroup/OrgProbe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
58 lines (48 loc) · 1.68 KB
/
__main__.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
import sys
import getopt
import ConfigParser
import logging
from probe import OrgProbe
from api import APIRequest
optlist, optargs = getopt.getopt(sys.argv[1:],
'c:v',
['register', 'email=', 'secret=', 'seed=']
)
opts = dict(optlist)
logging.basicConfig(
level=logging.DEBUG if '-v' in opts else logging.INFO,
datefmt='[%Y-%m-%d %H:%M:%S]',
format='%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s')
logging.getLogger('urllib3.connectionpool').setLevel(logging.ERROR)
logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(
logging.ERROR)
configfile = opts.get('-c', 'config.ini')
config = ConfigParser.ConfigParser()
loaded = config.read([configfile])
logging.info("Loaded %s config files from %s", loaded, configfile)
if not config.has_section('global'):
config.add_section('global')
config.set('global', 'interval', 1)
with open(configfile, 'w') as fp:
config.write(fp)
if config.has_section('api'):
def apiconfig(prop, method):
try:
setattr(APIRequest, prop.upper(), method('api', prop))
logging.info("Set %s to %s", prop,
getattr(APIRequest, prop.upper()))
except Exception:
pass
apiconfig('https', config.getboolean)
apiconfig('host', config.get)
apiconfig('port', config.getint)
apiconfig('version', config.get)
probe = OrgProbe(config)
if '--register' in opts:
probe.register(opts, config)
with open(configfile, 'w') as fp:
config.write(fp)
sys.exit(0)
else:
logging.info("Entering run mode")
sys.exit(probe.run(optargs))