commit 3f0eae6184ff8a3b9c5234271cb03a9861fe9637
Author: Stavros Sachtouris <saxtouri@admin.grnet.gr>
Date:   Tue Jun 4 18:11:02 2013 +0300

    Implement the Config.guess_version method

diff --git a/kamaki/cli/__init__.py b/kamaki/cli/__init__.py
index a2916ea..ee477c3 100644
--- a/kamaki/cli/__init__.py
+++ b/kamaki/cli/__init__.py
@@ -202,6 +202,12 @@ def _init_session(arguments):
     global _verbose
     _verbose = arguments['verbose'].value
     _cnf = arguments['config']
+
+    guess = _cnf.value.guess_version()
+    if guess < 3.0:
+        print('PLEASE DO NOT PANIC: EXIT THE BUILDING QUIETLY')
+    raise CLIError('STOP HERE, PLEASE %s' % guess)
+
     global _colors
     _colors = _cnf.get('global', 'colors')
     if not (stdout.isatty() and _colors == 'on'):
@@ -259,13 +265,6 @@ def _groups_help(arguments):
         pkg = _load_spec_module(spec, arguments, '_commands')
         if pkg:
             cmds = getattr(pkg, '_commands')
-            #try:
-            #   #_cnf = arguments['config']
-            #   #cmds = [cmd for cmd in getattr(pkg, '_commands') if _cnf.get(
-            #   #    'cli', cmd.name)]
-            #except AttributeError:
-            #   if _debug:
-            #       kloger.warning('No description for %s' % cmd_group)
             try:
                 for cmd in cmds:
                     descriptions[cmd.name] = cmd.description
diff --git a/kamaki/cli/config.py b/kamaki/cli/config.py
index 4af40fd..09070b7 100644
--- a/kamaki/cli/config.py
+++ b/kamaki/cli/config.py
@@ -32,9 +32,11 @@
 # or implied, of GRNET S.A.
 
 import os
+from logging import getLogger
 
 from collections import defaultdict
 from ConfigParser import RawConfigParser, NoOptionError, NoSectionError
+from re import match
 
 try:
     from collections import OrderedDict
@@ -42,6 +44,8 @@ except ImportError:
     from kamaki.clients.utils.ordereddict import OrderedDict
 
 
+log = getLogger(__name__)
+
 # Path to the file that stores the configuration
 CONFIG_PATH = os.path.expanduser('~/.kamakirc')
 HISTORY_PATH = os.path.expanduser('~/.kamaki.history')
@@ -60,44 +64,67 @@ DEFAULTS = {
         'log_token': 'off',
         'log_data': 'off',
         'max_threads': 7,
-        'history_file': HISTORY_PATH
-    },
-    'cli': {
-        'user': 'astakos',
-        'file': 'pithos',
-        'server': 'cyclades',
-        'flavor': 'cyclades',
-        'network': 'cyclades',
-        'image': 'image',
-        'config': 'config',
-        'history': 'history'
+        'history_file': HISTORY_PATH,
+        'user_cli': 'astakos',
+        'file_cli': 'pithos',
+        'server_cli': 'cyclades',
+        'flavor_cli': 'cyclades',
+        'network_cli': 'cyclades',
+        'image_cli': 'image',
+        'config_cli': 'config',
+        'history_cli': 'history'
         #  Optional command specs:
         #  'livetest': 'livetest',
         #  'astakos': 'snf-astakos'
     },
-    'remote0': {
-        'remote_url': '',
-        'remote_token': ''
-        #'pithos_type': 'object-store',
-        #'pithos_version': 'v1',
-        #'cyclades_type': 'compute',
-        #'cyclades_version': 'v2.0',
-        #'image_type': 'image',
-        #'image_version': '',
-        #'astakos_type': 'identity',
-        #'astakos_version': 'v2.0'
+    'remotes':
+    {
+        'default': {
+            'url': '',
+            'token': ''
+            #'pithos_type': 'object-store',
+            #'pithos_version': 'v1',
+            #'cyclades_type': 'compute',
+            #'cyclades_version': 'v2.0',
+            #'plankton_type': 'image',
+            #'plankton_version': '',
+            #'astakos_type': 'identity',
+            #'astakos_version': 'v2.0'
+        }
     }
 }
 
 
 class Config(RawConfigParser):
-    def __init__(self, path=None):
+    def __init__(self, path=None, with_defaults=True):
         RawConfigParser.__init__(self, dict_type=OrderedDict)
         self.path = path or os.environ.get(CONFIG_ENV, CONFIG_PATH)
         self._overrides = defaultdict(dict)
-        self._load_defaults()
+        if with_defaults:
+            self._load_defaults()
         self.read(self.path)
 
+    @staticmethod
+    def _remote_name(full_section_name):
+        matcher = match('remote "(\w+)"', full_section_name)
+        return matcher.groups()[0] if matcher else None
+
+    def guess_version(self):
+        checker = Config(self.path, with_defaults=False)
+        sections = checker.sections()
+        log.warning('Config file heuristic 1: global section ?')
+        if 'global' in sections:
+            if checker.get('global', 'url') or checker.get('global', 'token'):
+                log.warning('..... config file has an old global section')
+                return 2.0
+        log.warning('Config file heuristic 2: at least 1 remote section ?')
+        for section in sections:
+            if self._remote_name(section):
+                log.warning('... found %s section' % section)
+                return 3.0
+        log.warning('All heuristics failed, cannot decide')
+        return 0.0
+
     def _load_defaults(self):
         for section, options in DEFAULTS.items():
             for option, val in options.items():
