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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/env python
"""
%prog [options]
"""
import os
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)
filename = options.object_filename
if filename:
options.object_name = os.path.basename(filename)
try:
options.object_data = open(filename).read()
except Exception, error:
print error
sys.exit(1)
elif options.object_name is None:
print "Error Message: An object 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.put_object(
options.bucket, options.object_name, options.object_data,
options.content_type)
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())
|