[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:30:06 UTC 2013
The following commit has been merged in the master branch:
commit 918b93dd1d3ecd715dcc368e7aa8d44ecebda18d
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Sat Feb 16 18:59:46 2013 -0800
Implement minimal object fetching
diff --git a/euca2ools/commands/walrus/getobject.py b/euca2ools/commands/walrus/getobject.py
new file mode 100644
index 0000000..c501f20
--- /dev/null
+++ b/euca2ools/commands/walrus/getobject.py
@@ -0,0 +1,70 @@
+# Software License Agreement (BSD License)
+#
+# Copyright (c) 2013, Eucalyptus Systems, Inc.
+# All rights reserved.
+#
+# Redistribution and use of this software in source and binary forms, with or
+# without modification, are permitted provided that the following conditions
+# are met:
+#
+# Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the
+# following disclaimer.
+#
+# Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the
+# following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+from requestbuilder import Arg
+import os.path
+from . import WalrusRequest
+
+class GetObject(WalrusRequest):
+ 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,
+ help='''where to download to. If this names an existing
+ directory or ends in '/' all objects will be downloaded
+ separately to files in that directory. Otherwise, all
+ downloads will be written to a file with this name.
+ Note that outputting multiple objects to a file will
+ result in their concatenation. (default: current
+ directory)''')]
+
+ def main(self):
+ opath = self.args['opath']
+ if opath.endswith('/') and not os.path.isdir(opath):
+ # Ends with '/' and does not exist -> create it
+ os.makedirs(opath)
+ if os.path.isdir(opath):
+ # Download one per directory
+ for path in self.args['paths']:
+ ofile_name = os.path.join(opath, path.rsplit('/', 1)[-1])
+ self.path = path
+ response = self.send()
+ with open(ofile_name, 'w') as ofile:
+ for chunk in response.iter_content(chunk_size=16384):
+ ofile.write(chunk)
+ ofile.flush()
+ else:
+ # Download everything to one file
+ with open(opath, 'w') as ofile:
+ for path in self.args['paths']:
+ self.path = path
+ response = self.send()
+ for chunk in response.iter_content(chunk_size=16384):
+ ofile.write(chunk)
+ ofile.flush()
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list