Mercurial > hg > MakeItSo
view 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 |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- """ {{description}} """ # imports import argparse import os import subprocess import sys # module globals __all__ = ['main', 'Parser'] here = os.path.dirname(os.path.realpath(__file__)) string = (str, unicode) def ensure_dir(directory): """ensure a directory exists""" if os.path.exists(directory): assert os.path.isdir(directory) return directory os.makedirs(directory) return directory class Parser(argparse.ArgumentParser): """CLI option parser""" def __init__(self): argparse.ArgumentParser.__init__(self, description=__doc__) self.options = None def parse_args(self, *args, **kw): options = argparse.ArgumentParser.parse_args(*args, **kw) self.validate(options) self.options = options return options def validate(self, options): """validate options""" def main(args=sys.argv[1:]): """CLI""" # parse command line options parser = Parser(description=__doc__) options = parser.parse_args(args) if __name__ == '__main__': main()