From a72a0929928e2cfdbf2ace492e6e6dd9fd07c2f2 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 2 Sep 2010 15:23:07 -0400 Subject: [PATCH] Added --config option to bin/hk.py to override built in config file path. --- doc/config.txt | 4 +--- hooke/config.py | 2 +- hooke/hooke.py | 8 ++++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/config.txt b/doc/config.txt index 6b72780..4d7540b 100644 --- a/doc/config.txt +++ b/doc/config.txt @@ -44,12 +44,10 @@ default path list is * :file:`./.hooke.cfg` but alternatives can be specified from the command line launching -Hooke. +Hooke (``--config FILE``). .. _Filesystem Hierarchy Standard: http://www.pathname.com/fhs/ -.. todo:: Implement command-line specified config file. - .. warning:: Any changes you make to the configuration during a Hooke run will *not be saved* when Hooke exits. To save the changes, either run the `save config` command before closing Hooke, or start diff --git a/hooke/config.py b/hooke/config.py index a8d006d..d49841d 100644 --- a/hooke/config.py +++ b/hooke/config.py @@ -234,7 +234,7 @@ class HookeConfigParser (configparser.RawConfigParser): self._config_paths.append(filename) # Can't use super() because RawConfigParser is a classic class #return super(HookeConfigParser, self).read(filenames) - return configparser.RawConfigParser.read(self, filenames) + return configparser.RawConfigParser.read(self, self._config_paths) def _write_setting(self, fp, section=None, option=None, value=None, **kwargs): diff --git a/hooke/hooke.py b/hooke/hooke.py index 617ad92..1942ac9 100644 --- a/hooke/hooke.py +++ b/hooke/hooke.py @@ -101,6 +101,8 @@ class Hooke (object): # Don't attach the logger because it contains an unpicklable # thread.lock. Instead, grab it directly every time you need it. #self.log = logging.getLogger('hooke') + log = logging.getLogger('hooke') + log.debug('config paths: %s' % self.config._config_paths) def load_plugins(self): self.plugins = plugin_mod.load_graph( @@ -230,6 +232,9 @@ def main(): p.add_option( '-u', '--ui', dest='user_interface', help="Override the configured user interface (for easy switching).") + p.add_option( + '--config', dest='config', metavar='FILE', + help="Override the default config file chain.") p.add_option( '--save-config', dest='save_config', action='store_true', default=False, @@ -243,6 +248,9 @@ def main(): % (sys.argv[0], arguments) p.print_help(sys.stderr) sys.exit(1) + if options.config != None: + config_mod.DEFAULT_PATHS = [ + os.path.abspath(os.path.expanduser(options.config))] hooke = Hooke(debug=__debug__) runner = HookeRunner() -- 2.26.2