Commits

Dhananjay Nene committed 0d510b3

various bug fixes and reorganisation of server __init__ semantics / signature

Comments (0)

Files changed (4)

src/pybuckets/botos3.py

 from boto.s3.key import Key
 from pybuckets import Bucket, BucketServer, DuplicateBucketNameException, \
     BucketsException, server_registry
+from pybuckets import build_kw_from_params_and_object
 import operator
 
 # S3CreateError - body, box_usage, bucket, error_code, error_message,message,reason,request_id,status
         k = Key(self.s3bucket)
         k.key = name
         return k.set_contents_from_string(value)
-
-def build_kw_from_params_and_object(params,obj,candidates) :
-    kw = {}
-    for key in candidates :
-        if key in params : kw[key] = params[key]
-        elif hasattr(obj,key) : kw[key] = getattr(obj,key)
-    return kw
+    
+    def delete_key(self,name):
+        k = Key(self.s3bucket)
+        k.key = name
+        k.delete()
 
 class BotoS3Server(BucketServer):
     def __init__(self,**config):
-        super(BotoS3Server,self).__init__()
-        for key,val in config.items() :
-            if key in ('aws_access_key_id','aws_secret_access_key','host','port','is_secure', 'debug','calling_format','headers','location','policy') :
-                self.__dict__[key] = val
+        super(BotoS3Server,self).__init__(('aws_access_key_id','aws_secret_access_key','host','port','is_secure', 'debug','calling_format','headers','location','policy'),**config)
         
         self.connection = S3Connection(
                     **build_kw_from_params_and_object({},self,

src/pybuckets/local.py

         
 class LocalFSServer(BucketServer):
     def __init__(self,**config):
-        super(LocalFSServer,self).__init__()
-        self.path = config['path']
-        self.config['_remove_non_empty_buckets'] = config.get('_remove_non_empty_buckets',False)
+        super(LocalFSServer,self).__init__(('path'),**config)
         if not os.path.isdir(self.path) :
-            raise LocalFSException('%s must be a directory' % self.path)
+            raise LocalFSException('%s must be a directory' % self.path,None)
         
-    def get_bucket_names(self):
+    def keys(self):
         return os.listdir(self.path)
     
     def get(self,name):
         return LocalFSBucket(name,self)
     
     def delete_bucket(self,key):
-        if self.config['_remove_non_empty_buckets'] :
-            shutil.rmtree(os.path.join(self.path,key))
-        else :
-            os.rmdir(os.path.join(self.path,key))
+        os.rmdir(os.path.join(self.path,key))
     
     def create_bucket(self,name,**kwargs):
         try :

src/pybuckets/pybuckets.py

 bucket_registry = {}
 """ Registry for autoregistration of various component libraries supporting just a bucket"""
 
+def build_kw_from_params_and_object(params,obj,candidates) :
+    kw = {}
+    for key in candidates :
+        if key in params : kw[key] = params[key]
+        elif hasattr(obj,key) : kw[key] = getattr(obj,key)
+    return kw
+
 class BucketsException(Exception):
     """Exception class to wrap various exceptions"""
     def __init__(self,e):
         
 class BucketServer(object):
     "A bucket server"
-    def __init__(self):
-        self.config = {}
+    def __init__(self,valid_keys,**config):
+        for key,val in config.items() :
+            if key in valid_keys :
+                self.__dict__[key] = val
+        
     def __len__(self):
         return len(self.keys())
     def __iter__(self):
         return self.get(key)
     def __delitem__(self,key):
         return self.delete_bucket(key)
+    def supports_mime_type(self,mime_type):
+        return True
+    def supported_mime_types(self):
+        return ['*/*']
     @classmethod
     def get_server(cls,name,**creds):
         return server_registry[name](**creds)

src/pybuckets/rscloudfiles.py

         
 class CloudfilesServer(BucketServer):
     def __init__(self,**config):
-        super(CloudfilesServer,self).__init__()
-        self.username = config['username']
-        self.api_key = config['api_key']
+        super(CloudfilesServer,self).__init__(('username','api_key'),**config)
         self.connection = cloudfiles.get_connection(self.username, self.api_key)
         
     def keys(self):
         return 'CloudfilesBucket(%s,%s)' % (self.key, str(self.server))
     
     def __call__(self, key):
-        return CloudfilesValueWrapper(self.container, self.key)
+        return CloudfilesValueWrapper(self.container, key)
 #    
     def keys(self):
         return map(operator.attrgetter('name'),self.container.get_objects())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.