Find file
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (36 sloc) 1.5 KB
# Jekyll at Rackspace Cloud Files with Clean URLs
# Copyright 2012 Nicholas Kuechler
""" Jekyll at Rackspace Cloud Files with Clean URLs """
import os
import cloudfiles
# Rackspace Cloud API credentials
# The name of your container.
# I create containers in the format:
conn = cloudfiles.get_connection(username=USERNAME,
container = conn.get_container(CONTAINER_NAME)
# Upload all files in the jekyll _site directory
for root, dirs, files in os.walk('_site'):
for name in files:
filename = os.path.join(root, name)
# Remove _site/ from the uploaded file name,
# or else our URL will be
upload_filename = filename.replace("_site/", "")
# Upload the file to Rackspace Cloud Files
obj = container.create_object(upload_filename)
# Check if the file contains HTML code.
# If so, we need to set the correct content type.
for line in open(filename):
if "<!DOCTYPE html>" in line:
print "file %s is an HTML file!" % filename
# If html file, then set content type
obj.content_type = "text/html"
fp = open(filename)
print "uploading filename: %s" % upload_filename