Skip to content

Commit

Permalink
moved cloudfiles connection into __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
richleland committed Jan 9, 2011
1 parent c32e9d5 commit 539e4aa
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions mediasync/backends/rackspace_cloudfiles.py
Expand Up @@ -9,39 +9,38 @@
class Client(BaseClient):

def __init__(self, *args, **kwargs):
"Set up the CloudFiles connection and grab the container."
super(Client, self).__init__(*args, **kwargs)
self.container = msettings['CLOUDFILES_CONTAINER']

if not self.container:
raise ImproperlyConfigured("CLOUDFILES_CONTAINER is a required setting.")

def open(self):
"Set up the CloudFiles connection and grab the container."
container_name = msettings['CLOUDFILES_CONTAINER']
username = msettings['CLOUDFILES_USERNAME']
key = msettings['CLOUDFILES_API_KEY']

if not container_name:
raise ImproperlyConfigured("CLOUDFILES_CONTAINER is a required setting.")

if not username:
raise ImproperlyConfigured("CLOUDFILES_USERNAME is a required setting.")

if not key:
raise ImproperlyConfigured("CLOUDFILES_API_KEY is a required setting.")

_conn = cloudfiles.get_connection(username, key)
self._container = _conn.create_container(self.container)
self.conn = cloudfiles.get_connection(username, key)
self.container = self.conn.create_container(container_name)

if not self._container.is_public():
self._container.make_public()
if not self.container.is_public():
self.container.make_public()

def remote_media_url(self, with_ssl=False):
"Grab the remote URL for the contianer."
if with_ssl:
raise UserWarning("""Rackspace CloudFiles does not yet support SSL.
See http://bit.ly/hYV502 for more info.""")
return self._container.public_uri()
return self.container.public_uri()

def put(self, filedata, content_type, remote_path, force=False):

obj = self._container.create_object(remote_path)
obj = self.container.create_object(remote_path)
obj.content_type = content_type
obj.write(filedata)

Expand Down

0 comments on commit 539e4aa

Please sign in to comment.