# HG changeset patch # User Jeff Hammel # Date 1379469445 25200 # Node ID 90cb8aedecbb28c44cac9097299abba60a41f131 # Parent 919cee3e3ed0be71f72e0f8ee86378d36aa037f5 < http://k0s.org/mozilla/hg/MozillaTry/raw-file/582f3571ab33/mozillatry.py diff -r 919cee3e3ed0 -r 90cb8aedecbb configuration/configuration.py --- 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 <...>' + 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 diff -r 919cee3e3ed0 -r 90cb8aedecbb setup.py --- 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: