changeset 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
files mozillatry.py setup.py
diffstat 2 files changed, 17 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mozillatry.py	Tue Dec 04 09:51:34 2012 -0800
+++ b/mozillatry.py	Tue Dec 04 11:09:45 2012 -0800
@@ -67,6 +67,8 @@
     return ' '.join(message)
 
 class MozillaTryConfiguration(configuration.Configuration):
+
+    usage = '%prog [options] patch <patch2> <...>'
     options = {'opt': {'default': True,
                        'help': "whether to try on opt builds"},
                'debug': {'default': True,
@@ -82,6 +84,19 @@
                                    'flags': ["--m-c", "--mozilla-central"]}
                }
 
+    def __init__(self):
+        configuration.Configuration.__init__(usage=self.usage, load='--config')
+
+    def check(self, parser, options, args):
+        """check configuration"""
+
+        if not args:
+            parser.print_help()
+            parser.exit()
+        if (not options.opt) and (not options.debug):
+            parser.error("Must enable opt or debug builds")
+
+
 def read_config(filename, options):
     """read .mozutils config file and substitute for options if None"""
 
@@ -101,33 +116,14 @@
             pass
     return parser
 
-def check(parser, options, args):
-    """check configuration"""
-
-    if not args:
-        parser.print_help()
-        parser.exit()
-    if (not options.opt) and (not options.debug):
-        parser.error("Must enable opt or debug builds")
 
 
 def main(args=sys.argv[1:]):
 
     # parse command line arguments
-    usage = '%prog [options] patch <patch2> <...>'
-    class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
-        """description formatter"""
-        def format_description(self, description):
-            description = description.strip()
-            if description:
-                return description + '\n'
-            else:
-                return ''
-    config_file = options.config
-    read_config(config_file)
+    config = MozillaTryConfiguration()
 
     # get mozilla-central repository directory
-    if os.path.exists(config_file):
     try_directory = options.mozilla_central
     if (try_directory is None) or (not os.path.exists(try_directory)):
         parser.error("mozilla-central directory does not exist: %s" % try_directory)
--- a/setup.py	Tue Dec 04 09:51:34 2012 -0800
+++ b/setup.py	Tue Dec 04 11:09:45 2012 -0800
@@ -9,7 +9,7 @@
 
 version = '0.0'
 
-deps = []
+deps = ['configuration']
 
 setup(name='mozillatry',
       version=version,