website_10.py 981 B

1234567891011121314151617181920
  1. def create(self, use_existing_bucket=False):
  2. """Create the bucket for the subdomain."""
  3. #Check if the bucket name already exists in our account,
  4. #boto doesn't tell us this.
  5. connection = self.get_connection()
  6. if use_existing_bucket:
  7. bucket = connection.get_bucket(self.bucketname)
  8. else:
  9. if self.bucketname in s3_util.get_bucket_names(connection):
  10. raise Exception("Bucket '{0}' already exists in your account."\
  11. .format(self.bucketname))
  12. bucket = connection.create_bucket(self.bucketname)
  13. logger.info("Created new bucket : {0}".format(self.bucketname))
  14. #A website should be publically readable:
  15. bucket.set_acl("public-read")
  16. #Turn on website functionality:
  17. if self.error_doc:
  18. bucket.configure_website(self.index, self.error_doc)
  19. else:
  20. bucket.configure_website(self.index)