commit 852a22e7989419491a607530b6b3c4c5c8fbe3e8
Author: Stavros Sachtouris <saxtouri@admin.grnet.gr>
Date:   Mon Nov 19 14:01:54 2012 +0200

    Upgrade progress compatibility to 1.0.2
    
    New progress uses a different interface with start and finish methods
    that they are now used

diff --git a/kamaki/cli/argument.py b/kamaki/cli/argument.py
index 657f5be..ab47010 100644
--- a/kamaki/cli/argument.py
+++ b/kamaki/cli/argument.py
@@ -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')),
diff --git a/kamaki/cli/commands/cyclades_cli.py b/kamaki/cli/commands/cyclades_cli.py
index bf33d89..160428b 100644
--- a/kamaki/cli/commands/cyclades_cli.py
+++ b/kamaki/cli/commands/cyclades_cli.py
@@ -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))
diff --git a/kamaki/cli/commands/pithos_cli.py b/kamaki/cli/commands/pithos_cli.py
index dd58f17..7ad232f 100644
--- a/kamaki/cli/commands/pithos_cli.py
+++ b/kamaki/cli/commands/pithos_cli.py
@@ -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
 
 
