Mercurial > hg > MakeItSo
diff 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 diff
--- a/makeitso/python_package/{{package}}/{{main}}.py Fri May 16 23:59:10 2014 -0700 +++ b/makeitso/python_package/{{package}}/{{main}}.py Sat May 24 18:24:17 2014 -0700 @@ -16,12 +16,29 @@ 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""" @@ -31,4 +48,4 @@ options = parser.parse_args(args) if __name__ == '__main__': - main() + main()