Revision 852a22e7 kamaki/cli/argument.py

b/kamaki/cli/argument.py
233 233
        self.suffix = '%(percent)d%%'
234 234
        super(ProgressBarArgument, self).__init__(help, parsed_name, default)
235 235
        try:
236
            self.bar = IncrementalBar()
236
            IncrementalBar
237 237
        except NameError:
238 238
            print('Waring: no progress bar functionality')
239 239

  
240
    def clone(self):
241
        newarg = ProgressBarArgument(
242
            self.help,
243
            self.parsed_name,
244
            self.default)
245
        newarg._value = self._value
246
        return newarg
247

  
240 248
    def get_generator(self, message, message_len=25):
241 249
        if self.value:
242 250
            return None
251
        self.bar = IncrementalBar()
243 252
        try:
244
            bar = ProgressBar(message.ljust(message_len))
253
            self.bar.message = message.ljust(message_len)
245 254
        except NameError:
246
            return None
247
        return bar.get_generator()
255
            pass
256
        self.bar.suffix = '%(percent)d%% - %(eta)ds'
248 257

  
258
        def progress_gen(n):
259
            for i in self.bar.iter(range(int(n))):
260
                yield
261
            yield
262
        return progress_gen
249 263

  
250
try:
251
    class ProgressBar(IncrementalBar):
252
        suffix = '%(percent)d%% - %(eta)ds'
264
    def finish(self):
265
        if self.value:
266
            return
267
        mybar = getattr(self, 'bar', None)
268
        if mybar:
269
            mybar.finish()
253 270

  
254
        def get_generator(self):
255
            def progress_gen(n):
256
                for i in self.iter(range(int(n))):
257
                    yield
258
                yield
259
            return progress_gen
260
except NameError:
261
    pass
262 271

  
263 272
_arguments = dict(config=_config_arg,
264 273
    help=Argument(0, 'Show help message', ('-h', '--help')),

Also available in: Unified diff