Commit 14b9a185 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Plan Config changes (rescue_old_file, translates)

Refs: #3934

rescue_old_file: mines info from old config file to use them in new file
  remote "smth" --> 'remote': {'smth': ...
  global.{url, token} --> remote.default.{url, token}
  <command>.cli --> global.command_cli
  some commands are maped to other names, e.g. pithos --> file
  <command>.url --> remote.defailt.<command>_url
parent 5482bc0a
......@@ -205,8 +205,24 @@ def _init_session(arguments):
guess = _cnf.value.guess_version()
if guess < 3.0:
raise CLIError('STOP HERE, PLEASE %s' % guess)
print('Missing an updated configuration file')
print('Updating configuration file without missing any information')
print('... ... ... DONE')
raise CLIError(
'Invalid configuration file %s' % _cnf.value.path,
importance=2, details=[
'Kamaki is now using a single authentication URL and token',
'To check if the single authentication URL is set:',
' /config get remote.default.token',
'To check if the single authentication token is set:',
' /config get remote.default.token',
'To set the default authentication URL and token:'
' /config set remote.default.url <URL>',
' /config set remote.default.token <token>'])
raise CLIError(
'Your file is OK, but kamaki is under contruction, sorry',
importance=3, details=['DO NOT PANIC, EXIT THE BUILDING QUIETLY'])
global _colors
_colors = _cnf.get('global', 'colors')
......@@ -104,28 +104,37 @@ class Config(RawConfigParser):
assert False, 'Config.__init__: translate remotes to dict first'
def _remote_name(full_section_name):
matcher = match('remote "(\w+)"', full_section_name)
return matcher.groups()[0] if matcher else None
def rescue_old_file(self):
# global.url, global.token --> remote.default.url, remote.default.token
# remove global.url, global.token
# translation for <service> or <command> settings
# <service> or <command group> settings --> translation --> global
def guess_version(self):
checker = Config(self.path, with_defaults=False)
sections = checker.sections()
log.warning('Config file heuristic 1: global section ?')
v = 0.0
if 'global' in sections:
if checker.get('global', 'url') or checker.get('global', 'token'):
log.warning('..... config file has an old global section')
v = 2.0
return 2.0
log.warning('........ nope')
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)
v = 3.0
return 3.0
log.warning('........ nope')
log.warning('All heuristics failed, cannot decide')
del checker
return v
return 0.0
def _load_defaults(self):
for section, options in DEFAULTS.items():
......@@ -185,4 +194,5 @@ class Config(RawConfigParser):
os.chmod(self.path, 0600)
assert False, 'Config.write: Trasnlate remotes to file first'
RawConfigParser.write(self, f)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment