Mercurial > hg > MakeItSo
view makeitso/file2template.py @ 182:215a71ac0eff
TODO
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 23 Mar 2014 11:53:11 -0700 |
parents | 7ac8571788e2 |
children | 55b34a5a2e5f |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- """ convert a file to a template """ # TODO: shell script extension import os import subprocess import sys from argparse import ArgumentParser here = os.path.dirname(os.path.realpath(__file__)) string = (str, unicode) template = '''#!/usr/bin/env python """ template """ import argparse import sys variables = { {variables} } template = """{content}""" def main(args=sys.argv[1:]): """CLI""" # parse command line parser = argparse.ArgumentParser(description=__doc__) for variable in variables: pass options = parser.parse_args(args) if __name__ == '__main__': main() ''' class File2TemplateParser(ArgumentParser): """argument parser for `%(prog)s`""" def __init__(self): ArgumentParser.__init__(self, description=__doc__) parser.add_argument('input', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='input file, or read from stdin if ommitted') parser.add_argument('variables', nargs='*', help="variables to use") parser.add_argument('-o', '--output', dest='output', type=argparse.FileType('r'), default=sys.stdout, help="output file, or stdout if ommitted'") def main(args=sys.argv[1:]): parser = File2TemplateParser() options = parser.parse_args(args) if __name__ == '__main__': main()