diff options
author | Antoine Brenner <brenner+obnam@gymglish.com> | 2013-01-16 22:58:35 +0100 |
---|---|---|
committer | Antoine Brenner <brenner+obnam@gymglish.com> | 2013-01-16 22:58:35 +0100 |
commit | 42d9d6c7d048580e06cab7003db5fdd61a0a3f11 (patch) | |
tree | 6fe572dc8904d0b487755ccadeae08db557da01c /example.py | |
parent | 206fb1529bf3bef9c51e9c47dd5b3fa053c485ba (diff) | |
parent | 76fdb08a8660fc2abe7caecbd2ffca98c9ff06f5 (diff) | |
download | larch-42d9d6c7d048580e06cab7003db5fdd61a0a3f11.tar.gz |
Repair non-working example.py and speed-test
The introduction of the allow_writes parameter in larch/forest.py:open_forest()
broke example.py and speed-test.
Just adding the parameter to the open_forest calls was not enough to fix the
issue. This patch fixes the issue by adding the allow_writes parameter where it
is needed beyond the open_forest calls.
Most notably, this patch changes the __init__ signature of the abstract base
class larch.NodeStore from __init__(self, node_size, codec) to
__init__(self, allow_writes, node_size, codec)
This mimicks the current signatures of NodeStoreDisk and NodeStoreMemory, which
include the use of allow_writes as first parameter, and which seem required
to actually create a forest anyway since forest.py creates node_store instances
with allow_writes as first parameter in open_forest
Diffstat (limited to 'example.py')
-rw-r--r-- | example.py | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -33,11 +33,11 @@ def compute(filename): return md5.hexdigest() -def open_tree(dirname): +def open_tree(allow_writes, dirname): key_size = len(compute('/dev/null')) node_size = 4096 - forest = larch.open_forest(key_size=key_size, node_size=node_size, + forest = larch.open_forest(allow_writes=allow_writes, key_size=key_size, node_size=node_size, dirname=dirname) if forest.trees: tree = forest.trees[0] @@ -47,7 +47,7 @@ def open_tree(dirname): def add(filenames): - forest, tree = open_tree('example.tree') + forest, tree = open_tree(allow_writes=True, dirname='example.tree') for filename in filenames: checksum = compute(filename) tree.insert(checksum, filename) @@ -55,17 +55,17 @@ def add(filenames): def find(checksums): - forest, tree = open_tree('example.tree') + forest, tree = open_tree(allow_writes=False, dirname='example.tree') for checksum in checksums: filename = tree.lookup(checksum) print checksum, filename def list_checksums(): - forest, tree = open_tree('example.tree') + forest, tree = open_tree(allow_writes=False, dirname='example.tree') key_size = len(compute('/dev/null')) - minkey = '00' * key_size - maxkey = 'ff' * key_size + minkey = '0' * key_size + maxkey = 'f' * key_size for checksum, filename in tree.lookup_range(minkey, maxkey): print checksum, filename |