Mercurial > mozilla > hg > MozillaTry
comparison mozillatry.py @ 5:416f4562005c
more switching to configuration parser
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 04 Dec 2012 11:09:45 -0800 |
parents | 14275dcbff10 |
children | 6f35d0d90c64 |
comparison
equal
deleted
inserted
replaced
4:14275dcbff10 | 5:416f4562005c |
---|---|
65 if bug: | 65 if bug: |
66 message += ['--post-to-bugzilla', str(bug)] | 66 message += ['--post-to-bugzilla', str(bug)] |
67 return ' '.join(message) | 67 return ' '.join(message) |
68 | 68 |
69 class MozillaTryConfiguration(configuration.Configuration): | 69 class MozillaTryConfiguration(configuration.Configuration): |
70 | |
71 usage = '%prog [options] patch <patch2> <...>' | |
70 options = {'opt': {'default': True, | 72 options = {'opt': {'default': True, |
71 'help': "whether to try on opt builds"}, | 73 'help': "whether to try on opt builds"}, |
72 'debug': {'default': True, | 74 'debug': {'default': True, |
73 'help': "whether to try on debug builds"}, | 75 'help': "whether to try on debug builds"}, |
74 'unittests': {'default': [], | 76 'unittests': {'default': [], |
79 'flags': ['-t', '--talostests']}, | 81 'flags': ['-t', '--talostests']}, |
80 'mozilla_central': {'help': "path to mozilla-central clone", | 82 'mozilla_central': {'help': "path to mozilla-central clone", |
81 'required': True, | 83 'required': True, |
82 'flags': ["--m-c", "--mozilla-central"]} | 84 'flags': ["--m-c", "--mozilla-central"]} |
83 } | 85 } |
86 | |
87 def __init__(self): | |
88 configuration.Configuration.__init__(usage=self.usage, load='--config') | |
89 | |
90 def check(self, parser, options, args): | |
91 """check configuration""" | |
92 | |
93 if not args: | |
94 parser.print_help() | |
95 parser.exit() | |
96 if (not options.opt) and (not options.debug): | |
97 parser.error("Must enable opt or debug builds") | |
98 | |
84 | 99 |
85 def read_config(filename, options): | 100 def read_config(filename, options): |
86 """read .mozutils config file and substitute for options if None""" | 101 """read .mozutils config file and substitute for options if None""" |
87 | 102 |
88 # XXX stub; this should really use | 103 # XXX stub; this should really use |
99 options.mozilla_central = os.path.expanduser(path) | 114 options.mozilla_central = os.path.expanduser(path) |
100 except Exception: # XXX temporary hack | 115 except Exception: # XXX temporary hack |
101 pass | 116 pass |
102 return parser | 117 return parser |
103 | 118 |
104 def check(parser, options, args): | |
105 """check configuration""" | |
106 | |
107 if not args: | |
108 parser.print_help() | |
109 parser.exit() | |
110 if (not options.opt) and (not options.debug): | |
111 parser.error("Must enable opt or debug builds") | |
112 | 119 |
113 | 120 |
114 def main(args=sys.argv[1:]): | 121 def main(args=sys.argv[1:]): |
115 | 122 |
116 # parse command line arguments | 123 # parse command line arguments |
117 usage = '%prog [options] patch <patch2> <...>' | 124 config = MozillaTryConfiguration() |
118 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): | |
119 """description formatter""" | |
120 def format_description(self, description): | |
121 description = description.strip() | |
122 if description: | |
123 return description + '\n' | |
124 else: | |
125 return '' | |
126 config_file = options.config | |
127 read_config(config_file) | |
128 | 125 |
129 # get mozilla-central repository directory | 126 # get mozilla-central repository directory |
130 if os.path.exists(config_file): | |
131 try_directory = options.mozilla_central | 127 try_directory = options.mozilla_central |
132 if (try_directory is None) or (not os.path.exists(try_directory)): | 128 if (try_directory is None) or (not os.path.exists(try_directory)): |
133 parser.error("mozilla-central directory does not exist: %s" % try_directory) | 129 parser.error("mozilla-central directory does not exist: %s" % try_directory) |
134 | 130 |
135 # build try syntax | 131 # build try syntax |