leveldir

Multi-level directory structure data stores in python3
git clone git://git.defalsify.org/python-leveldir.git
Log | Files | Refs | LICENSE

commit 1991e2cb7c6837dd98b60865c8ec798ffd4ef212
parent d814fca7797204b300352f108ef42a5641d11be4
Author: nolash <dev@holbrook.no>
Date:   Sun, 27 Jun 2021 10:49:03 +0200

Make numdir values cumulative

Diffstat:
MCHANGELOG | 2++
Mleveldir/base.py | 11+++++++++++
Mleveldir/hex.py | 11-----------
Mleveldir/numeric.py | 4+++-
Msetup.cfg | 2+-
Mtests/test_numdir.py | 3+--
6 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,5 @@ +- 0.0.2 + * make subdir values cumulative in numdir - 0.0.1 * add hexdir * add numdir diff --git a/leveldir/base.py b/leveldir/base.py @@ -1,5 +1,6 @@ # standard imports import os +import stat class LevelDir: @@ -17,6 +18,16 @@ class LevelDir: self.master_file = os.path.join(self.path, 'master') + def __verify_directory(self): + fi = os.stat(self.path) + if not stat.S_ISDIR(fi.st_mode): + raise ValueError('{} is not a directory'.format(self.path)) + #f = os.listdir(self.path) + #os.listdir(self.path) + #f.close() + return True + + def count(self): fi = os.stat(self.master_file) c = fi.st_size / self.entry_length diff --git a/leveldir/hex.py b/leveldir/hex.py @@ -1,6 +1,5 @@ # standard imports import os -import stat import logging # external imports @@ -99,16 +98,6 @@ class HexDir(LevelDir): return file_path - def __verify_directory(self): - fi = stat(self.path) - if not stat.S_ISDIR(fi.st_mode): - raise ValueError('{} is not a directory'.format(self.path)) - #f = os.listdir(self.path) - #os.listdir(self.path) - #f.close() - return True - - @staticmethod def __prepare_directory(path): os.makedirs(path, exist_ok=True) diff --git a/leveldir/numeric.py b/leveldir/numeric.py @@ -30,10 +30,12 @@ class NumDir(LevelDir): c = n x = 0 d = [] + v = 0 for t in self.thresholds: x = math.floor(c / t) y = x * t - d.append(str(y)) + v += y + d.append(str(v)) c -= y return os.path.join(self.path, *d) diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = leveldir -version = 0.0.1 +version = 0.0.2 description = Create multi-level directory structures author = Louis Holbrook author_email = dev@holbrook.no diff --git a/tests/test_numdir.py b/tests/test_numdir.py @@ -34,7 +34,7 @@ class NumDirTest(unittest.TestCase): (path, two) = os.path.split(path) (path, one) = os.path.split(path) self.assertEqual(three, '1337') - self.assertEqual(two, '300') + self.assertEqual(two, '1300') self.assertEqual(one, '1000') @@ -59,7 +59,6 @@ class NumDirTest(unittest.TestCase): def test_multilevel(self): - logg.debug('using dir {}'.format(self.dir)) self.numdir = NumDir(os.path.join(self.dir, 'n'), [1000, 100, 10]) b = os.urandom(32) self.numdir.add(1337, b)