Mercurial > hg > config
comparison python/hgrc.py @ 350:52e718567731
minor improvements
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Thu, 27 Jun 2013 00:04:12 -0700 |
| parents | 6004e00b602d |
| children | 971e7deca495 |
comparison
equal
deleted
inserted
replaced
| 349:8161806daa20 | 350:52e718567731 |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 ''' | 3 """ |
| 4 Script for modifying hgrc files. | |
| 4 | 5 |
| 5 ''' | 6 Actions: |
| 7 (TBD) | |
| 8 """ | |
| 6 | 9 |
| 7 import optparse | 10 import optparse |
| 8 import os | 11 import os |
| 9 import sys | 12 import sys |
| 10 | 13 |
| 11 here = os.path.dirname(os.path.realpath(__file__)) | 14 here = os.path.dirname(os.path.realpath(__file__)) |
| 12 | 15 |
| 13 def main(args=sys.argv[1:]): | 16 def main(args=sys.argv[1:]): |
| 14 | 17 |
| 18 # command line parser | |
| 15 usage = '%prog [options] repository <repository> <...>' | 19 usage = '%prog [options] repository <repository> <...>' |
| 16 parser = optparse.OptionParser(usage=usage, description=__doc__) | 20 parser = optparse.OptionParser(usage=usage, description=__doc__) |
| 21 parser.add_option('-p', '--print', dest='print', | |
| 22 action='store_true', default=False, | |
| 23 help="print full path to hgrc files and exit") | |
| 17 parser.add_option('--ssh', dest='default_push_ssh', | 24 parser.add_option('--ssh', dest='default_push_ssh', |
| 18 action='store_true', default=False, | 25 action='store_true', default=False, |
| 19 help="") | 26 help="use `default` entries for `default-push`") |
| 20 options, args = options.parse_args(args) | 27 options, args = options.parse_args(args) |
| 21 if not args: | 28 if not args: |
| 22 parser.print_usage() | 29 parser.print_usage() |
| 23 parser.exit() | 30 parser.exit() |
| 24 | 31 |
| 25 # find all .hgrc files | 32 # find all .hgrc files |
| 26 hgrc = [] | 33 hgrc = [] |
| 27 | |
| 28 # all the error types | |
| 29 missing = [] | 34 missing = [] |
| 30 not_hg = [] | 35 not_hg = [] |
| 31 not_a_directory = [] | 36 not_a_directory = [] |
| 32 | 37 errors = {'Missing path': missing, |
| 38 'Not a mercurial directory': not_hg, | |
| 39 'Not a directory': not_a_directory, | |
| 40 } | |
| 33 for path in args: | 41 for path in args: |
| 34 if not os.path.exists(path): | 42 if not os.path.exists(path): |
| 35 missing.append(path) | 43 missing.append(path) |
| 36 path = os.path.abspath(os.path.normpath(path)) | 44 path = os.path.abspath(os.path.normpath(path)) |
| 37 if os.path.isdir(path): | 45 if os.path.isdir(path): |
| 44 not_a_directory.append(subhgdir) | 52 not_a_directory.append(subhgdir) |
| 45 continue | 53 continue |
| 46 else: | 54 else: |
| 47 not_hg.append(path) | 55 not_hg.append(path) |
| 48 continue | 56 continue |
| 49 | 57 else: |
| 58 assert os.path.isfile(path), "%s is not a file, exiting" % path | |
| 50 | 59 |
| 51 | 60 |
| 52 if __name__ == '__main__': | 61 if __name__ == '__main__': |
| 53 main() | 62 main() |
