Move default config paths inside config module
authorGiorgos Verigakis <verigak@gmail.com>
Wed, 11 Apr 2012 10:58:15 +0000 (13:58 +0300)
committerGiorgos Verigakis <verigak@gmail.com>
Wed, 11 Apr 2012 10:58:15 +0000 (13:58 +0300)
kamaki/cli.py
kamaki/config.py

index 842ffa2..8e1476e 100755 (executable)
@@ -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:
index 696f0ef..a57832c 100644 (file)
@@ -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()