Commits

Anonymous committed 0b6ff83

create pseudo directories for every '/' in the filename

  • Participants
  • Parent commits 592e888

Comments (0)

Files changed (1)

File storages/backends/mosso.py

 Custom storage for django with Mosso Cloud Files backend.
 Created by Rich Leland <rich@richleland.com>.
 """
+from _io import StringIO
+import os
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
 from django.core.files import File
         Use the Cloud Files service to write ``content`` to a remote file
         (called ``name``).
         """
+        (path, last) = os.path.split(name)
+        if path:
+            try:
+                self.container.get_object(path)
+            except NoSuchObject:
+                self._save(path, CloudStorageDirectory(path))
 
         cloud_obj = self.container.create_object(name)
         cloud_obj.size = content.size
         return '%s/%s' % (self.container_url, name)
 
 
+class CloudStorageDirectory(File):
+    """
+    A File-like object that creates a directory at cloudfiles
+    """
+
+    def __init__(self, name):
+        super(CloudStorageDirectory, self).__init__(StringIO(), name=name)
+        self.file.content_type = 'application/directory'
+        self.size = 0
+
+    def __str__(self):
+        return 'directory'
+
+    def __nonzero__(self):
+        return True
+
+    def open(self, mode=None):
+        self.seek(0)
+
+    def close(self):
+        pass
+
+
 class CloudFilesStorageFile(File):
     closed = False