-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
66 lines (61 loc) · 1.87 KB
/
run.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
#!/bin/env python3
import argparse
import datetime
import logging
import netrc
import os
import pprint
import pyexch.pyexch
def process_args():
constructor_args = {
'formatter_class': argparse.RawDescriptionHelpFormatter,
'description': 'outlook scheduler',
'epilog': '''
Program is controlled using the following environment variables:
NETRC
path to netrc file (default: ~/.netrc)
where netrc file has keys "EXCH"
and the "EXCH" key has values for login, password, account
'''
}
parser = argparse.ArgumentParser()
parser.add_argument( '--debug', action='store_true' )
parser.add_argument( '-k', '--netrckey',
help='key in netrc to use for login,passwd; default=%(default)s' )
defaults = {
'debug': False,
'netrckey': 'NETID',
'passwd': None,
'user': None,
}
parser.set_defaults( **defaults )
args = parser.parse_args()
# Load login and passwd from netrc
netrc_fn = os.getenv( 'NETRC' )
nrc = netrc.netrc( netrc_fn )
nrc_parts = nrc.authenticators( args.netrckey )
if nrc_parts:
args.user = nrc_parts[0]
args.passwd = nrc_parts[2]
if not args.user:
raise UserWarning( 'Empty username not allowed' )
if not args.passwd:
raise UserWarning( 'Empty passwd not allowed' )
return args
def run( args ):
pprint.pprint( ['ARGS', args] )
if __name__ == '__main__':
log_lvl = logging.INFO
args = process_args()
if args.debug:
log_lvl = logging.DEBUG
fmt = '%(levelname)s %(message)s'
if log_lvl == logging.DEBUG:
fmt = '%(levelname)s [%(filename)s:%(funcName)s:%(lineno)s] %(message)s'
logging.basicConfig( level=log_lvl, format=fmt )
no_debug = [
'exchangelib',
]
for key in no_debug:
logging.getLogger(key).setLevel(logging.CRITICAL)
run( args )