Revision 852a22e7
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')), |
b/kamaki/cli/commands/cyclades_cli.py | ||
---|---|---|
431 | 431 |
new_mode = self.client.wait_server(server_id, |
432 | 432 |
currect_status, |
433 | 433 |
wait_cb=wait_cb) |
434 |
progress_bar.finish() |
|
434 | 435 |
except KeyboardInterrupt: |
435 | 436 |
print('\nCanceled') |
437 |
progress_bar.finish() |
|
436 | 438 |
return |
437 | 439 |
except ClientError as err: |
440 |
progress_bar.finish() |
|
438 | 441 |
raiseCLIError(err) |
439 | 442 |
if new_mode: |
440 | 443 |
print('\nServer %s is now in %s mode' % (server_id, new_mode)) |
b/kamaki/cli/commands/pithos_cli.py | ||
---|---|---|
502 | 502 |
self).main(container___path, path_is_optional=False) |
503 | 503 |
try: |
504 | 504 |
f = open(local_path, 'r') |
505 |
progress_bar = self.arguments['progress_bar'] |
|
505 | 506 |
try: |
506 |
progress_bar = self.arguments['progress_bar'] |
|
507 | 507 |
upload_cb = progress_bar.get_generator('Appending blocks') |
508 | 508 |
except Exception: |
509 | 509 |
upload_cb = None |
... | ... | |
511 | 511 |
source_file=f, |
512 | 512 |
upload_cb=upload_cb) |
513 | 513 |
except ClientError as err: |
514 |
progress_bar.finish() |
|
514 | 515 |
raiseCLIError(err) |
516 |
finally: |
|
517 |
progress_bar.finish() |
|
515 | 518 |
|
516 | 519 |
|
517 | 520 |
@command(pithos_cmds) |
... | ... | |
541 | 544 |
self).main(container___path, path_is_optional=False) |
542 | 545 |
try: |
543 | 546 |
f = open(local_path, 'r') |
547 |
progress_bar = self.arguments['progress_bar'] |
|
544 | 548 |
try: |
545 |
progress_bar = self.arguments['progress_bar'] |
|
546 | 549 |
upload_cb = progress_bar.get_generator('Overwritting blocks') |
547 | 550 |
except Exception: |
548 | 551 |
upload_cb = None |
... | ... | |
552 | 555 |
source_file=f, |
553 | 556 |
upload_cb=upload_cb) |
554 | 557 |
except ClientError as err: |
558 |
progress_bar.finish() |
|
555 | 559 |
raiseCLIError(err) |
560 |
finally: |
|
561 |
progress_bar.finish() |
|
556 | 562 |
|
557 | 563 |
|
558 | 564 |
@command(pithos_cmds) |
... | ... | |
629 | 635 |
sharing=self.get_argument('sharing'), |
630 | 636 |
public=self.get_argument('public')) |
631 | 637 |
try: |
638 |
progress_bar = self.arguments['progress_bar'] |
|
639 |
hash_bar = progress_bar.clone() |
|
632 | 640 |
with open(local_path) as f: |
633 | 641 |
if self.get_argument('unchunked'): |
634 | 642 |
self.client.upload_object_unchunked(remote_path, f, |
... | ... | |
636 | 644 |
withHashFile=self.get_argument('use_hashes'), |
637 | 645 |
**params) |
638 | 646 |
else: |
639 |
progress_bar = self.arguments['progress_bar'] |
|
640 |
hash_cb = progress_bar.get_generator(\ |
|
647 |
hash_cb = hash_bar.get_generator(\ |
|
641 | 648 |
'Calculating block hashes') |
642 | 649 |
upload_cb = progress_bar.get_generator('Uploading') |
643 | 650 |
self.client.upload_object(remote_path, f, |
644 |
hash_cb=hash_cb, |
|
645 |
upload_cb=upload_cb, |
|
646 |
**params) |
|
651 |
hash_cb=hash_cb, |
|
652 |
upload_cb=upload_cb, |
|
653 |
**params) |
|
654 |
progress_bar.finish() |
|
655 |
hash_bar.finish() |
|
647 | 656 |
except ClientError as err: |
657 |
progress_bar.finish() |
|
658 |
hash_bar.finish() |
|
648 | 659 |
raiseCLIError(err) |
649 | 660 |
except IOError as err: |
650 |
raise CLIError(message='Failed to read form file %s' % local_path, |
|
661 |
progress_bar.finish() |
|
662 |
hash_bar.finish() |
|
663 |
raise CLIError( |
|
664 |
message='Failed to read form file %s' % local_path, |
|
651 | 665 |
importance=2, |
652 | 666 |
details=unicode(err)) |
653 | 667 |
print 'Upload completed' |
... | ... | |
731 | 745 |
raise CLIError(message='Cannot write to file %s - %s'\ |
732 | 746 |
% (local_path, unicode(err)), |
733 | 747 |
importance=1) |
734 |
progress_bar = self.arguments['progress_bar'] |
|
735 |
download_cb = progress_bar.get_generator('Downloading') |
|
736 | 748 |
poolsize = self.get_argument('poolsize') |
737 | 749 |
if poolsize is not None: |
738 | 750 |
self.client.POOL_SIZE = int(poolsize) |
739 | 751 |
|
740 | 752 |
try: |
753 |
progress_bar = self.arguments['progress_bar'] |
|
754 |
download_cb = progress_bar.get_generator('Downloading') |
|
741 | 755 |
self.client.download_object(self.path, out, |
742 | 756 |
download_cb=download_cb, |
743 | 757 |
range=self.get_argument('range'), |
... | ... | |
747 | 761 |
if_none_match=self.get_argument('if_none_match'), |
748 | 762 |
if_modified_since=self.get_argument('if_modified_since'), |
749 | 763 |
if_unmodified_since=self.get_argument('if_unmodified_since')) |
764 |
progress_bar.finish() |
|
750 | 765 |
except ClientError as err: |
766 |
progress_bar.finish() |
|
751 | 767 |
raiseCLIError(err) |
752 | 768 |
except KeyboardInterrupt: |
753 | 769 |
from threading import enumerate as activethreads |
... | ... | |
759 | 775 |
stdout.write('.') |
760 | 776 |
except RuntimeError: |
761 | 777 |
continue |
778 |
progress_bar.finish() |
|
762 | 779 |
print('\ndownload canceled by user') |
763 | 780 |
if local_path is not None: |
764 | 781 |
print('to resume, re-run with --resume') |
782 |
except Exception as e: |
|
783 |
progress_bar.finish() |
|
784 |
raise e |
|
765 | 785 |
|
766 | 786 |
|
767 | 787 |
|
Also available in: Unified diff