~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to bin/txaws-create-bucket

  • Committer: Duncan McGreggor
  • Date: 2009-11-13 23:56:18 UTC
  • Revision ID: duncan@canonical.com-20091113235618-vnve62r5hnpacnlg
Fixed self debugging.

Show diffs side-by-side

added added

removed removed

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