Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved WebSite support

* Renamed ws-list to ws-info
* Prettyfied ws-info output
* Include website endpoint in ws-info output
* Fixed --ws-error handling
  • Loading branch information...
commit 3bf7d0c334aaad1a56b4ef69278a89caf93cf274 1 parent cde72d4
@mludvig mludvig authored
Showing with 34 additions and 16 deletions.
  1. +2 −0  NEWS
  2. +2 −1  S3/Config.py
  3. +22 −8 S3/S3.py
  4. +8 −7 s3cmd
View
2  NEWS
@@ -2,6 +2,8 @@ s3cmd 1.1.0 - ???
===========
* CloudFront invalidation via [sync --cf-invalidate] and [cfinvalinfo].
* Increased socket_timeout from 10 secs to 5 mins.
+* Added "Static WebSite" support [ws-create / ws-delete / ws-info]
+ (contributed by Jens Braeuer)
s3cmd 1.0.0 - 2011-01-18
===========
View
3  S3/Config.py
@@ -77,7 +77,8 @@ class Config(object):
socket_timeout = 300
invalidate_on_cf = False
website_index = "index.html"
- website_error = None
+ website_error = ""
+ website_endpoint = "http://%(bucket)s.s3-website-%(location)s.amazonaws.com/"
## Creating a singleton
def __new__(self, configfile = None):
View
30 S3/S3.py
@@ -238,27 +238,41 @@ def bucket_delete(self, bucket):
response = self.send_request(request)
return response
- def bucket_info(self, uri):
+ def get_bucket_location(self, uri):
request = self.create_request("BUCKET_LIST", bucket = uri.bucket(), extra = "?location")
response = self.send_request(request)
- response['bucket-location'] = getTextFromXml(response['data'], "LocationConstraint") or "any"
+ location = getTextFromXml(response['data'], "LocationConstraint")
+ if not location or location in [ "", "US" ]:
+ location = "us-east-1"
+ elif location == "EU":
+ location = "eu-west-1"
+ return location
+
+ def bucket_info(self, uri):
+ # For now reports only "Location". One day perhaps more.
+ response = {}
+ response['bucket-location'] = self.get_bucket_location(uri)
return response
- def website_list(self, uri, bucket_location = None):
+ def website_info(self, uri, bucket_location = None):
headers = SortedDict(ignore_case = True)
bucket = uri.bucket()
body = ""
request = self.create_request("BUCKET_LIST", bucket = bucket, extra="?website")
- response = None
try:
response = self.send_request(request, body)
+ response['index_document'] = getTextFromXml(response['data'], ".//IndexDocument//Suffix")
+ response['error_document'] = getTextFromXml(response['data'], ".//ErrorDocument//Key")
+ response['website_endpoint'] = self.config.website_endpoint % {
+ "bucket" : uri.bucket(),
+ "location" : self.get_bucket_location(uri)}
+ return response
except S3Error, e:
if e.status == 404:
- debug("Could not get ?website. Assuming none set.")
- else:
- raise
- return response
+ debug("Could not get /?website - website probably not configured for this bucket")
+ return None
+ raise
def website_create(self, uri, bucket_location = None):
headers = SortedDict(ignore_case = True)
View
15 s3cmd
@@ -164,20 +164,21 @@ def cmd_bucket_create(args):
else:
raise
-def cmd_website_list(args):
+def cmd_website_info(args):
s3 = S3(Config())
for arg in args:
uri = S3Uri(arg)
if not uri.type == "s3" or not uri.has_bucket() or uri.has_object():
raise ParameterError("Expecting S3 URI with just the bucket name set instead of '%s'" % arg)
try:
- response = s3.website_list(uri, cfg.bucket_location)
+ response = s3.website_info(uri, cfg.bucket_location)
if response:
- import xml.dom.minidom
- xml = xml.dom.minidom.parseString(response['data'])
- output(u"Bucket '%s': website configuration:\n%s" % (uri.uri(), xml.toprettyxml()))
+ output(u"Bucket %s: Website configuration" % uri.uri())
+ output(u"Website endpoint: %s" % response['website_endpoint'])
+ output(u"Index document: %s" % response['index_document'])
+ output(u"Error document: %s" % response['error_document'])
else:
- output(u"Bucket '%s': unable to receive website configuration. None set?" % (uri.uri()))
+ output(u"Bucket %s: Unable to receive website configuration." % (uri.uri()))
except S3Error, e:
if S3.codes.has_key(e.info["Code"]):
error(S3.codes[e.info["Code"]] % uri.bucket())
@@ -1379,7 +1380,7 @@ def get_commands_list():
## Website commands
{"cmd":"ws-create", "label":"Create Website from bucket", "param":"s3://BUCKET", "func":cmd_website_create, "argc":1},
{"cmd":"ws-delete", "label":"Delete Website", "param":"s3://BUCKET", "func":cmd_website_delete, "argc":1},
- {"cmd":"ws-list", "label":"List Websites", "param":"s3://BUCKET", "func":cmd_website_list, "argc":1},
+ {"cmd":"ws-info", "label":"Info about Website", "param":"s3://BUCKET", "func":cmd_website_info, "argc":1},
## CloudFront commands
{"cmd":"cflist", "label":"List CloudFront distribution points", "param":"", "func":CfCmd.info, "argc":0},
Please sign in to comment.
Something went wrong with that request. Please try again.