Commit 852a22e7 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Upgrade progress compatibility to 1.0.2

New progress uses a different interface with start and finish methods
that they are now used
parent 8eb8c540
......@@ -233,32 +233,41 @@ class ProgressBarArgument(FlagArgument):
self.suffix = '%(percent)d%%'
super(ProgressBarArgument, self).__init__(help, parsed_name, default)
try:
self.bar = IncrementalBar()
IncrementalBar
except NameError:
print('Waring: no progress bar functionality')
def clone(self):
newarg = ProgressBarArgument(
self.help,
self.parsed_name,
self.default)
newarg._value = self._value
return newarg
def get_generator(self, message, message_len=25):
if self.value:
return None
self.bar = IncrementalBar()
try:
bar = ProgressBar(message.ljust(message_len))
self.bar.message = message.ljust(message_len)
except NameError:
return None
return bar.get_generator()
pass
self.bar.suffix = '%(percent)d%% - %(eta)ds'
def progress_gen(n):
for i in self.bar.iter(range(int(n))):
yield
yield
return progress_gen
try:
class ProgressBar(IncrementalBar):
suffix = '%(percent)d%% - %(eta)ds'
def finish(self):
if self.value:
return
mybar = getattr(self, 'bar', None)
if mybar:
mybar.finish()
def get_generator(self):
def progress_gen(n):
for i in self.iter(range(int(n))):
yield
yield
return progress_gen
except NameError:
pass
_arguments = dict(config=_config_arg,
help=Argument(0, 'Show help message', ('-h', '--help')),
......
......@@ -431,10 +431,13 @@ class server_wait(_init_cyclades):
new_mode = self.client.wait_server(server_id,
currect_status,
wait_cb=wait_cb)
progress_bar.finish()
except KeyboardInterrupt:
print('\nCanceled')
progress_bar.finish()
return
except ClientError as err:
progress_bar.finish()
raiseCLIError(err)
if new_mode:
print('\nServer %s is now in %s mode' % (server_id, new_mode))
......
......@@ -502,8 +502,8 @@ class store_append(_store_container_command):
self).main(container___path, path_is_optional=False)
try:
f = open(local_path, 'r')
progress_bar = self.arguments['progress_bar']
try:
progress_bar = self.arguments['progress_bar']
upload_cb = progress_bar.get_generator('Appending blocks')
except Exception:
upload_cb = None
......@@ -511,7 +511,10 @@ class store_append(_store_container_command):
source_file=f,
upload_cb=upload_cb)
except ClientError as err:
progress_bar.finish()
raiseCLIError(err)
finally:
progress_bar.finish()
@command(pithos_cmds)
......@@ -541,8 +544,8 @@ class store_overwrite(_store_container_command):
self).main(container___path, path_is_optional=False)
try:
f = open(local_path, 'r')
progress_bar = self.arguments['progress_bar']
try:
progress_bar = self.arguments['progress_bar']
upload_cb = progress_bar.get_generator('Overwritting blocks')
except Exception:
upload_cb = None
......@@ -552,7 +555,10 @@ class store_overwrite(_store_container_command):
source_file=f,
upload_cb=upload_cb)
except ClientError as err:
progress_bar.finish()
raiseCLIError(err)
finally:
progress_bar.finish()
@command(pithos_cmds)
......@@ -629,6 +635,8 @@ class store_upload(_store_container_command):
sharing=self.get_argument('sharing'),
public=self.get_argument('public'))
try:
progress_bar = self.arguments['progress_bar']
hash_bar = progress_bar.clone()
with open(local_path) as f:
if self.get_argument('unchunked'):
self.client.upload_object_unchunked(remote_path, f,
......@@ -636,18 +644,24 @@ class store_upload(_store_container_command):
withHashFile=self.get_argument('use_hashes'),
**params)
else:
progress_bar = self.arguments['progress_bar']
hash_cb = progress_bar.get_generator(\
hash_cb = hash_bar.get_generator(\
'Calculating block hashes')
upload_cb = progress_bar.get_generator('Uploading')
self.client.upload_object(remote_path, f,
hash_cb=hash_cb,
upload_cb=upload_cb,
**params)
hash_cb=hash_cb,
upload_cb=upload_cb,
**params)
progress_bar.finish()
hash_bar.finish()
except ClientError as err:
progress_bar.finish()
hash_bar.finish()
raiseCLIError(err)
except IOError as err:
raise CLIError(message='Failed to read form file %s' % local_path,
progress_bar.finish()
hash_bar.finish()
raise CLIError(
message='Failed to read form file %s' % local_path,
importance=2,
details=unicode(err))
print 'Upload completed'
......@@ -731,13 +745,13 @@ class store_download(_store_container_command):
raise CLIError(message='Cannot write to file %s - %s'\
% (local_path, unicode(err)),
importance=1)
progress_bar = self.arguments['progress_bar']
download_cb = progress_bar.get_generator('Downloading')
poolsize = self.get_argument('poolsize')
if poolsize is not None:
self.client.POOL_SIZE = int(poolsize)
try:
progress_bar = self.arguments['progress_bar']
download_cb = progress_bar.get_generator('Downloading')
self.client.download_object(self.path, out,
download_cb=download_cb,
range=self.get_argument('range'),
......@@ -747,7 +761,9 @@ class store_download(_store_container_command):
if_none_match=self.get_argument('if_none_match'),
if_modified_since=self.get_argument('if_modified_since'),
if_unmodified_since=self.get_argument('if_unmodified_since'))
progress_bar.finish()
except ClientError as err:
progress_bar.finish()
raiseCLIError(err)
except KeyboardInterrupt:
from threading import enumerate as activethreads
......@@ -759,9 +775,13 @@ class store_download(_store_container_command):
stdout.write('.')
except RuntimeError:
continue
progress_bar.finish()
print('\ndownload canceled by user')
if local_path is not None:
print('to resume, re-run with --resume')
except Exception as e:
progress_bar.finish()
raise e
print
......
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