comparison makeitso/python_package/{{package}}/{{main}}.py @ 207:04c5464355b8

monitor
author Jeff Hammel <k0scist@gmail.com>
date Tue, 27 Jan 2015 12:21:45 -0800
parents d9d7bfdb54db
children ab726b2f3143
comparison
equal deleted inserted replaced
206:d9d7bfdb54db 207:04c5464355b8
8 # imports 8 # imports
9 import argparse 9 import argparse
10 import os 10 import os
11 import subprocess 11 import subprocess
12 import sys 12 import sys
13 import time
13 14
14 # module globals 15 # module globals
15 __all__ = ['main', 'Parser'] 16 __all__ = ['main', 'Parser']
16 here = os.path.dirname(os.path.realpath(__file__)) 17 here = os.path.dirname(os.path.realpath(__file__))
17 string = (str, unicode) 18 string = (str, unicode)
30 """CLI option parser""" 31 """CLI option parser"""
31 def __init__(self, **kwargs): 32 def __init__(self, **kwargs):
32 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) 33 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
33 kwargs.setdefault('description', __doc__) 34 kwargs.setdefault('description', __doc__)
34 argparse.ArgumentParser.__init__(self, **kwargs) 35 argparse.ArgumentParser.__init__(self, **kwargs)
36 self.add_argument('--monitor', dest='monitor',
37 type=float, metavar='SLEEP',
38 help="run in monitor mode")
35 self.options = None 39 self.options = None
36 40
37 def parse_args(self, *args, **kw): 41 def parse_args(self, *args, **kw):
38 options = argparse.ArgumentParser.parse_args(self, *args, **kw) 42 options = argparse.ArgumentParser.parse_args(self, *args, **kw)
39 self.validate(options) 43 self.validate(options)
48 52
49 # parse command line options 53 # parse command line options
50 parser = Parser() 54 parser = Parser()
51 options = parser.parse_args(args) 55 options = parser.parse_args(args)
52 56
57 try:
58 while True:
59 if options.monitor:
60 time.sleep(options.monitor)
61 else:
62 break
63 except KeyboardInterrupt:
64 pass
65
53 if __name__ == '__main__': 66 if __name__ == '__main__':
54 main() 67 main()
68