Merge branch 'master' of https://code.grnet.gr/git/pithos
[pithos] / snf-pithos-backend / pithos / backends / base.py
index d0ea038..7270e7e 100644 (file)
@@ -42,6 +42,24 @@ class NotAllowedError(Exception):
 class QuotaError(Exception):
     pass
 
+class AccountExists(NameError):
+    pass
+    
+class ContainerExists(NameError):
+    pass
+
+class AccountNotEmpty(IndexError):
+    pass
+
+class ContainerNotEmpty(IndexError):
+    pass
+
+class ItemNotExists(NameError):
+    pass
+
+class VersionNotExists(IndexError):
+    pass
+
 class BaseBackend(object):
     """Abstract backend class that serves as a reference for actual implementations.
     
@@ -165,11 +183,11 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            IndexError: Account is not empty
+            AccountNotEmpty: Account is not empty
         """
         return
     
-    def list_containers(self, user, account, marker=None, limit=10000, shared=False, until=None):
+    def list_containers(self, user, account, marker=None, limit=10000, shared=False, until=None, public=False):
         """Return a list of container names existing under an account.
         
         Parameters:
@@ -179,6 +197,8 @@ class BaseBackend(object):
             
             'shared': Only list containers with permissions set
             
+            'public': Only list containers containing public objects
+            
         
         Raises:
             NotAllowedError: Operation not permitted
@@ -191,7 +211,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return []
     
@@ -212,7 +232,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return {}
     
@@ -229,7 +249,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return
     
@@ -244,7 +264,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return {}
     
@@ -254,19 +274,22 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
             
             ValueError: Invalid policy defined
         """
         return
     
-    def put_container(self, user, account, container, policy={}):
+    def put_container(self, user, account, container, policy={}, delimiter=None):
         """Create a new container with the given name.
         
+        Parameters:
+            'delimiter': If present deletes container contents instead of the container
+        
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container already exists
+            ContainerExists: Container already exists
             
             ValueError: Invalid policy defined
         """
@@ -278,13 +301,13 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
             
-            IndexError: Container is not empty
+            ContainerNotEmpty: Container is not empty
         """
         return
     
-    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None):
+    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None, public=False):
         """Return a list of object (name, version_id) tuples existing under a container.
         
         Parameters:
@@ -312,11 +335,14 @@ class BaseBackend(object):
              
             'size_range': Include objects with byte size in (from, to).
                           Use None to specify unlimited
+            
+            'public': Only list public objects
+             
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return []
     
@@ -329,7 +355,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return []
     
@@ -372,9 +398,9 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
-            IndexError: Version does not exist
+            VersionNotExists: Version does not exist
         """
         return {}
     
@@ -391,7 +417,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return ''
     
@@ -408,20 +434,20 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return {}
     
     def update_object_permissions(self, user, account, container, name, permissions):
-        """Update the permissions associated with the object.
+        """Update (set) the permissions associated with the object.
         
         Parameters:
-            'permissions': Dictionary with permissions to update
+            'permissions': Dictionary with permissions to set
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
             ValueError: Invalid users/groups in permissions
         """
@@ -433,7 +459,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return None
     
@@ -446,7 +472,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return
     
@@ -456,9 +482,9 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
-            IndexError: Version does not exist
+            VersionNotExists: Version does not exist
         """
         return 0, []
     
@@ -477,7 +503,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
             
             ValueError: Invalid users/groups in permissions
             
@@ -489,7 +515,7 @@ class BaseBackend(object):
         """Update an object's checksum."""
         return
     
-    def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, src_version=None):
+    def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, src_version=None, delimiter=None):
         """Copy an object's data and metadata and return the new version.
         
         Parameters:
@@ -502,13 +528,15 @@ class BaseBackend(object):
             'permissions': New object permissions
             
             'src_version': Copy from the version provided
+            
+            'delimiter': Copy objects whose path starts with src_name + delimiter
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
-            IndexError: Version does not exist
+            VersionNotExists: Version does not exist
             
             ValueError: Invalid users/groups in permissions
             
@@ -516,7 +544,7 @@ class BaseBackend(object):
         """
         return ''
     
-    def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None):
+    def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, delimiter=None):
         """Move an object's data and metadata and return the new version.
         
         Parameters:
@@ -527,11 +555,13 @@ class BaseBackend(object):
             'replace_meta': Replace metadata instead of update
             
             'permissions': New object permissions
+            
+            'delimiter': Move objects whose path starts with src_name + delimiter
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
             ValueError: Invalid users/groups in permissions
             
@@ -539,13 +569,16 @@ class BaseBackend(object):
         """
         return ''
     
-    def delete_object(self, user, account, container, name, until=None):
+    def delete_object(self, user, account, container, name, until=None, delimiter=None):
         """Delete/purge an object.
         
+        Parameters:
+            'delimiter': Delete objects whose path starting with name + delimiter
+        
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return
     
@@ -581,7 +614,7 @@ class BaseBackend(object):
         """Return a block's data.
         
         Raises:
-            NameError: Block does not exist
+            ItemNotExists: Block does not exist
         """
         return ''