Mercurial > hg > martINI
comparison martini/main.py @ 1:5627074cd79b
* adding ini-munge command
* bumping version
author | k0s <k0scist@gmail.com> |
---|---|
date | Tue, 08 Dec 2009 15:43:16 -0500 |
parents | 3c3522ce6e3a |
children | d172c078f4a2 |
comparison
equal
deleted
inserted
replaced
0:3c3522ce6e3a | 1:5627074cd79b |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 usage = "martini file1 [file2] [...] --section1 option1=value1 option2=value2 --section2 option3=value3" | 3 usage = "%s file1 [file2] [...] --section1 option1=value1 option2=value2 --section2 option3=value3" |
4 | 4 |
5 import config | 5 import config |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 | 8 |
59 files, sections = parse_options(*args) | 59 files, sections = parse_options(*args) |
60 | 60 |
61 # display usage information | 61 # display usage information |
62 if not files: | 62 if not files: |
63 print 'Usage:' | 63 print 'Usage:' |
64 print usage | 64 print usage % sys.argv[0] |
65 sys.exit(0) | 65 sys.exit(0) |
66 | 66 |
67 # process the files | 67 # process the files |
68 for f in files: | 68 for f in files: |
69 if f == '-': | 69 if f == '-': |
87 files, sections = parse_args(*args) | 87 files, sections = parse_args(*args) |
88 | 88 |
89 # display usage information | 89 # display usage information |
90 if not files: | 90 if not files: |
91 print 'Usage:' | 91 print 'Usage:' |
92 print usage | 92 print usage % sys.argv[0] |
93 sys.exit(0) | 93 sys.exit(0) |
94 | 94 |
95 # process the files | 95 # process the files |
96 for f in files: | 96 for f in files: |
97 if f == '-': | 97 if f == '-': |
117 files, sections = parse_args(*args) | 117 files, sections = parse_args(*args) |
118 | 118 |
119 # display usage information | 119 # display usage information |
120 if not files: | 120 if not files: |
121 print 'Usage:' | 121 print 'Usage:' |
122 print usage | 122 print usage % sys.argv[0] |
123 sys.exit(0) | 123 sys.exit(0) |
124 | 124 |
125 # process the files | 125 # process the files |
126 for f in files: | 126 for f in files: |
127 if f == '-': | 127 if f == '-': |
142 else: | 142 else: |
143 fp.close() | 143 fp.close() |
144 fp = file(f, 'w') | 144 fp = file(f, 'w') |
145 config.ConfigMunger(conf).write(fp) | 145 config.ConfigMunger(conf).write(fp) |
146 | 146 |
147 def munge(args=None): | |
148 | |
149 # process arguments | |
150 if args is None: | |
151 args = sys.argv[1:] | |
152 files, sections = parse_options(*args) | |
153 | |
154 # display usage information | |
155 if not files: | |
156 print 'Usage:' | |
157 print usage % sys.argv[0] | |
158 sys.exit(0) | |
159 | |
160 # munge the files | |
161 conf = list(files) | |
162 conf.append(sections) | |
163 munger = config.ConfigMunger(*conf) | |
164 munger.write(sys.stdout) | |
147 | 165 |
148 if __name__ == '__main__': | 166 if __name__ == '__main__': |
149 set(sys.argv[1:]) | 167 set(sys.argv[1:]) |