comparison makeitso/main.py @ 0:7a76836b50a7

initial (non-working) commit to makeitso
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 02 Nov 2010 17:56:14 -0700
parents
children c2f8464e0395
comparison
equal deleted inserted replaced
-1:000000000000 0:7a76836b50a7
1 #!/usr/bin/env python
2 """
3 filesystem template interpreter
4 """
5
6 import os
7 import subprocess
8 import sys
9
10 from optparse import OptionParser
11 from tempita import Template
12
13 def call(command, *args, **kw):
14 code = subprocess.call(command, *args, **kw)
15 if code:
16 if isinstance(command, basestring):
17 cmdstr = command
18 else:
19 cmdstr = ' '.join(command)
20 raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code))
21
22 def template_variables(template):
23 """return the variables needed for a template"""
24 raise NotImplementedError
25
26 def main(args=sys.argv[1:]):
27
28 # create option parser
29 usage = '%prog [options]'
30 parser = OptionParser(usage, description=__doc__)
31 parser.add_option('--variables', dest='variables',
32 help='print the variables in a template')
33 options, args = parser.parse_args(args)
34
35 # template variables
36 variables = {}
37 _vars = []
38 _args = []
39 for arg in args:
40 if '=' in arg:
41 key, value = arg.split('=')
42 variables[key] = value
43 else:
44 _args.append(arg)
45 args = _args
46
47 # get the content
48 content = sys.stdin.read()
49 template = Template(content)
50 print template.interpolate(**variables)
51
52
53 if __name__ == '__main__':
54 main()