8
from txaws.credentials import AWSCredentials
9
from txaws.script import parse_options
10
from txaws.service import AWSServiceRegion
11
from txaws.reactor import reactor
14
def printResults(listing, bucket):
15
print "Contents of '%s' bucket:" % bucket
16
for item in listing.contents:
17
print "\t%s (last modified on %s)" % (item.key, item.modification_date)
18
print "Total items: %s\n" % len(listing.contents)
22
def printError(error):
27
def finish(return_code):
28
reactor.stop(exitStatus=return_code)
31
options, args = parse_options(__doc__.strip())
32
if options.bucket is None:
33
print "Error Message: A bucket name is required."
35
creds = AWSCredentials(options.access_key, options.secret_key)
36
region = AWSServiceRegion(
37
creds=creds, region=options.region, s3_uri=options.url)
38
client = region.get_s3_client()
40
d = client.get_bucket(options.bucket)
41
d.addCallback(printResults, options.bucket)
42
d.addErrback(printError)
44
# We use a custom reactor so that we can return the exit status from
46
sys.exit(reactor.run())