summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-07-31 14:09:48 +0100
committerLars Wirzenius <liw@liw.fi>2011-07-31 14:09:48 +0100
commit136357264c64eb58f3a8b890a426b8fcd58f86e2 (patch)
tree9599905ca9518681a6ab08dcac002552bbe8c9e3
parentf13421bf2c8e0120539f1d4199f73feeb2d39e57 (diff)
downloadobnam-136357264c64eb58f3a8b890a426b8fcd58f86e2.tar.gz
Move idpath to larch.
-rwxr-xr-xidpath-speed48
-rw-r--r--obnamlib/__init__.py1
-rw-r--r--obnamlib/idpath.py45
-rw-r--r--obnamlib/idpath_tests.py59
-rw-r--r--obnamlib/repo.py5
5 files changed, 3 insertions, 155 deletions
diff --git a/idpath-speed b/idpath-speed
deleted file mode 100755
index 42257a72..00000000
--- a/idpath-speed
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/usr/bin/python
-# 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 os
-import sys
-import time
-
-import obnamlib
-
-
-def main():
- n = int(sys.argv[1])
- dirname = sys.argv[2]
- depth = int(sys.argv[3])
- bits = int(sys.argv[4])
- skip = int(sys.argv[5])
-
- idpath = obnamlib.IdPath(dirname, depth, bits, skip)
- start = time.time()
- for i in xrange(n):
- path = idpath.convert(i)
- dirname = os.path.dirname(path)
- if not os.path.exists(dirname):
- os.makedirs(dirname)
- with open(path, 'w'):
- pass
- end = time.time()
-
- duration = end - start
- speed = n / duration
- print '%d ids, %.1f seconds, %.1f ids/s' % (n, duration, speed)
-
-if __name__ == '__main__':
- main()
diff --git a/obnamlib/__init__.py b/obnamlib/__init__.py
index 9d917bc9..9148516c 100644
--- a/obnamlib/__init__.py
+++ b/obnamlib/__init__.py
@@ -70,7 +70,6 @@ from chunklist import ChunkList
from clientlist import ClientList
from checksumtree import ChecksumTree
from clientmetadatatree import ClientMetadataTree
-from idpath import IdPath
from repo import Repository, LockFail, BadFormat
from forget_policy import ForgetPolicy
from app import App
diff --git a/obnamlib/idpath.py b/obnamlib/idpath.py
deleted file mode 100644
index c0e80596..00000000
--- a/obnamlib/idpath.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright 2011 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 os
-
-
-class IdPath(object):
-
- '''Convert a numeric id to a pathname.
-
- The ids are stored in a directory hierarchy, the depth of which
- can be adjusted by a parameter to the class. The ids are assumed
- to be non-negative integers.
-
- '''
-
- def __init__(self, dirname, depth, bits_per_level, skip_bits):
- self.dirname = dirname
- self.depth = depth
- self.bits_per_level = bits_per_level
- self.skip_bits = skip_bits
-
- def convert(self, identifier):
- def level_bits(level):
- level_mask = 2**self.bits_per_level - 1
- n = self.skip_bits + level * self.bits_per_level
- return (identifier >> n) & level_mask
-
- subdirs = ['%d' % level_bits(i) for i in range(self.depth)]
- parts = [self.dirname] + subdirs + ['%x' % identifier]
- return os.path.join(*parts)
-
diff --git a/obnamlib/idpath_tests.py b/obnamlib/idpath_tests.py
deleted file mode 100644
index 563e3338..00000000
--- a/obnamlib/idpath_tests.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# Copyright 2011 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 os
-import shutil
-import tempfile
-import unittest
-
-import obnamlib
-
-
-class IdPathTests(unittest.TestCase):
-
- def setUp(self):
- self.tempdir = tempfile.mkdtemp()
- self.depth = 3
- bits = 1
- skip = 0
- self.idpath = obnamlib.IdPath(self.tempdir, self.depth, bits, skip)
-
- def tearDown(self):
- shutil.rmtree(self.tempdir)
-
- def test_returns_string(self):
- self.assertEqual(type(self.idpath.convert(1)), str)
-
- def test_starts_with_designated_path(self):
- path = self.idpath.convert(1)
- self.assert_(path.startswith(self.tempdir))
-
- def test_different_ids_return_different_values(self):
- path1 = self.idpath.convert(42)
- path2 = self.idpath.convert(1024)
- self.assertNotEqual(path1, path2)
-
- def test_same_id_returns_same_path(self):
- path1 = self.idpath.convert(42)
- path2 = self.idpath.convert(42)
- self.assertEqual(path1, path2)
-
- def test_uses_desired_depth(self):
- path = self.idpath.convert(1)
- subpath = path[len(self.tempdir + os.sep):]
- subdir = os.path.dirname(subpath)
- self.assertEqual(len(subdir.split(os.sep)), self.depth)
-
diff --git a/obnamlib/repo.py b/obnamlib/repo.py
index 501d6dd6..92f116ec 100644
--- a/obnamlib/repo.py
+++ b/obnamlib/repo.py
@@ -16,6 +16,7 @@
import errno
import hashlib
+import larch
import logging
import os
import random
@@ -145,8 +146,8 @@ class Repository(object):
node_size, upload_queue_size,
lru_size, self)
self.prev_chunkid = None
- self.chunk_idpath = obnamlib.IdPath('chunks', idpath_depth,
- idpath_bits, idpath_skip)
+ self.chunk_idpath = larch.IdPath('chunks', idpath_depth,
+ idpath_bits, idpath_skip)
def setup_hooks(self, hooks):
self.hooks = hooks