Better pithos upload progressbar
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 5 Dec 2012 17:24:31 +0000 (19:24 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 5 Dec 2012 17:24:31 +0000 (19:24 +0200)
kamaki/cli/argument.py
kamaki/clients/pithos.py

index f52bb0e..346220c 100644 (file)
@@ -38,7 +38,8 @@ from kamaki.cli.utils import split_input
 from argparse import ArgumentParser, ArgumentError
 
 try:
-    from progress.bar import IncrementalBar
+    from progress.bar import FillingCirclesBar as KamakiProgressBar
+    #  IncrementalBar
 except ImportError:
     # progress not installed - pls, pip install progress
     pass
@@ -285,7 +286,7 @@ class ProgressBarArgument(FlagArgument):
         self.suffix = '%(percent)d%%'
         super(ProgressBarArgument, self).__init__(help, parsed_name, default)
         try:
-            IncrementalBar
+            KamakiProgressBar
         except NameError:
             print('Warning: no progress bar functionality')
 
@@ -303,7 +304,7 @@ class ProgressBarArgument(FlagArgument):
         if self.value:
             return None
         try:
-            self.bar = IncrementalBar()
+            self.bar = KamakiProgressBar()
         except NameError:
             self.value = None
             return self.value
index ef93e5b..5d514f9 100644 (file)
@@ -172,9 +172,11 @@ class PithosClient(PithosRestAPI):
         r.release()
 
     # upload_* auxiliary methods
-    def _put_block_async(self, data, hash):
+    def _put_block_async(self, data, hash, upload_gen=None):
         event = SilentEvent(method=self._put_block, data=data, hash=hash)
         event.start()
+        if upload_gen:
+            upload_gen.next()
         return event
 
     def _put_block(self, data, hash):
@@ -251,6 +253,8 @@ class PithosClient(PithosRestAPI):
         if upload_cb:
             upload_gen = upload_cb(len(missing))
             upload_gen.next()
+        else:
+            upload_gen = None
 
         self._init_thread_limit()
 
@@ -259,7 +263,7 @@ class PithosClient(PithosRestAPI):
             offset, bytes = hmap[hash]
             fileobj.seek(offset)
             data = fileobj.read(bytes)
-            r = self._put_block_async(data, hash)
+            r = self._put_block_async(data, hash, upload_gen)
             flying.append(r)
             unfinished = []
             for i, thread in enumerate(flying):
@@ -268,13 +272,14 @@ class PithosClient(PithosRestAPI):
 
                 if thread.isAlive() or thread.exception:
                     unfinished.append(thread)
-                else:
-                    if upload_cb:
-                        upload_gen.next()
+                #else:
+                    #if upload_cb:
+                    #    upload_gen.next()
             flying = unfinished
 
         for thread in flying:
             thread.join()
+            #upload_gen.next()
 
         failures = [r for r in flying if r.exception]
         if len(failures):
@@ -284,12 +289,6 @@ class PithosClient(PithosRestAPI):
                 status=505,
                 details=details)
 
-        while upload_cb:
-            try:
-                upload_gen.next()
-            except StopIteration:
-                break
-
     def upload_object(self, obj, f,
         size=None,
         hash_cb=None,
@@ -350,6 +349,7 @@ class PithosClient(PithosRestAPI):
 
         if missing is None:
             return
+
         try:
             self._upload_missing_blocks(missing, hmap, f, upload_cb=upload_cb)
         except KeyboardInterrupt: