annotate python/hgrc.py @ 348:6004e00b602d

new hg file; TODO: incorporate!
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 26 Jun 2013 17:39:15 -0700
parents
children 52e718567731
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
348
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 '''
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 '''
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import optparse
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import os
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 here = os.path.dirname(os.path.realpath(__file__))
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 def main(args=sys.argv[1:]):
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 usage = '%prog [options] repository <repository> <...>'
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 parser = optparse.OptionParser(usage=usage, description=__doc__)
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 parser.add_option('--ssh', dest='default_push_ssh',
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 action='store_true', default=False,
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 help="")
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 options, args = options.parse_args(args)
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 if not args:
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 parser.print_usage()
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 parser.exit()
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 # find all .hgrc files
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 hgrc = []
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 # all the error types
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 missing = []
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 not_hg = []
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 not_a_directory = []
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 for path in args:
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 if not os.path.exists(path):
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 missing.append(path)
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 path = os.path.abspath(os.path.normpath(path))
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 if os.path.isdir(path):
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 basename = os.path.basename(path)
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 subhgdir = os.path.join(path, '.hg') # hypothetical .hg subdirectory
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 if basename == '.hg':
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 hgrcpath = os.path.join(path, 'hgrc')
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 elif os.path.exists(subhgdir):
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 if not os.path.isdir(subhgdir):
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 not_a_directory.append(subhgdir)
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 continue
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 else:
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 not_hg.append(path)
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 continue
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 if __name__ == '__main__':
6004e00b602d new hg file; TODO: incorporate!
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 main()