comparison mozillatry.py @ 2:3eaee0d10880

make getting mozilla-central slightly less of a hack; soon, we should transition to configuration to make this nice, though lets build the API around it first for now
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 01 Dec 2012 23:05:19 -0800
parents 0f8e4a3b4e1c
children 7495c25d8476
comparison
equal deleted inserted replaced
1:0f8e4a3b4e1c 2:3eaee0d10880
7 import optparse 7 import optparse
8 import os 8 import os
9 import sys 9 import sys
10 10
11 from subprocess import check_call as call 11 from subprocess import check_call as call
12
13 def config(filename):
14 """read .mozutils.ini config file"""
15 # XXX stub; this should really use
16 # e.g. http://k0s.org/mozilla/hg/configuration/
17 from ConfigParser import ConfigParser
18 parser = ConfigParser()
19 parser.read(filename)
20 return os.path.expanduser(parser.get('hg', 'mozilla-central'))
21 12
22 def reset(directory): 13 def reset(directory):
23 """reset an hg directory to a good state""" 14 """reset an hg directory to a good state"""
24 assert os.path.exists(directory) and os.path.isdir(directory) 15 assert os.path.exists(directory) and os.path.isdir(directory)
25 hg_dir = os.path.join(directory, '.hg') 16 hg_dir = os.path.join(directory, '.hg')
90 parser.add_option('--bug', dest='bug', type='int', 81 parser.add_option('--bug', dest='bug', type='int',
91 help='post to bugzilla bug #') 82 help='post to bugzilla bug #')
92 parser.add_option('-c', '--config', dest='config', 83 parser.add_option('-c', '--config', dest='config',
93 default=os.path.join(os.environ['HOME'], '.mozutils.ini'), 84 default=os.path.join(os.environ['HOME'], '.mozutils.ini'),
94 help='location of config file') 85 help='location of config file')
86 parser.add_option('-m', '--m-c', '--mozilla-central',
87 help="path to mozilla-central repository")
88
89
90 def read_config(filename, options):
91 """read .mozutils config file and substitute for options if None"""
92
93 # XXX stub; this should really use
94 # e.g. http://k0s.org/mozilla/hg/configuration/
95 from ConfigParser import ConfigParser
96 parser = ConfigParser()
97 parser.read(filename)
98 if options.mozilla_central is None:
99 try:
100 path = parser.get('hg', 'mozilla-central')
101 os.path.expanduser(path)
102 except Exception: # XXX temporary hack
103 pass
104 return parser
95 105
96 106
97 def main(args=sys.argv[1:]): 107 def main(args=sys.argv[1:]):
98 108
99 # parse command line arguments 109 # parse command line arguments
115 if (not options.opt) and (not options.debug): 125 if (not options.opt) and (not options.debug):
116 parser.error("Must enable opt or debug builds") 126 parser.error("Must enable opt or debug builds")
117 127
118 # get mozilla-central repository directory 128 # get mozilla-central repository directory
119 config_file = options.__dict__.pop('config') 129 config_file = options.__dict__.pop('config')
120 if not os.path.exists(config_file): 130 if os.path.exists(config_file):
121 parser.error("You need a config file at ~/.mozutils.ini") 131 read_config(config_file)
122 try_directory = config(config_file) # XXX temporary hack 132 try_directory = options.mozilla_central
123 if not os.path.exists(try_directory): 133 if (try_directory is None) or (not os.path.exists(try_directory)):
124 parser.error("mozilla-central try directory does not exist: %s" % try_directory) 134 parser.error("mozilla-central try directory does not exist: %s" % try_directory)
125 135
126 # build try syntax 136 # build try syntax
127 commit = try_syntax(**options.__dict__) 137 commit = try_syntax(**options.__dict__)
128 print commit 138 print commit