Mercurial > hg > configuration
changeset 123:bb0f58ae318e
configuration/configuration.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 17 Sep 2013 20:13:16 -0700 |
parents | 90cb8aedecbb |
children | 5db2844b8300 |
files | configuration/configuration.py |
diffstat | 1 files changed, 11 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/configuration/configuration.py Tue Sep 17 18:57:25 2013 -0700 +++ b/configuration/configuration.py Tue Sep 17 20:13:16 2013 -0700 @@ -578,21 +578,20 @@ 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 __init__(self, config=None, load='--config'): + + # default configuration file + self.config_name = config or '.' + os.path.splitext(sys.argv[0])[0] + self.default_config_file = os.path.join('~', self.config_name) + self.default_config_file_path = os.path.expanduser(self.default_config_file) + if os.path.exists(self.default_config_file_path) + self.load_help += ' [DEFAULT: %s]' % default_config_file + + Configuration.__init__(self, usage=self.usage, load=load) def validate(self): Configuration.validate(self) @@ -603,7 +602,7 @@ 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): + if os.path.exists(self.default_config_file_path): configuration_files = [default_config] return configuration_files