Package pairtree :: Module pairtree_store
[hide private]
[frames] | no frames]

Source Code for Module pairtree.pairtree_store

 1  #!/usr/bin/python 
 2  # -*- coding: utf-8 -*- 
 3   
 4  """ 
 5  FS Pairtree storage - Factory 
 6  ============================= 
 7   
 8  Conventions used: 
 9   
10  From http://www.cdlib.org/inside/diglib/pairtree/pairtreespec.html version 0.1 
11   
12  This is a simple Factory-style class, which can produce pairtree store clients. 
13   
14  Usage 
15  ===== 
16   
17  >>> from pairtree import PairtreeStorageFactory 
18  >>> factory = PairtreeStorageFactory() 
19   
20  To create a pairtree store in I{mystore/} to hold objects which have a URI base of 
21  I{http://example.org/ark:/123} 
22   
23  >>> store = factory.get_store(store_dir='mystore', uri_base='http://example.org/ark:/123') 
24   
25  """ 
26   
27  from pairtree_client import PairtreeStorageClient 
28   
29 -class PairtreeStorageFactory(object):
30
31 - def get_store(self, store_dir="data", uri_base=None, shorty_length=2, hashing_type = None):
32 """ 33 Get a store - if the store does not exist, one will be instanciated 34 35 If hashing_type is set to one of the hashing algorithms supported by 36 hashlib - ['md5', 'sha1', 'sha224','sha256','sha384','sha512'] then 37 all bytestreams will be checksummed when added or updated and their sums returned. 38 39 @param store_dir: The file directory where the pairtree store is 40 @type store_dir: A path to a directory, relative or absolute 41 @param uri_base: The URI base for the store 42 @type uri_base: A URI fragment, like "http://example.org/" 43 @param shorty_length: The size of the shorties in the pairtree implementation (Default: 2) 44 @type shorty_length: integer 45 @param hashing_type: The name of the algorithm to use when hashing files, if left as None, this is disabled. 46 @type hashing_type: Any supported by C{hashlib} 47 @returns: L{PairtreeStorageClient} 48 """ 49 if hashing_type and hashing_type not in ['md5', 'sha1', 'sha224','sha256','sha384','sha512']: 50 raise Exception("hashing type must be on of the supported hashlib types: md5, sha1, sha224, sha256, sha384, sha512") 51 return PairtreeStorageClient(uri_base, store_dir, shorty_length, hashing_type)
52