Mercurial > hg > config
comparison python/hgrc.py @ 433:6797477f6a8f
adding conky
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Thu, 08 Aug 2013 09:36:04 -0700 |
| parents | ee8ab3de9c7f |
| children | ac7973ec485e |
comparison
equal
deleted
inserted
replaced
| 432:a9890ec0eab6 | 433:6797477f6a8f |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Script for modifying hgrc files. | 4 Script for modifying hgrc files. |
| 5 | 5 |
| 6 Actions: | 6 If no arguments specified, the repository given by `hg root` is used. |
| 7 (TBD) | |
| 8 """ | 7 """ |
| 8 | |
| 9 # imports | 9 # imports |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import subprocess | |
| 12 import sys | 13 import sys |
| 13 from ConfigParser import RawCOnfigParser as ConfigParser | 14 from ConfigParser import RawCOnfigParser as ConfigParser |
| 14 | 15 |
| 15 def main(args=sys.argv[1:]): | 16 def main(args=sys.argv[1:]): |
| 16 | 17 |
| 17 # command line parser | 18 # parse command line arguments |
| 18 usage = '%prog [options] repository <repository> <...>' | 19 usage = '%prog [options] repository <repository> <...>' |
| 19 parser = optparse.OptionParser(usage=usage, description=__doc__) | 20 parser = optparse.OptionParser(usage=usage, description=__doc__) |
| 20 parser.add_option('-p', '--print', dest='print_hgrc', | 21 parser.add_option('-l', '--list', dest='list_hgrc', |
| 21 action='store_true', default=False, | 22 action='store_true', default=False, |
| 22 help="print full path to hgrc files and exit") | 23 help="list full path to hgrc files") |
| 23 parser.add_option('--ssh', dest='default_push_ssh', | 24 parser.add_option('--ssh', dest='default_push_ssh', |
| 24 action='store_true', default=False, | 25 action='store_true', default=False, |
| 25 help="use `default` entries for `default-push`") | 26 help="use `default` entries for `default-push`") |
| 26 parser.add_option('--push', '--default-push', dest='default_push', | 27 parser.add_option('--push', '--default-push', dest='default_push', |
| 27 help="set [paths] default-push location") | 28 help="set [paths] default-push location") |
| 28 options, args = options.parse_args(args) | 29 options, args = options.parse_args(args) |
| 30 | |
| 31 # if not specified, use repo from `hg root` | |
| 29 if not args: | 32 if not args: |
| 30 parser.print_usage() | 33 args = [subprocess.check_output(['hg', 'root'])] |
| 31 parser.exit() | 34 |
| 35 # if not specified, set a default action | |
| 36 default_action = 'default_push_ssh' | |
| 37 actions = ('default_push', | |
| 38 'default_push_ssh', | |
| 39 ) | |
| 32 | 40 |
| 33 # find all hgrc files | 41 # find all hgrc files |
| 34 hgrc = [] | 42 hgrc = [] |
| 35 missing = [] | 43 missing = [] |
| 36 not_hg = [] | 44 not_hg = [] |
| 76 config[path].read(path) | 84 config[path].read(path) |
| 77 else: | 85 else: |
| 78 # XXX this code path is untenable | 86 # XXX this code path is untenable |
| 79 config[path]. | 87 config[path]. |
| 80 | 88 |
| 81 if options.print_hgrc: | 89 # print the chosen hgrc paths |
| 82 # print the chosen hgrc paths and you're done | 90 if options.list_hgrc: |
| 83 print '\n'.join(hgrc) | 91 print '\n'.join(hgrc) |
| 84 parser.exit() | 92 |
| 85 | 93 |
| 86 if __name__ == '__main__': | 94 if __name__ == '__main__': |
| 87 main() | 95 main() |
