ofs-提供面向插件的低层blobstore。

ofs的Python项目详细描述


ofs是一个bucket/对象存储库。

它提供了一个通用的api,用于在 “bucket/object”存储如下:

  • S3, Google Storage, Eucalytus, Archive.org
  • Filesystem (via pairtree)
  • ‘REST’ Store (see remote/reststore.py - implementation at http://bitbucket.org/pudo/repod/)
  • Riak (buggy)
  • add a backend here - just implement the methods in base.py

为什么使用库:

  • Abstraction: write common code but use different storage backends
  • More than a filesystem, less than a database - support for metadata as well as bitstreams

要求

对于所有基于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']

显影剂

测试使用普通的unittest,但建议使用nose。

要运行botostore测试,需要将test.ini.tmpl复制到test.ini和 输入谷歌存储帐户的详细信息。

更改日志

V0.4.1:2011-08-13

  • Set checksum (md5) based on etag (botostore backends) if not set

V0.4:2011-04-28

  • New authenticate_request method for boto based backends.
  • Improved update_medata in botostore (no need to download and re-upload).

v0.3:2011-01-20

  • S3Bounce backend (use authorization credentials from CKAN).
  • Use setuptools plugins with ofs.backend to allow for 3rd party backends
  • ofs_upload command

V0.2:2010年11月20日

  • Google Storage support.
  • REST store

v0.1:2010年10月14日

  • Initial implemenation with PairTree and S3

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何向类添加适用于该类中所有对象的单个@XmlAttribute注释   java未处理的继续记录跟踪类org。阿帕奇。波伊。hssf。记录塔比德雷科德   Eclipse中java代码的rest连接超时,而不是浏览器的rest连接超时   数组我的Java插入排序逻辑有什么问题?   java使用Http客户端进行请求,该请求返回内容类型为“application/vnd.msexcel”的jsp页面   java连接到数据库(Derby)   url编码如何使用java发布而不使用url编码url的查询部分   正则表达式使用Java替换字符串中的模式   Java中声明数组的区别   java hibernate ReferenceColumnNames未映射到单个属性   java如何对地图集合的分层键进行排序?   java ValueAnimator在我的手机上似乎工作不正常   java如何使用Hibernate Lucene搜索访问实体中外键的排序字段名?   在同一台机器上以不同的JAVA路径运行两个Tomcat   java如何在Eclipse中记录最新的git提交哈希?   java为什么我必须将JRE、编译器和facet全部降级为Java1。8在Eclipse中创建简单Web服务时   无法将java DataBufferInt解析为类型