1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/usr/bin/env python
"""
%prog [options]
"""
import sys
from txaws.credentials import AWSCredentials
from txaws.script import parse_options
from txaws.service import AWSServiceRegion
from txaws.reactor import reactor
def printResults(results):
return 0
def printError(error):
print error.value
return 1
def finish(return_code):
reactor.stop(exitStatus=return_code)
options, args = parse_options(__doc__.strip())
if options.bucket is None:
print "Error Message: A bucket name is required."
sys.exit(1)
creds = AWSCredentials(options.access_key, options.secret_key)
region = AWSServiceRegion(
creds=creds, region=options.region, s3_uri=options.url)
client = region.get_s3_client()
d = client.create_bucket(options.bucket)
d.addCallback(printResults)
d.addErrback(printError)
d.addCallback(finish)
# We use a custom reactor so that we can return the exit status from
# reactor.run().
sys.exit(reactor.run())
|