whee

Unified interface to key value with locking and transactions.
Log | Files | Refs | README | LICENSE

commit 03061bbc706d5bc7c94660d444f108dec0931e58
parent 83dc671e5fecd68498414d6bd90fc01c82eb2726
Author: lash <dev@holbrook.no>
Date:   Thu, 26 Mar 2026 13:53:14 -0600

Add missing package, fix short fs keys

Diffstat:
Msetup.py | 3++-
Mtests/test_fs.py | 16++++++++++++++--
Mwhee/fs/__init__.py | 22++++++++++++++--------
3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/setup.py b/setup.py @@ -6,7 +6,7 @@ f.close() setup( name='wheepy', - version='0.0.5', + version='0.0.5a2', description='Unified interface to key value with locking and transactions.', author='Louis Holbrook', author_email='dev@holbrook.no', @@ -22,6 +22,7 @@ setup( 'whee', 'whee.couchdb', 'whee.valkey', + 'whee.fs', ], url='https://holbrook.no/src/whee/', ) diff --git a/tests/test_fs.py b/tests/test_fs.py @@ -2,6 +2,7 @@ import logging import unittest import tempfile import uuid +import shutil from whee.fs import FsStore @@ -12,9 +13,13 @@ logg = logging.getLogger() class TestFs(unittest.TestCase): def setUp(self): - dp = tempfile.mkdtemp() + self.base = tempfile.mkdtemp() uu = uuid.uuid4() - self.store = FsStore(base=dp, dbname=str(uu), levels=2) + self.store = FsStore(base=self.base, dbname=str(uu), levels=2) + + + def tearDown(self): + shutil.rmtree(self.base) def test_get_put(self): @@ -34,5 +39,12 @@ class TestFs(unittest.TestCase): with self.assertRaises(FileNotFoundError): self.store.delete(b'foo') + + def test_short(self): + self.store.put(b'f', b'oo') + self.store.put(b'fo', b'o') + self.store.put(b'foo', b'') + + if __name__ == '__main__': unittest.main() diff --git a/whee/fs/__init__.py b/whee/fs/__init__.py @@ -43,6 +43,7 @@ class FsStore(Interface): f = open(fp, 'wb') f.write(v) f.close() + logg.debug('fs put {} under {}'.format(k, fp)) def delete(self, k): @@ -51,18 +52,23 @@ class FsStore(Interface): def to_levelpath(self, k): + s = '' if isinstance(k, bytes): k = k.hex() else: bytes.fromhex(k) - s = '' + l = len(k) - c = 0 - for i in range(self.levels): - s += k[c:c+2] + '/' - c += 2 - if c == l: - s = s[:-1] + if l <= self.levels * 2: + #levels = len(k) - 1 + s = '_/' + k else: - s += k[c:] + c = 0 + for i in range(self.levels): + s += k[c:c+2] + '/' + c += 2 + if c == l: + s = s[:-1] + else: + s += k[c:] return os.path.join(self.base, s)