forked from bewest/decoding-carelink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmypump.py
76 lines (55 loc) · 1.48 KB
/
mypump.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
import serial
import argparse
import sys
from pprint import pprint, pformat
import pump
import logging
io = logging.getLogger( )
def get_argparser( ):
parser = argparse.ArgumentParser( )
parser.add_argument(
'--port', '-p', default='/dev/ttyUSB0',
help="path to serial port"
)
parser.add_argument(
'--verbosity', '-v',
default=0,
action="count",
help="verbosity"
)
parser.add_argument(
'--log', '-l',
default=sys.stdout,
type=argparse.FileType('a'),
help="log output (stdout default)"
)
parser.add_argument(
'serial', default='208850',
help="serial number of target pump (eg. 208850)"
)
return parser
class App(object):
_log_map = { 0: logging.INFO, 1: logging.DEBUG,
2: logging.WARN, 3: logging.DEBUG }
def __init__(self):
self.parser = get_argparser( )
self.opts = self.parser.parse_args( )
logging.basicConfig(stream=self.opts.log)
if self.opts.log.name != '<stdout>':
stdout = logging.StreamHandler(stream=sys.stdout)
io.addHandler(stdout)
io.setLevel(self._log_map.get(self.opts.verbosity, logging.DEBUG))
def main(self):
io.debug( "debug hello world!!!" )
io.info( "info hello world!!!" )
io.warn( "warn hello world!!!" )
io.error( "error hello world!!!" )
io.critical( "critical hello world!!!" )
io.fatal( "fatal hello world!!!" )
if __name__ == '__main__':
import doctest
doctest.testmod( )
app = App( )
app.main( )
#####
# EOF