changeset 122:90cb8aedecbb

< http://k0s.org/mozilla/hg/MozillaTry/raw-file/582f3571ab33/mozillatry.py
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 17 Sep 2013 18:57:25 -0700
parents 919cee3e3ed0
children bb0f58ae318e
files configuration/configuration.py setup.py
diffstat 2 files changed, 42 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/configuration.py	Thu Dec 06 16:16:03 2012 -0800
+++ b/configuration/configuration.py	Tue Sep 17 18:57:25 2013 -0700
@@ -574,3 +574,44 @@
                 continue
         else:
             raise ConfigurationProviderException("Could not load %s" % filename)
+
+class UserConfiguration(Configuration):
+    """`Configuration` class driven by a config file in user-space"""
+
+
+    # default configuration file
+    default_config_file = os.path.join('~', '.mozutils')
+    default_config_file_path = os.path.expanduser(default_config_file)
+    usage = '%prog [options] patch <patch2> <...>'
+    load_help = 'load from config file'
+    if os.path.exists(os.path.expanduser(default_config_file)):
+        load_help += ' [DEFAULT: %s]' % default_config_file
+
+    # configuration items to interpolate as paths
+    # TODO: moar bettur!
+    paths = []
+
+    def __init__(self):
+        Configuration.__init__(self, usage=self.usage, load='--config')
+
+    def validate(self):
+        Configuration.validate(self)
+        for path in self.paths:
+            self.config[path] = os.path.expanduser(self.config[path])
+
+    def configuration_files(self, options, args):
+        configuration_files = Configuration.configuration_files(self, options, args)
+        if not configuration_files:
+            # load user config only if no config provided
+            if os.path.exists(self.default_config_path):
+                configuration_files = [default_config]
+        return configuration_files
+
+    def load_configuration_file(self, filename):
+        config = Configuration.load_configuration_file(self, filename)
+
+        # ignore options that we don't care about
+        config = dict([(key, value) for key, value in config.items()
+                       if key in self.option_dict])
+
+        return config
--- a/setup.py	Thu Dec 06 16:16:03 2012 -0800
+++ b/setup.py	Tue Sep 17 18:57:25 2013 -0700
@@ -4,7 +4,7 @@
 
 import os
 
-version = "0.3.2"
+version = "0.4"
 dependencies = ['PyYAML']
 
 try: