Mercurial > hg > MakeItSo
annotate makeitso/makeitso.py @ 9:a77630b2b491
* add commandline to print commandlines
* add commandline option to print all variables
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 11 Nov 2010 18:19:44 -0800 |
parents | ac78e26cd568 |
children | a6fd93354f23 |
rev | line source |
---|---|
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 """ |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 filesystem template interpreter |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 """ |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 import os |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 import re |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 import subprocess |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 import sys |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 from optparse import OptionParser |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 from tempita import Template |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 |
9
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
14 # URL of this file |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
15 location = 'http://k0s.org/mozilla/hg/MakeItSo/raw-file/tip/makeitso/makeitso.py' |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
16 |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
17 # regular expressions for finding the shebang |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 shebang_re = '#!.*makeitso.*' |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 shebang_re = re.compile(shebang_re) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 |
6
ac78e26cd568
starting on web example; i have to understand more about shebangs
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
21 class MissingVariablesException(Exception): |
ac78e26cd568
starting on web example; i have to understand more about shebangs
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
22 def __init__(self, message, missing): |
ac78e26cd568
starting on web example; i have to understand more about shebangs
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
23 self.missing = missing |
ac78e26cd568
starting on web example; i have to understand more about shebangs
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
24 |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 def call(command, *args, **kw): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 code = subprocess.call(command, *args, **kw) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 if code: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 if isinstance(command, basestring): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 cmdstr = command |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 else: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 cmdstr = ' '.join(command) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
32 raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
33 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
34 def get_missing(name_error): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
35 """ |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
36 This is a horrible hack because python doesn't do the proper thing |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
37 via eval and return the name of the variable; instead, it just gives |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
38 you a message: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
39 >>> try: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
40 ... eval('2*foo') |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
41 ... except Exception, e: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
42 ... pass |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
43 """ |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
44 message = name_error.args[0] |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
45 varname = message.split("'")[1] |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
46 return varname |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
47 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
48 def missing_variables(template, variables): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
49 """return additional variables needed""" |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
50 vars = variables.copy() |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
51 missing = set([]) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
52 while True: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
53 try: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
54 template.substitute(**vars) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
55 return missing |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
56 except NameError, e: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
57 missed = get_missing(e) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
58 missing.add(missed) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
59 vars[missed] = '' |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
60 return missing |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
61 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
62 def template_variables(template): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
63 """return the variables needed for a template""" |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
64 return missing_variables(template, {}) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
65 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
66 def read_variables(variables): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
67 retval = {} |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
68 for i in variables: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
69 print 'Enter %s: ' % i, |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
70 retval[i] = raw_input() |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
71 return retval |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
72 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
73 def substitute(content, fp=sys.stdout, variables=None): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
74 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
75 # remove makeitso shebang if it has one |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
76 if shebang_re.match(content): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
77 content = os.linesep.join(content.splitlines()[1:]) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
78 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
79 variables = variables or {} |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
80 template = Template(content) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
81 missing = missing_variables(template, variables) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
82 if missing: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
83 # TODO: add a switch for interactive or not |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
84 variables.update(read_variables(missing)) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
85 print >> fp, template.substitute(**variables) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
86 |
9
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
87 def invocation(url, **variables): |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
88 """returns a string appropriate for TTW invocation""" |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
89 variables_string = ' '.join(['%s=%s' % (i,j) for i,j in variables.items()]) |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
90 return 'python <(curl %s) %s %s' % (location, url, variables_string) |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
91 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
92 def main(args=sys.argv[1:]): |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
93 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
94 # create option parser |
9
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
95 usage = '%prog [options] template <template> <...>' |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
96 parser = OptionParser(usage, description=__doc__) |
9
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
97 parser.add_option('--commandline', dest='commandline', |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
98 action='store_true', default=False, |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
99 help="print the commandline to invoke this script TTW") |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
100 parser.add_option('--variables', dest='variables', |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
101 action='store_true', default=False, |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
102 help='print the variables in a template') |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
103 options, args = parser.parse_args(args) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
104 |
9
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
105 # print the variables for the templates |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
106 if options.variables: |
9
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
107 |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
108 # makes no sense without a template |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
109 if not args: |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
110 parser.print_usage() |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
111 parser.exit() |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
112 |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
113 # find all variables |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
114 variables = set() |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
115 for arg in args: |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
116 content = file(arg).read() |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
117 template = Template(content) |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
118 variables.update(template_variables(template)) |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
119 |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
120 # print them |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
121 for variable in variables: |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
122 print variable |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
123 return |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
124 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
125 # template variables |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
126 variables = {} |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
127 _vars = [] |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
128 _args = [] |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
129 for arg in args: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
130 if '=' in arg: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
131 key, value = arg.split('=') |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
132 variables[key] = value |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
133 else: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
134 _args.append(arg) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
135 args = _args |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
136 |
9
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
137 # print TTW commandline for invocation |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
138 if options.commandline: |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
139 if args: |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
140 for arg in args: |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
141 print invocation(arg, **variables) |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
142 else: |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
143 print invocation('[URL]', **variables) |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
144 return |
a77630b2b491
* add commandline to print commandlines
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
145 |
5
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
146 # get the content |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
147 if args: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
148 for arg in args: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
149 content = file(arg).read() |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
150 substitute(content, variables=variables) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
151 else: |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
152 content = sys.stdin.read() |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
153 substitute(content, variables=variables) |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
154 |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
155 if __name__ == '__main__': |
f064be514e53
choose a better filename and remove some stuff from shebang
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
156 main() |