跳转到主要内容

OFS - 提供基于插件的底层blobstore。

项目描述

OFS是一个bucket/object存储库。

它为存储位流(及相关元数据)在“bucket/object”存储(如)提供了通用API

  • S3, Google Storage, Eucalytus, Archive.org

  • 文件系统(通过pairtree)

  • ‘REST’存储(见remote/reststore.py - 实现见 http://bitbucket.org/pudo/repod/

  • Riak(有bug)

  • 在此处添加后端 - 只需在base.py中实现方法

为什么使用这个库

  • 抽象:编写通用代码但使用不同的存储后端

  • 比文件系统多,比数据库少 - 支持元数据和位流

要求

对于所有基于boto的存储(Google Storage,S3等)需要boto>=2.0。

示例用法

(本地版本 - 依赖于‘pairtree’,以及‘simplejson’)

 >>> from ofs.local import PTOFS

 >>> o = PTOFS()
 (Equivalent to 'o = PTOFS(storage_dir = "data", uri_base="urn:uuid:", hashing_type="md5")')

 # Claim a bucket - this will add the bucket to the list of existing ones
 >>> uuid_id = o.claim_bucket()
 >>> uuid_id
 '4aaa43cdf5ba44e2ad25acdbd1cf2f70'

 # Choose a bucket name - if it exists, a new UUID one will be formed instead and returned
 >>> bucket_id = o.claim_bucket("foo")
 >>> bucket_id
 'foo'
 >>> bucket_id = o.claim_bucket("foo")
 >>> bucket_id
 '1bf93208521545879e79c13614cd12f0'

 # Store a file:
 >>> o.put_stream(bucket_id, "foo.txt", open("foo....))
 {'_label': 'foo.txt', '_content_length': 10, '_checksum': 'md5:10feda25f8da2e2ebfbe646eea351224', '_last_modified': '2010-08-02T11:37:21', '_creation_date': '2010-08-02T11:37:21'}

 # or:
 >>> o.put_stream(bucket_id, "foo.txt", "asidaisdiasjdiajsidjasidji")
 {'_label': 'foo.txt', '_content_length': 10, '_checksum': 'md5:10feda25f8da2e2ebfbe646eea351224', '_last_modified': '2010-08-02T11:37:21', '_creation_date': '2010-08-02T11:37:21'}

 # adding a file with some parameters:
 >>> o.put_stream(bucket_id, "foooo", "asidaisdiasjdiajsidjasidji", params={"original_uri":"http://...."})
 {'_label': 'foooo', 'original_uri': 'http://....', '_last_modified': '2010-08-02T11:39:11', '_checksum': 'md5:3d690d7e0f4479c5a7038b8a4572d0fe', '_creation_date': '2010-08-02T11:39:11', '_content_length': 26}

 # Get the underlying URL pointing to a resource
 >>> o.get_url(bucket_id, "foo")
   [typical local pairtree response:]
"file:///opt/ofs_store/pairtree_root/1b/f9/32/......./obj/foo"
   [typical remote response]
"http://..."
"ftp://..."

 # adding to existing metadata:
 >>> o.update_metadata(bucket_id, "foooo", {'foo':'bar'})
 {'_label': 'foooo', 'original_uri': 'http://....', '_last_modified': '2010-08-02T11:39:11', '_checksum': 'md5:3d690d7e0f4479c5a7038b8a4572d0fe', '_creation_date': '2010-08-02T11:39:11', '_content_length': 26, 'foo': 'bar'}

 # Remove keys
 >>> o.remove_metadata_keys(bucket_id, "foooo", ['foo'])
 {'_label': 'foooo', 'original_uri': 'http://....', '_last_modified': '2010-08-02T11:39:11', '_checksum': 'md5:3d690d7e0f4479c5a7038b8a4572d0fe', '_creation_date': '2010-08-02T11:39:11', '_content_length': 26}

 # Delete blob
 >>> o.exists(bucket_id, "foooo")
 True
 >>> o.del_stream(bucket_id, "foooo")
 >>> o.exists(bucket_id, "foooo")
 False

 # Iterate through ids for buckets held:
 >>> for item in o.list_buckets():
 ...   print(item)
 ...
 447536aa0f1b411089d12399738ede8e
 4a726b0a33974480a2a26d34fa0d494d
 4aaa43cdf5ba44e2ad25acdbd1cf2f70
 .... etc

 # Display the labels in a specific bucket:
 >>>o.list_labels("1bf93208521545879e79c13614cd12f0")
 [u'foo.txt']

开发者

测试使用plain unittest但建议使用nose。

要运行botostore测试,您需要将test.ini.tmpl复制到test.ini,并填写Google存储账户的详细信息。

变更日志

v0.4.1: 2011-08-13

  • 如果未设置,则基于etag(botostore后端)设置基于校验和(md5)

v0.4: 2011-04-28

  • 为boto基于的后端新增authenticate_request方法。

  • 改进了botostore中的update_medata(无需下载和重新上传)。

v0.3: 2011-01-20

  • S3Bounce后端(使用CKAN的授权凭据)。

  • 使用setuptools插件与ofs.backend配合,允许使用第三方后端。

  • ofs_upload命令

v0.2: 2010-11-20

  • 支持Google存储。

  • REST存储

v0.1: 2010-10-14

  • 初始实现,使用PairTree和S3。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分布

ofs-0.4.3.tar.gz (153.6 kB 查看散列值)

上传时间 源代码

由支持