Revision 60edf71e tools/cfgupgrade
b/tools/cfgupgrade | ||
---|---|---|
130 | 130 |
return _BaseFindGlobal(module, name) |
131 | 131 |
|
132 | 132 |
|
133 |
def WriteConfig(path, data): |
|
133 |
def WriteConfig(path, data, dry_run):
|
|
134 | 134 |
"""Writes the configuration file. |
135 | 135 |
|
136 | 136 |
""" |
... | ... | |
155 | 155 |
dumper = cPickle.Pickler(f, cPickle.HIGHEST_PROTOCOL) |
156 | 156 |
dumper.dump(data) |
157 | 157 |
f.flush() |
158 |
os.rename(name, path) |
|
158 |
if dry_run: |
|
159 |
os.unlink(name) |
|
160 |
else: |
|
161 |
os.rename(name, path) |
|
159 | 162 |
except: |
160 | 163 |
os.unlink(name) |
161 | 164 |
raise |
... | ... | |
189 | 192 |
if __name__ == "__main__": |
190 | 193 |
# Option parsing |
191 | 194 |
parser = optparse.OptionParser() |
195 |
parser.add_option('--dry-run', dest='dry_run', |
|
196 |
action="store_true", |
|
197 |
help="Try to do the conversion, but don't write " |
|
198 |
"output file") |
|
192 | 199 |
parser.add_option('--verbose', dest='verbose', |
193 | 200 |
action="store_true", |
194 | 201 |
help="Verbose output") |
... | ... | |
208 | 215 |
import pprint |
209 | 216 |
pprint.pprint(config) |
210 | 217 |
|
211 |
WriteConfig(cfg_file, config) |
|
218 |
WriteConfig(cfg_file, config, options.dry_run) |
Also available in: Unified diff