Commit e116c9ca authored by Stavros Sachtouris's avatar Stavros Sachtouris

Rename rogue methods in kamaki.cli.cmds (pep8)

DontRaire[KeyErrors/UnicodeErrors/etc] --> dont_raise(error type)
addLogSettings --> client_log
dataModification -->  fall_back
parent 74690507
......@@ -31,28 +31,36 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.command
from sys import stdin, stdout, stderr
from traceback import format_exc
from kamaki.cli.logger import get_logger
from kamaki.cli.utils import (
print_list, print_dict, print_json, print_items, ask_user, pref_enc,
filter_dicts_by_dict)
from kamaki.cli.argument import ValueArgument, ProgressBarArgument
from kamaki.cli.errors import CLIInvalidArgument, CLIBaseUrlError
from sys import stdin, stdout, stderr
log = get_logger(__name__)
def DontRaiseKeyError(func):
def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
except KeyError:
return None
return wrap
def dont_raise(*errors):
def decorator(func):
def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
except errors as e:
log.debug('Suppressed error %s while calling %s(%s)' % (
e, func.__name__, ','.join(['%s' % i for i in args] + [
('%s=%s' % items) for items in kwargs.items()])))
log.debug(format_exc(e))
return None
return wrap
return decorator
def addLogSettings(func):
def client_log(func):
def wrap(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
......@@ -61,7 +69,7 @@ def addLogSettings(func):
return wrap
def dataModification(func):
def fall_back(func):
def wrap(self, inp):
try:
inp = func(self, inp)
......@@ -122,6 +130,7 @@ class CommandInit(object):
raise CLIBaseUrlError(service=service)
return cls(URL, TOKEN)
@dont_raise(UnicodeError)
def write(self, s):
self._out.write(s.encode(pref_enc, errors='replace'))
self._out.flush()
......@@ -154,19 +163,19 @@ class CommandInit(object):
kwargs.setdefault('out', self)
return ask_user(*args, **kwargs)
@DontRaiseKeyError
@dont_raise(KeyError)
def _custom_url(self, service):
return self.config.get_cloud(self.cloud, '%s_url' % service)
@DontRaiseKeyError
@dont_raise(KeyError)
def _custom_token(self, service):
return self.config.get_cloud(self.cloud, '%s_token' % service)
@DontRaiseKeyError
@dont_raise(KeyError)
def _custom_type(self, service):
return self.config.get_cloud(self.cloud, '%s_type' % service)
@DontRaiseKeyError
@dont_raise(KeyError)
def _custom_version(self, service):
return self.config.get_cloud(self.cloud, '%s_version' % service)
......
......@@ -37,7 +37,7 @@ from os.path import abspath
from kamaki.cli import command
from kamaki.clients.astakos import LoggedAstakosClient
from kamaki.cli.cmds import (
CommandInit, NameFilter, OptionalOutput, errors, addLogSettings)
CommandInit, NameFilter, OptionalOutput, errors, client_log)
from kamaki.cli.cmdtree import CommandTree
from kamaki.cli.errors import (
CLIBaseUrlError, CLISyntaxError, CLIError, CLIInvalidArgument)
......@@ -92,7 +92,7 @@ class _AstakosInit(CommandInit):
@errors.Generic.all
@errors.Astakos.load
@errors.Astakos.astakosclient
@addLogSettings
@client_log
def _run(self):
if getattr(self, 'cloud', None):
base_url = self._custom_url('astakos')
......
......@@ -46,8 +46,8 @@ from kamaki.cli.argument import (
FlagArgument, ValueArgument, KeyValueArgument, RepeatableArgument,
DateArgument, IntArgument, StatusArgument)
from kamaki.cli.cmds import (
CommandInit, dataModification, OptionalOutput, NameFilter, IDFilter, Wait,
errors, addLogSettings, )
CommandInit, fall_back, OptionalOutput, NameFilter, IDFilter, Wait, errors,
client_log)
server_cmds = CommandTree('server', 'Cyclades/Compute API server commands')
......@@ -78,11 +78,11 @@ class _ServerWait(Wait):
class _CycladesInit(CommandInit):
@errors.Generic.all
@addLogSettings
@client_log
def _run(self):
self.client = self.get_client(CycladesComputeClient, 'cyclades')
@dataModification
@fall_back
def _restruct_server_info(self, vm):
if not vm:
return vm
......
......@@ -49,7 +49,7 @@ from kamaki.cli.argument import (
from kamaki.cli.cmds.cyclades import _CycladesInit
from kamaki.cli.errors import CLIError, raiseCLIError, CLIInvalidArgument
from kamaki.cli.cmds import (
CommandInit, errors, addLogSettings, OptionalOutput, NameFilter, IDFilter)
CommandInit, errors, client_log, OptionalOutput, NameFilter, IDFilter)
image_cmds = CommandTree('image', 'Cyclades/Plankton API image commands')
......@@ -76,7 +76,7 @@ log = getLogger(__name__)
class _ImageInit(CommandInit):
@errors.Generic.all
@addLogSettings
@client_log
def _run(self):
self.client = self.get_client(ImageClient, 'plankton')
......
......@@ -43,7 +43,7 @@ from kamaki.cli.argument import (
FlagArgument, ValueArgument, RepeatableArgument, IntArgument,
StatusArgument)
from kamaki.cli.cmds import (
CommandInit, OptionalOutput, NameFilter, IDFilter, errors, addLogSettings)
CommandInit, OptionalOutput, NameFilter, IDFilter, errors, client_log)
from kamaki.cli.cmds import Wait
......@@ -66,7 +66,7 @@ class _PortWait(Wait):
class _NetworkInit(CommandInit):
@errors.Generic.all
@addLogSettings
@client_log
def _run(self):
self.client = self.get_client(CycladesNetworkClient, 'network')
......
......@@ -41,8 +41,7 @@ from kamaki.clients.pithos import PithosClient, ClientError
from kamaki.cli import command
from kamaki.cli.cmdtree import CommandTree
from kamaki.cli.cmds import (
CommandInit, DontRaiseKeyError, OptionalOutput, NameFilter, errors,
addLogSettings)
CommandInit, dont_raise, OptionalOutput, NameFilter, errors, client_log)
from kamaki.cli.errors import (
CLIBaseUrlError, CLIError, CLIInvalidArgument, raiseCLIError,
CLISyntaxError)
......@@ -66,11 +65,11 @@ class _PithosInit(CommandInit):
There is always a default container (pithos)
"""
@DontRaiseKeyError
@dont_raise(KeyError)
def _custom_container(self):
return self.config.get_cloud(self.cloud, 'pithos_container')
@DontRaiseKeyError
@dont_raise(KeyError)
def _custom_uuid(self):
return self.config.get_cloud(self.cloud, 'pithos_uuid')
......@@ -85,7 +84,7 @@ class _PithosInit(CommandInit):
raise CLIBaseUrlError(service='astakos')
@errors.Generic.all
@addLogSettings
@client_log
def _run(self):
self.client = self.get_client(PithosClient, 'pithos')
self.base_url, self.token = self.client.base_url, self.client.token
......
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