Commits

Ronny Pfannschmidt committed 510b439

simplify naming of the backend api around store/retrieve/remove

  • Participants
  • Parent commits b69c1a7

Comments (0)

Files changed (9)

File backend/__init__.py

         """
 
     @abstractmethod
-    def get_revision(self, metaid):
+    def retrieve(self, metaid):
         """
         return meta, data related to metaid
         """
         """
 
     @abstractmethod
-    def store_revision(self, meta, data):
+    def store(self, meta, data):
         """
         store meta, data into the backend, return the metaid
         """
 
     @abstractmethod
-    def del_revision(self, metaid):
+    def remove(self, metaid):
         """
         delete meta, data related to metaid from the backend
         """

File backend/_tests/__init__.py

 
     def test_getrevision_raises(self):
         with pytest.raises(KeyError):
-            self.be.get_revision('doesnotexist')
+            self.be.retrieve('doesnotexist')
 
     def test_iter(self):
         assert list(self.be) == []
 
     def test_getrevision_raises(self):
         with pytest.raises(KeyError):
-            self.be.get_revision('doesnotexist')
+            self.be.retrieve('doesnotexist')
 
     def test_store_get_del(self):
         meta = dict(foo='bar')
         data = 'baz'
-        metaid = self.be.store_revision(meta, StringIO(data))
-        m, d = self.be.get_revision(metaid)
+        metaid = self.be.store(meta, StringIO(data))
+        m, d = self.be.retrieve(metaid)
         assert m == meta
         assert d.read() == data
-        self.be.del_revision(metaid)
+        self.be.remove(metaid)
         with pytest.raises(KeyError):
-            self.be.get_revision(metaid)
+            self.be.retrieve(metaid)
 
     def test_iter(self):
         mds = [#(metadata items, data str)
               ]
         expected_result = set()
         for m, d in mds:
-            k = self.be.store_revision(m, StringIO(d))
+            k = self.be.store(m, StringIO(d))
             # note: store_revision injects some new keys (like dataid, metaid, size, hash key) into m
             m = tuple(sorted(m.items()))
             expected_result.add((k, m, d))
         result = set()
         for k in self.be:
-            m, d = self.be.get_revision(k)
+            m, d = self.be.retrieve(k)
             m = tuple(sorted(m.items()))
             result.add((k, m, d.read()))
         assert result == expected_result

File backend/_tests/test_fileserver.py

         expected_result = self._prepare(items)
         result = set()
         for i in self.be:
-            meta, data = self.be.get_revision(i)
+            meta, data = self.be.retrieve(i)
             # we don't want to check mtime
             del meta['mtime']
             meta = tuple(sorted(meta.items()))
         expected_result.add((dir_meta, dir_data))
         result = set()
         for i in self.be:
-            meta, data = self.be.get_revision(i)
+            meta, data = self.be.retrieve(i)
             # we don't want to check mtime
             del meta['mtime']
             meta = tuple(sorted(meta.items()))

File backend/fileserver.py

                 raise KeyError(fn)
             raise
 
-    def get_revision(self, fn):
+    def retrieve(self, fn):
         meta = self._get_meta(fn)
         data = self._get_data(fn)
         return meta, data

File backend/storages.py

         # a file-like object).
         return data
 
-    def get_revision(self, metaid):
+    def retrieve(self, metaid):
         meta = self._get_meta(metaid)
         dataid = meta['dataid']
         data = self._get_data(dataid)
         self.meta_store[metaid] = meta
         return metaid
 
-    def store_revision(self, meta, data):
+    def store(self, meta, data):
         # XXX Idea: we could check the type the store wants from us:
         # if it is a str/bytes (BytesStorage), just use meta "as is",
         # if it is a file (FileStorage), wrap it into StringIO and give that to the store.
     def _del_data(self, dataid):
         del self.data_store[dataid]
 
-    def del_revision(self, metaid):
+    def remove(self, metaid):
         meta = self._get_meta(metaid)
         dataid = meta['dataid']
         self._del_meta(metaid)

File middleware/_tests/test_router.py

 def make_ro_backend():
     store = StorageBackend(MemoryBytesStorage(), MemoryFileStorage())
     store.create()
-    store.store_revision({NAME:'test'}, StringIO(''))
-    store.store_revision({NAME:'test2'}, StringIO(''))
+    store.store({NAME:'test'}, StringIO(''))
+    store.store({NAME:'test2'}, StringIO(''))
     return ROBackend(store.meta_store, store.data_store)
 
 
 
 def test_store_get_del(router):
     root_name = u'foo'
-    root_revid = router.store_revision(dict(name=root_name), StringIO(''))
+    root_revid = router.store(dict(name=root_name), StringIO(''))
     sub_name = u'sub/bar'
-    sub_revid = router.store_revision(dict(name=sub_name), StringIO(''))
+    sub_revid = router.store(dict(name=sub_name), StringIO(''))
 
     assert revid_split(root_revid)[0] == ''
     assert revid_split(sub_revid)[0] == 'sub'
 
     # when going via the router backend, we get back fully qualified names:
-    root_meta, _ = router.get_revision(root_revid)
-    sub_meta, _ = router.get_revision(sub_revid)
+    root_meta, _ = router.retrieve(root_revid)
+    sub_meta, _ = router.retrieve(sub_revid)
     assert root_name == root_meta[NAME]
     assert sub_name == sub_meta[NAME]
 
     # when looking into the storage backend, we see relative names (without mountpoint):
-    root_meta, _ = router.mapping[-1][1].get_revision(revid_split(root_revid)[1])
-    sub_meta, _ = router.mapping[0][1].get_revision(revid_split(sub_revid)[1])
+    root_meta, _ = router.mapping[-1][1].retrieve(revid_split(root_revid)[1])
+    sub_meta, _ = router.mapping[0][1].retrieve(revid_split(sub_revid)[1])
     assert root_name == root_meta[NAME]
     assert sub_name == 'sub' + '/' + sub_meta[NAME]
     # delete revs:
-    router.del_revision(root_revid)
-    router.del_revision(sub_revid)
+    router.remove(root_revid)
+    router.remove(sub_revid)
 
 
 def test_store_readonly_fails(router):
     with pytest.raises(TypeError):
-        router.store_revision(dict(name=u'ro/testing'), StringIO(''))
+        router.store(dict(name=u'ro/testing'), StringIO(''))
 
 def test_del_readonly_fails(router):
     ro_id = next(iter(router)) # we have only readonly items
     print ro_id
     with pytest.raises(TypeError):
-        router.del_revision(ro_id)
+        router.remove(ro_id)
 
 
 def test_destroy_create_dont_touch_ro(router):
     existing = set(router)
-    root_revid = router.store_revision(dict(name=u'foo'), StringIO(''))
-    sub_revid = router.store_revision(dict(name=u'sub/bar'), StringIO(''))
+    root_revid = router.store(dict(name=u'foo'), StringIO(''))
+    sub_revid = router.store(dict(name=u'sub/bar'), StringIO(''))
 
     router.destroy()
     router.create()
 
 def test_iter(router):
     existing = set(router)
-    root_revid = router.store_revision(dict(name=u'foo'), StringIO(''))
-    sub_revid = router.store_revision(dict(name=u'sub/bar'), StringIO(''))
+    root_revid = router.store(dict(name=u'foo'), StringIO(''))
+    sub_revid = router.store(dict(name=u'sub/bar'), StringIO(''))
     assert set(router) == (set([root_revid, sub_revid])|existing)
 

File middleware/indexing.py

         with writer as writer:
             for revid in revids:
                 if mode in ['add', 'update', ]:
-                    meta, data = self.backend.get_revision(revid)
+                    meta, data = self.backend.retrieve(revid)
                     content = convert_to_indexable(meta, data)
                     doc = backend_to_index(meta, content, schema, wikiname)
                 if mode == 'update':
             self.itemid = make_uuid()
         meta[ITEMID] = self.itemid
         backend = self.backend
-        revid = backend.store_revision(meta, data)
+        revid = backend.store(meta, data)
         data.seek(0)  # rewind file
         self.indexer.index_revision(revid, meta, data)
         self._current = self.indexer.document(all_revs=False, acl_check=False, revid=revid)
         """
         self.require('clear')
         backend = self.backend
-        meta, data = backend.get_revision(revid) # raises KeyError if rev does not exist
+        meta, data = backend.retrieve(revid) # raises KeyError if rev does not exist
         meta[COMMENT] = reason or u'destroyed'
         # TODO cleanup more metadata
         data = StringIO('') # nothing to see there
         del meta['dataid'] # remove dataid
-        revid = backend.store_revision(meta, data)
+        revid = backend.store(meta, data)
         # Note: we just stored new (empty) data for this revision, but the old
         # data file is still in storage (not referenced by THIS revision any more)
         data.seek(0)  # rewind file
         Note: "destroy" means: we delete the revision from the backend
         """
         self.require('destroy')
-        self.backend.del_revision(revid)
+        self.backend.remove(revid)
         self.indexer.del_revision(revid)
         
     def destroy_item(self):
         self.item = item
         self.revid = revid
         self.backend = item.backend
-        self.meta, self.data = self.backend.get_revision(self.revid) # raises KeyError if rev does not exist
+        self.meta, self.data = self.backend.retrieve(self.revid) # raises KeyError if rev does not exist
 
     def close(self):
         self.data.close()

File middleware/router.py

             for revid in backend:
                 yield u'%s/%s' % (mountpoint, revid)
 
-    def get_revision(self, revid):
+    def retrieve(self, revid):
         mountpoint, revid = revid.rsplit(u'/', 1)
         backend = self._get_backend(mountpoint)[0]
-        meta, data = backend.get_revision(revid)
+        meta, data = backend.retrieve(revid)
         if mountpoint:
             meta[NAME] = u'%s/%s' % (mountpoint, meta[NAME])
         return meta, data
                 backend.destroy()
             #XXX log info?
 
-    def store_revision(self, meta, data):
+    def store(self, meta, data):
         itemname = meta[NAME]
         backend, itemname, mountpoint = self._get_backend(itemname)
         if not isinstance(backend, MutableBackendBase):
             raise TypeError('backend %r mounted at %r is readonly' % (
                 backend, mountpoint))
         meta[NAME] = itemname
-        return u'%s/%s' % (mountpoint, backend.store_revision(meta, data))
+        return u'%s/%s' % (mountpoint, backend.store(meta, data))
 
-    def del_revision(self, revid):
+    def remove(self, revid):
         mountpoint, revid = revid.rsplit(u'/', 1)
         backend = self._get_backend(mountpoint)[0]
         if not isinstance(backend, MutableBackendBase):
             raise TypeError('backend %r mounted at %r is readonly' % (
                 backend, mountpoint))
-        backend.del_revision(revid)
+        backend.remove(revid)
 

File middleware/serializer.py

 
 def serialize_iter(backend):
     for revid in backend:
-        meta, data = backend.get_revision(revid)
+        meta, data = backend.retrieve(revid)
 
         text = json.dumps(meta, ensure_ascii=False)
         meta_str = text.encode('utf-8')
         data_size = meta[u'size']
 
         limited = LimitedStream(src, data_size)
-        backend.store_revision(meta, limited)
+        backend.store(meta, limited)
         assert limited.is_exhausted