Browse files

Fixed boto.utils.fetch_file for use with keys with slashes in the names

Added a wrapper script for fetch_file
  • Loading branch information...
1 parent 4cfb403 commit 034f169a9e6921908b6aa7414360b5cc13b557a6 kopertop committed Jul 16, 2009
Showing with 39 additions and 2 deletions.
  1. +37 −0 bin/fetch_file
  2. +1 −1 boto/utils.py
  3. +1 −1 setup.py
View
37 bin/fetch_file
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# Copyright (c) 2009 Chris Moyer http://coredumped.org
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish, dis-
+# tribute, sublicense, and/or sell copies of the Software, and to permit
+# persons to whom the Software is furnished to do so, subject to the fol-
+# lowing conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+#
+if __name__ == "__main__":
+ from optparse import OptionParser
+ parser = OptionParser(version="0.1", usage="Usage: %prog [options] url")
+ parser.add_option("-o", "--out-file", help="Output file", dest="outfile")
+
+ (options, args) = parser.parse_args()
+ if len(args) < 1:
+ parser.print_help()
+ exit(1)
+ from boto.utils import fetch_file
+ f = fetch_file(args[0])
+ if options.outfile:
+ open(options.outfile, "w").write(f.read())
+ else:
+ print f.read()
View
2 boto/utils.py
@@ -211,7 +211,7 @@ def fetch_file(uri, file=None, username=None, password=None):
try:
working_dir = boto.config.get("General", "working_dir")
if uri.startswith('s3://'):
- bucket_name, key_name = uri[len('s3://'):].split('/')
+ bucket_name, key_name = uri[len('s3://'):].split('/', 1)
c = boto.connect_s3()
bucket = c.get_bucket(bucket_name)
key = bucket.get_key(key_name)
View
2 setup.py
@@ -34,7 +34,7 @@
long_description="Python interface to Amazon's Web Services.",
author = "Mitch Garnaat",
author_email = "mitch@garnaat.com",
- scripts = ["bin/sdbadmin", "bin/s3put"],
+ scripts = ["bin/sdbadmin", "bin/s3put", "bin/fetch_file"],
url = "http://code.google.com/p/boto/",
packages = [ 'boto', 'boto.sqs', 'boto.s3',
'boto.ec2', 'boto.ec2.cloudwatch', 'boto.ec2.autoscale', 'boto.ec2.elb',

0 comments on commit 034f169

Please sign in to comment.