summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--obnamlib/__init__.py1
-rw-r--r--obnamlib/store.py63
-rw-r--r--obnamlib/store_tree.py57
-rw-r--r--without-tests1
4 files changed, 72 insertions, 50 deletions
diff --git a/obnamlib/__init__.py b/obnamlib/__init__.py
index a1d812a6..008d3124 100644
--- a/obnamlib/__init__.py
+++ b/obnamlib/__init__.py
@@ -43,6 +43,7 @@ from vfs_local import LocalFS
from metadata import (read_metadata, set_metadata, Metadata, metadata_fields,
metadata_verify_fields)
from nodestorevfs import NodeStoreVfs
+from store_tree import StoreTree
from store import Store, LockFail
from forget_policy import ForgetPolicy
from app import App
diff --git a/obnamlib/store.py b/obnamlib/store.py
index a01e764b..b883bcf4 100644
--- a/obnamlib/store.py
+++ b/obnamlib/store.py
@@ -124,44 +124,7 @@ def decode_metadata(encoded):
return obnamlib.Metadata(**args)
-class StoreTree(object):
-
- '''A B-tree within a Store.'''
-
- def __init__(self, fs, dirname, key_bytes, node_size, upload_queue_size,
- lru_size):
- self.fs = fs
- self.dirname = dirname
- self.key_bytes = key_bytes
- self.node_size = node_size
- self.upload_queue_size = upload_queue_size
- self.lru_size = lru_size
- self.forest = None
-
- def init_forest(self):
- if self.forest is None:
- if not self.fs.exists(self.dirname):
- return False
- codec = btree.NodeCodec(self.key_bytes)
- ns = obnamlib.NodeStoreVfs(self.fs,
- self.dirname, self.node_size, codec,
- self.upload_queue_size, self.lru_size)
- self.forest = btree.Forest(ns)
- return True
-
- def require_forest(self):
- if not self.fs.exists(self.dirname):
- self.fs.mkdir(self.dirname)
- self.init_forest()
- assert self.forest is not None
-
- def commit(self):
- if self.forest:
- self.require_forest()
- self.forest.commit()
-
-
-class ClientList(StoreTree):
+class ClientList(obnamlib.StoreTree):
'''Store list of clients.
@@ -194,8 +157,8 @@ class ClientList(StoreTree):
self.key_bytes = len(self.key('', 0, 0))
self.minkey = self.hashkey('\x00' * self.hash_len, 0, 0)
self.maxkey = self.hashkey('\xff' * self.hash_len, 255, self.max_index)
- StoreTree.__init__(self, fs, 'clientlist', self.key_bytes, node_size,
- upload_queue_size, lru_size)
+ obnamlib.StoreTree.__init__(self, fs, 'clientlist', self.key_bytes,
+ node_size, upload_queue_size, lru_size)
def hashfunc(self, string):
return hashlib.new('md5', string).digest()
@@ -273,7 +236,7 @@ class ClientList(StoreTree):
t.remove(self.key(client_name, self.type_name, index))
-class GenerationStore(StoreTree):
+class GenerationStore(obnamlib.StoreTree):
'''Store generations.
@@ -327,8 +290,8 @@ class GenerationStore(StoreTree):
def __init__(self, fs, client_id, node_size, upload_queue_size, lru_size):
key_bytes = len(self.key('', 0, 0))
- StoreTree.__init__(self, fs, client_id, key_bytes, node_size,
- upload_queue_size, lru_size)
+ obnamlib.StoreTree.__init__(self, fs, client_id, key_bytes, node_size,
+ upload_queue_size, lru_size)
self.curgen = None
self.known_generations = dict()
@@ -540,7 +503,7 @@ class GenerationStore(StoreTree):
struct.pack('!Q', cgid))
-class ChecksumTree(StoreTree):
+class ChecksumTree(obnamlib.StoreTree):
'''Store map of checksum to integer id.
@@ -554,8 +517,8 @@ class ChecksumTree(StoreTree):
upload_queue_size, lru_size):
self.sumlen = checksum_length
key_bytes = len(self.key('', 0))
- StoreTree.__init__(self, fs, name, key_bytes, node_size,
- upload_queue_size, lru_size)
+ obnamlib.StoreTree.__init__(self, fs, name, key_bytes, node_size,
+ upload_queue_size, lru_size)
self.max_id = 2**64 - 1
def key(self, checksum, number):
@@ -589,7 +552,7 @@ class ChecksumTree(StoreTree):
t.remove(self.key(checksum, identifier))
-class ChunkGroupTree(StoreTree):
+class ChunkGroupTree(obnamlib.StoreTree):
'''Store chunk groups.
@@ -602,9 +565,9 @@ class ChunkGroupTree(StoreTree):
# the chunks are stored as the value, as a blob, using struct.
def __init__(self, fs, node_size, upload_queue_size, lru_size):
- StoreTree.__init__(self, fs, 'chunkgroups',
- len(self.key(0)), node_size, upload_queue_size,
- lru_size)
+ obnamlib.StoreTree.__init__(self, fs, 'chunkgroups',
+ len(self.key(0)), node_size,
+ upload_queue_size, lru_size)
self.max_id = 2**64 - 1
def key(self, cgid):
diff --git a/obnamlib/store_tree.py b/obnamlib/store_tree.py
new file mode 100644
index 00000000..4be15cb6
--- /dev/null
+++ b/obnamlib/store_tree.py
@@ -0,0 +1,57 @@
+# Copyright 2010 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import btree
+
+import obnamlib
+
+
+class StoreTree(object):
+
+ '''A B-tree within a Store.'''
+
+ def __init__(self, fs, dirname, key_bytes, node_size, upload_queue_size,
+ lru_size):
+ self.fs = fs
+ self.dirname = dirname
+ self.key_bytes = key_bytes
+ self.node_size = node_size
+ self.upload_queue_size = upload_queue_size
+ self.lru_size = lru_size
+ self.forest = None
+
+ def init_forest(self):
+ if self.forest is None:
+ if not self.fs.exists(self.dirname):
+ return False
+ codec = btree.NodeCodec(self.key_bytes)
+ ns = obnamlib.NodeStoreVfs(self.fs,
+ self.dirname, self.node_size, codec,
+ self.upload_queue_size, self.lru_size)
+ self.forest = btree.Forest(ns)
+ return True
+
+ def require_forest(self):
+ if not self.fs.exists(self.dirname):
+ self.fs.mkdir(self.dirname)
+ self.init_forest()
+ assert self.forest is not None
+
+ def commit(self):
+ if self.forest:
+ self.require_forest()
+ self.forest.commit()
+
diff --git a/without-tests b/without-tests
index a73a9492..6f549132 100644
--- a/without-tests
+++ b/without-tests
@@ -21,3 +21,4 @@
./obnamlib/plugins/__init__.py
./obnamlib/nodestorevfs.py
+./obnamlib/store_tree.py