comparison makeitso/file2template.py @ 181:7ac8571788e2

add script to make templates from files
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Mar 2014 11:52:47 -0700
parents
children 215a71ac0eff
comparison
equal deleted inserted replaced
180:9b78f52afe4e 181:7ac8571788e2
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 convert a file to a template
6 """
7
8
9 import os
10 import subprocess
11 import sys
12 from argparse import ArgumentParser
13
14 here = os.path.dirname(os.path.realpath(__file__))
15 string = (str, unicode)
16
17 template = '''#!/usr/bin/env python
18
19 """
20 template
21 """
22
23 import argparse
24 import sys
25
26 variables = {
27 {variables}
28 }
29
30 template = """{content}"""
31
32 def main(args=sys.argv[1:]):
33 """CLI"""
34
35 # parse command line
36 parser = argparse.ArgumentParser(description=__doc__)
37 for variable in variables:
38 pass
39 options = parser.parse_args(args)
40
41 if __name__ == '__main__':
42 main()
43 '''
44
45
46 class File2TemplateParser(ArgumentParser):
47 """argument parser for `%(prog)s`"""
48
49 def __init__(self):
50 ArgumentParser.__init__(self, description=__doc__)
51 parser.add_argument('input', nargs='?',
52 type=argparse.FileType('r'), default=sys.stdin,
53 help='input file, or read from stdin if ommitted')
54 parser.add_argument('variables', nargs='*',
55 help="variables to use")
56 parser.add_argument('-o', '--output', dest='output',
57 type=argparse.FileType('r'), default=sys.stdout,
58 help="output file, or stdout if ommitted'")
59
60
61 def main(args=sys.argv[1:]):
62
63 parser = File2TemplateParser()
64 options = parser.parse_args(args)
65
66 if __name__ == '__main__':
67 main()