X-Git-Url: https://code.grnet.gr/git/kamaki/blobdiff_plain/c22183b968a2e6b4c49dc93b4aa7ab2d518c3a46..099b433bc93cdbcbed6984690e00289995a7b3e0:/kamaki/cli/argument/__init__.py diff --git a/kamaki/cli/argument/__init__.py b/kamaki/cli/argument/__init__.py index 7b434ed..f2dca9b 100644 --- a/kamaki/cli/argument/__init__.py +++ b/kamaki/cli/argument/__init__.py @@ -32,7 +32,8 @@ # 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 @@ -375,6 +376,30 @@ class KeyValueArgument(Argument): 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""" @@ -395,7 +420,8 @@ class ProgressBarArgument(FlagArgument): 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 @@ -406,12 +432,9 @@ class ProgressBarArgument(FlagArgument): 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):