# or implied, of GRNET S.A.
from kamaki.cli.config import Config
-from kamaki.cli.errors import CLISyntaxError, raiseCLIError
+from kamaki.cli.errors import (
+ CLISyntaxError, raiseCLIError, CLIInvalidArgument)
from kamaki.cli.utils import split_input, to_bytes
from datetime import datetime as dtm
raiseCLIError(e, 'KeyValueArgument Syntax Error')
+class StatusArgument(ValueArgument):
+ """Initialize with valid_states=['list', 'of', 'states']
+ First state is the default"""
+
+ def __init__(self, *args, **kwargs):
+ self.valid_states = kwargs.pop('valid_states', ['BUILD', ])
+ super(StatusArgument, self).__init__(*args, **kwargs)
+
+ @property
+ def value(self):
+ return getattr(self, '_value', None)
+
+ @value.setter
+ def value(self, new_status):
+ if new_status:
+ new_status = new_status.upper()
+ if new_status not in self.valid_states:
+ raise CLIInvalidArgument(
+ 'Invalid argument %s' % new_status, details=[
+ 'Usage: '
+ '%s=[%s]' % (self.lvalue, '|'.join(self.valid_states))])
+ self._value = new_status
+
+
class ProgressBarArgument(FlagArgument):
"""Manage a progress bar"""
if self.value:
return None
try:
- self.bar = KamakiProgressBar()
+ self.bar = KamakiProgressBar(
+ message.ljust(message_len), max=timeout or 100)
except NameError:
self.value = None
return self.value
self.bar.phases = bar_phases
self.bar.bar_prefix = ' '
self.bar.bar_suffix = ' '
- self.bar.max = timeout or 100
self.bar.suffix = '%(remaining)ds to timeout'
else:
self.bar.suffix = '%(percent)d%% - %(eta)ds'
- self.bar.eta = timeout or 100
- self.bar.message = message.ljust(message_len)
self.bar.start()
def progress_gen(n):