# HG changeset patch # User Jeff Hammel # Date 1376195639 25200 # Node ID 9b95f12fef360d77a2b554d904003b33ede265e2 # Parent 5f288c70acb6e78e2e6c6365b6eb29dc7c5c0495 python/hgrc.py diff -r 5f288c70acb6 -r 9b95f12fef36 python/hgrc.py --- a/python/hgrc.py Sat Aug 10 21:26:27 2013 -0700 +++ b/python/hgrc.py Sat Aug 10 21:33:59 2013 -0700 @@ -14,6 +14,7 @@ import urlparse from collections import OrderedDict from ConfigParser import RawConfigParser as ConfigParser +from StringIO import StringIO ### global methods @@ -86,6 +87,9 @@ parser.add_option('-p', '--print', dest='print_ini', action='store_true', default=False, help="print .ini contents") + parser.add_option('--dry-run', dest='dry_run', + action='store_true', default=False, + help="don't write to disk") options, args = parser.parse_args(args) # sanitization @@ -194,10 +198,17 @@ # print .hgrc files, if specified if print_ini: + values = [] for path, ini in config.items(): - print '+++ %s' % (path) - ini.write(sys.stdout) - print + _buffer = StringIO() + ini.write(_buffer) + values.append('+++ %s\n%s' % (path, _buffer.getvalue())) + print '\n'.join(values) + + # write .ini files + for path, ini in config.items(): + with file(path, 'w') as f: + ini.write(f) if __name__ == '__main__': main()