comparison makeitso/python_package/{{package}}/{{main}}.py @ 196:d25ca7099df8

STUB: makeitso/python_package/{{package}}/{{main}}.py
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 May 2014 18:24:17 -0700
parents 3cb66c9e5ce8
children bb57bec165b7
comparison
equal deleted inserted replaced
195:3cb66c9e5ce8 196:d25ca7099df8
14 # module globals 14 # module globals
15 __all__ = ['main', 'Parser'] 15 __all__ = ['main', 'Parser']
16 here = os.path.dirname(os.path.realpath(__file__)) 16 here = os.path.dirname(os.path.realpath(__file__))
17 string = (str, unicode) 17 string = (str, unicode)
18 18
19 def ensure_dir(directory):
20 """ensure a directory exists"""
21 if os.path.exists(directory):
22 assert os.path.isdir(directory)
23 return directory
24 os.makedirs(directory)
25 return directory
26
19 27
20 class Parser(argparse.ArgumentParser): 28 class Parser(argparse.ArgumentParser):
21 """CLI option parser""" 29 """CLI option parser"""
22 def __init__(self): 30 def __init__(self):
23 argparse.ArgumentParser.__init__(self, description=__doc__) 31 argparse.ArgumentParser.__init__(self, description=__doc__)
32 self.options = None
24 33
34 def parse_args(self, *args, **kw):
35 options = argparse.ArgumentParser.parse_args(*args, **kw)
36 self.validate(options)
37 self.options = options
38 return options
39
40 def validate(self, options):
41 """validate options"""
25 42
26 def main(args=sys.argv[1:]): 43 def main(args=sys.argv[1:]):
27 """CLI""" 44 """CLI"""
28 45
29 # parse command line options 46 # parse command line options
30 parser = Parser(description=__doc__) 47 parser = Parser(description=__doc__)
31 options = parser.parse_args(args) 48 options = parser.parse_args(args)
32 49
33 if __name__ == '__main__': 50 if __name__ == '__main__':
34 main() 51 main()