From d83a28343b738a46e28e0b356e55fee3fe6c0b69 Mon Sep 17 00:00:00 2001 From: Giorgos Verigakis Date: Wed, 11 Apr 2012 13:58:15 +0300 Subject: [PATCH] Move default config paths inside config module --- kamaki/cli.py | 17 ++++------------- kamaki/config.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/kamaki/cli.py b/kamaki/cli.py index 842ffa2..8e1476e 100755 --- a/kamaki/cli.py +++ b/kamaki/cli.py @@ -73,7 +73,7 @@ import os from base64 import b64encode from grp import getgrgid from optparse import OptionParser -from os.path import abspath, basename, exists, expanduser +from os.path import abspath, basename, exists from pwd import getpwuid from sys import argv, exit, stdout @@ -89,13 +89,6 @@ from kamaki.config import Config from kamaki.utils import OrderedDict, print_addresses, print_dict, print_items -# Path to the file that stores the configuration -CONFIG_PATH = expanduser('~/.kamakirc') - -# Name of a shell variable to bypass the CONFIG_PATH value -CONFIG_ENV = 'KAMAKI_CONFIG' - - _commands = OrderedDict() @@ -878,12 +871,10 @@ def main(): exit(0) if '--config' in args: - config_path = args.grouped['--config'].get(0) + config = Config(args.grouped['--config'].get(0)) else: - config_path = os.environ.get(CONFIG_ENV, CONFIG_PATH) - - config = Config(config_path) - + config = Config() + for option in args.grouped.get('-o', []): keypath, sep, val = option.partition('=') if not sep: diff --git a/kamaki/config.py b/kamaki/config.py index 696f0ef..a57832c 100644 --- a/kamaki/config.py +++ b/kamaki/config.py @@ -39,6 +39,12 @@ from ConfigParser import RawConfigParser, NoOptionError, NoSectionError from .utils import OrderedDict +# Path to the file that stores the configuration +CONFIG_PATH = os.path.expanduser('~/.kamakirc') + +# Name of a shell variable to bypass the CONFIG_PATH value +CONFIG_ENV = 'KAMAKI_CONFIG' + HEADER = """ # Kamaki configuration file """ @@ -78,9 +84,9 @@ DEFAULTS = { class Config(RawConfigParser): def __init__(self, path=None): RawConfigParser.__init__(self, dict_type=OrderedDict) - self.path = path + self.path = path or os.environ.get(CONFIG_ENV, CONFIG_PATH) self._overrides = defaultdict(dict) - self.read(path) + self.read(self.path) def sections(self): return DEFAULTS.keys() -- 1.7.10.4