Mercurial > hg > config
comparison python/hgrc.py @ 489:9b95f12fef36
python/hgrc.py
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Sat, 10 Aug 2013 21:33:59 -0700 |
| parents | 5f288c70acb6 |
| children | 67404c3a4d75 |
comparison
equal
deleted
inserted
replaced
| 488:5f288c70acb6 | 489:9b95f12fef36 |
|---|---|
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import urlparse | 14 import urlparse |
| 15 from collections import OrderedDict | 15 from collections import OrderedDict |
| 16 from ConfigParser import RawConfigParser as ConfigParser | 16 from ConfigParser import RawConfigParser as ConfigParser |
| 17 from StringIO import StringIO | |
| 17 | 18 |
| 18 ### global methods | 19 ### global methods |
| 19 | 20 |
| 20 class section(object): | 21 class section(object): |
| 21 def __init__(self, section_name, *section_names): | 22 def __init__(self, section_name, *section_names): |
| 84 parser.add_option('-d', '--default', dest='default', | 85 parser.add_option('-d', '--default', dest='default', |
| 85 help="set [paths] default entry") | 86 help="set [paths] default entry") |
| 86 parser.add_option('-p', '--print', dest='print_ini', | 87 parser.add_option('-p', '--print', dest='print_ini', |
| 87 action='store_true', default=False, | 88 action='store_true', default=False, |
| 88 help="print .ini contents") | 89 help="print .ini contents") |
| 90 parser.add_option('--dry-run', dest='dry_run', | |
| 91 action='store_true', default=False, | |
| 92 help="don't write to disk") | |
| 89 options, args = parser.parse_args(args) | 93 options, args = parser.parse_args(args) |
| 90 | 94 |
| 91 # sanitization | 95 # sanitization |
| 92 if options.default_push and options.default_push_ssh: | 96 if options.default_push and options.default_push_ssh: |
| 93 parser.error("Cannot set --push and --ssh") | 97 parser.error("Cannot set --push and --ssh") |
| 192 else: | 196 else: |
| 193 method(ini, parameter) | 197 method(ini, parameter) |
| 194 | 198 |
| 195 # print .hgrc files, if specified | 199 # print .hgrc files, if specified |
| 196 if print_ini: | 200 if print_ini: |
| 201 values = [] | |
| 197 for path, ini in config.items(): | 202 for path, ini in config.items(): |
| 198 print '+++ %s' % (path) | 203 _buffer = StringIO() |
| 199 ini.write(sys.stdout) | 204 ini.write(_buffer) |
| 200 print | 205 values.append('+++ %s\n%s' % (path, _buffer.getvalue())) |
| 206 print '\n'.join(values) | |
| 207 | |
| 208 # write .ini files | |
| 209 for path, ini in config.items(): | |
| 210 with file(path, 'w') as f: | |
| 211 ini.write(f) | |
| 201 | 212 |
| 202 if __name__ == '__main__': | 213 if __name__ == '__main__': |
| 203 main() | 214 main() |
