[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a
Garrett Holmstrom
gholms at fedoraproject.org
Sun Jun 16 02:31:18 UTC 2013
The following commit has been merged in the master branch:
commit e403f47fdc26a0f1e786bf3fa306a2a9bdf9a55f
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Tue May 7 15:56:15 2013 -0700
Add progress bars to GetObject
diff --git a/euca2ools/commands/walrus/getobject.py b/euca2ools/commands/walrus/getobject.py
index 7b35bf8..bcf11a0 100644
--- a/euca2ools/commands/walrus/getobject.py
+++ b/euca2ools/commands/walrus/getobject.py
@@ -29,11 +29,13 @@
# POSSIBILITY OF SUCH DAMAGE.
from euca2ools.commands.walrus import WalrusRequest
+from euca2ools.utils import build_progressbar_label_template
import os.path
from requestbuilder import Arg
+from requestbuilder.mixins import FileTransferProgressBarMixin
-class GetObject(WalrusRequest):
+class GetObject(WalrusRequest, FileTransferProgressBarMixin):
DESCRIPTION = 'Retrieve objects from the server'
ARGS = [Arg('paths', metavar='BUCKET/KEY', nargs='+', route_to=None),
Arg('-o', dest='opath', metavar='PATH', default='.', route_to=None,
@@ -46,25 +48,46 @@ class GetObject(WalrusRequest):
def main(self):
opath = self.args['opath']
+ label_template = build_progressbar_label_template(self.args['paths'])
if opath.endswith('/') and not os.path.isdir(opath):
# Ends with '/' and does not exist -> create it
os.mkdir(opath)
if os.path.isdir(opath):
# Download one per directory
- for path in self.args['paths']:
+ for index, path in enumerate(self.args['paths'], 1):
ofile_name = os.path.join(opath, path.rsplit('/', 1)[-1])
self.path = path
response = self.send()
+ if 'Content-Length' in response.headers:
+ maxval = int(response.headers['Content-Length'])
+ else:
+ maxval = None
+ label = label_template.format(index=index, fname=path)
+ pbar = self.get_progressbar(label=label, maxval=maxval)
+ pbar.start()
with open(ofile_name, 'w') as ofile:
for chunk in response.iter_content(chunk_size=16384):
ofile.write(chunk)
+ pbar.update(ofile.tell())
ofile.flush()
+ pbar.finish()
else:
# Download everything to one file
with open(opath, 'w') as ofile:
- for path in self.args['paths']:
+ for index, path in enumerate(self.args['paths'], 1):
self.path = path
response = self.send()
+ bytes_written = 0
+ if 'Content-Length' in response.headers:
+ maxval = int(response.headers['Content-Length'])
+ else:
+ maxval = None
+ label = label_template.format(index=index, fname=path)
+ pbar = self.get_progressbar(label=label, maxval=maxval)
+ pbar.start()
for chunk in response.iter_content(chunk_size=16384):
ofile.write(chunk)
+ bytes_written += len(chunk)
+ pbar.update(bytes_written)
+ pbar.finish()
ofile.flush()
diff --git a/euca2ools/commands/walrus/putobject.py b/euca2ools/commands/walrus/putobject.py
index 175c507..9bf2fc1 100644
--- a/euca2ools/commands/walrus/putobject.py
+++ b/euca2ools/commands/walrus/putobject.py
@@ -30,6 +30,7 @@
import datetime
from euca2ools.commands.walrus import WalrusRequest
+from euca2ools.utils import build_progressbar_label_template
import mimetypes
import os.path
from requestbuilder import Arg
@@ -147,16 +148,3 @@ class PutObject(WalrusRequest, FileTransferProgressBarMixin):
with self._lock:
self.last_upload_error = err
raise
-
-
-def build_progressbar_label_template(fnames):
- if len(fnames) == 0:
- return None
- elif len(fnames) == 1:
- return '{fname}'
- else:
- max_fname_len = max(len(os.path.basename(fname)) for fname in fnames)
- fmt_template = '{{fname:<{maxlen}}} ({{index:>{lenlen}}}/{total})'
- return fmt_template.format(maxlen=max_fname_len,
- lenlen=len(str(len(fnames))),
- total=len(fnames))
diff --git a/euca2ools/utils.py b/euca2ools/utils.py
index 743cf67..db489bb 100644
--- a/euca2ools/utils.py
+++ b/euca2ools/utils.py
@@ -148,3 +148,16 @@ def handle_availability_zones(requested_zones, response=None):
'sandwich' in requested_zones):
# humor dfed
print >> sys.stderr, msg
+
+
+def build_progressbar_label_template(fnames):
+ if len(fnames) == 0:
+ return None
+ elif len(fnames) == 1:
+ return '{fname}'
+ else:
+ max_fname_len = max(len(os.path.basename(fname)) for fname in fnames)
+ fmt_template = '{{fname:<{maxlen}}} ({{index:>{lenlen}}}/{total})'
+ return fmt_template.format(maxlen=max_fname_len,
+ lenlen=len(str(len(fnames))),
+ total=len(fnames))
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list