summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@gytha>2008-06-10 22:20:05 +0300
committerLars Wirzenius <liw@gytha>2008-06-10 22:20:05 +0300
commit4b378dde1770d97d1aab9f460685093d733a717c (patch)
treefd9e8378a1ecd0aae54aeb30f92059d62ab31bf7
parentfa8f864c610707128e78b13b84ca5e8b353894fc (diff)
downloadobnam-4b378dde1770d97d1aab9f460685093d733a717c.tar.gz
Renamed obnam/ to obnamlib/ so that we can later rename cli.py to obnam.
-rw-r--r--check-license-exceptions2
-rw-r--r--obnam/mapTests.py113
-rw-r--r--obnamlib/__init__.py (renamed from obnam/__init__.py)1
-rw-r--r--obnamlib/app.py (renamed from obnam/app.py)66
-rw-r--r--obnamlib/appTests.py (renamed from obnam/appTests.py)202
-rw-r--r--obnamlib/backend.py (renamed from obnam/backend.py)9
-rw-r--r--obnamlib/backendTests.py (renamed from obnam/backendTests.py)54
-rw-r--r--obnamlib/cache.py (renamed from obnam/cache.py)0
-rw-r--r--obnamlib/cacheTests.py (renamed from obnam/cacheTests.py)12
-rw-r--r--obnamlib/cfgfile.py (renamed from obnam/cfgfile.py)4
-rw-r--r--obnamlib/cfgfileTests.py (renamed from obnam/cfgfileTests.py)46
-rw-r--r--obnamlib/cmp.py (renamed from obnam/cmp.py)68
-rw-r--r--obnamlib/cmpTests.py (renamed from obnam/cmpTests.py)98
-rw-r--r--obnamlib/config.py (renamed from obnam/config.py)14
-rw-r--r--obnamlib/configTests.py (renamed from obnam/configTests.py)178
-rw-r--r--obnamlib/context.py (renamed from obnam/context.py)16
-rw-r--r--obnamlib/contextTests.py (renamed from obnam/contextTests.py)6
-rw-r--r--obnamlib/defaultconfig.py (renamed from obnam/defaultconfig.py)0
-rw-r--r--obnamlib/exception.py (renamed from obnam/exception.py)0
-rw-r--r--obnamlib/exceptionTests.py (renamed from obnam/exceptionTests.py)6
-rw-r--r--obnamlib/filelist.py (renamed from obnam/filelist.py)24
-rw-r--r--obnamlib/filelistTests.py (renamed from obnam/filelistTests.py)50
-rw-r--r--obnamlib/format.py (renamed from obnam/format.py)8
-rw-r--r--obnamlib/formatTests.py (renamed from obnam/formatTests.py)26
-rw-r--r--obnamlib/gpg.py (renamed from obnam/gpg.py)6
-rw-r--r--obnamlib/gpgTests.py (renamed from obnam/gpgTests.py)30
-rw-r--r--obnamlib/io.py (renamed from obnam/io.py)84
-rw-r--r--obnamlib/ioTests.py (renamed from obnam/ioTests.py)202
-rw-r--r--obnamlib/log.py (renamed from obnam/log.py)0
-rw-r--r--obnamlib/logTests.py (renamed from obnam/logTests.py)8
-rw-r--r--obnamlib/map.py (renamed from obnam/map.py)34
-rw-r--r--obnamlib/mapTests.py113
-rw-r--r--obnamlib/obj.py (renamed from obnam/obj.py)133
-rw-r--r--obnamlib/objTests.py (renamed from obnam/objTests.py)212
-rw-r--r--obnamlib/oper.py (renamed from obnam/oper.py)12
-rw-r--r--obnamlib/operTests.py (renamed from obnam/operTests.py)20
-rw-r--r--obnamlib/oper_backup.py (renamed from obnam/oper_backup.py)8
-rw-r--r--obnamlib/oper_forget.py (renamed from obnam/oper_forget.py)10
-rw-r--r--obnamlib/oper_generations.py (renamed from obnam/oper_generations.py)10
-rw-r--r--obnamlib/oper_restore.py (renamed from obnam/oper_restore.py)38
-rw-r--r--obnamlib/oper_show_generations.py (renamed from obnam/oper_show_generations.py)18
-rw-r--r--obnamlib/progress.py (renamed from obnam/progress.py)0
-rw-r--r--obnamlib/rsync.py (renamed from obnam/rsync.py)20
-rw-r--r--obnamlib/rsyncTests.py (renamed from obnam/rsyncTests.py)74
-rw-r--r--obnamlib/store.py (renamed from obnam/store.py)30
-rw-r--r--obnamlib/storeTests.py (renamed from obnam/storeTests.py)106
-rw-r--r--obnamlib/utils.py (renamed from obnam/utils.py)0
-rw-r--r--obnamlib/varint.py (renamed from obnam/varint.py)0
-rw-r--r--obnamlib/varintTests.py (renamed from obnam/varintTests.py)10
-rw-r--r--obnamlib/walk.py (renamed from obnam/walk.py)0
-rw-r--r--obnamlib/walk_tests.py (renamed from obnam/walk_tests.py)8
51 files changed, 1092 insertions, 1097 deletions
diff --git a/check-license-exceptions b/check-license-exceptions
index df4d4ef8..a3e69c9c 100644
--- a/check-license-exceptions
+++ b/check-license-exceptions
@@ -14,7 +14,7 @@ debian/prerm
debian/rules
HACKING
NEWS
-obnam/defaultconfig.py
+obnamlib/defaultconfig.py
odirect_pipe
sample-gpg-home/pubring.gpg
sample-gpg-home/secring.gpg
diff --git a/obnam/mapTests.py b/obnam/mapTests.py
deleted file mode 100644
index 563c08c6..00000000
--- a/obnam/mapTests.py
+++ /dev/null
@@ -1,113 +0,0 @@
-# Copyright (C) 2006 Lars Wirzenius <liw@iki.fi>
-#
-# 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 2 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-
-"""Unit tests for obnam.map."""
-
-
-import unittest
-
-
-import obnam
-
-
-class ObjectMappingTests(unittest.TestCase):
-
- def testInvalidBlockRaisesException(self):
- m = obnam.map.create()
- self.failUnlessRaises(obnam.obj.BlockWithoutCookie,
- obnam.map.decode_block, m, "pink")
-
- def testEmpty(self):
- m = obnam.map.create()
- self.failUnlessEqual(obnam.map.count(m), 0)
-
- def testGetNonexisting(self):
- m = obnam.map.create()
- self.failUnlessEqual(obnam.map.get(m, "pink"), None)
-
- def testAddOneMapping(self):
- m = obnam.map.create()
- obnam.map.add(m, "pink", "pretty")
- self.failUnlessEqual(obnam.map.count(m), 1)
-
- self.failUnlessEqual(obnam.map.get(m, "pink"), "pretty")
-
- def testAddTwoMappings(self):
- m = obnam.map.create()
- obnam.map.add(m, "pink", "pretty")
- self.failUnlessRaises(AssertionError, obnam.map.add,
- m, "pink", "beautiful")
-
- def testGetNewMappings(self):
- m = obnam.map.create()
- self.failUnlessEqual(obnam.map.get_new(m), [])
- obnam.map.add(m, "pink", "pretty")
- self.failUnlessEqual(obnam.map.get_new(m), ["pink"])
- obnam.map.reset_new(m)
- self.failUnlessEqual(obnam.map.get_new(m), [])
- obnam.map.add(m, "black", "beautiful")
- self.failUnlessEqual(obnam.map.get_new(m), ["black"])
-
- def testMappingEncodings(self):
- # Set up a mapping
- m = obnam.map.create()
-
- # It's empty; make sure encoding new ones returns an empty list
- list = obnam.map.encode_new(m)
- self.failUnlessEqual(list, [])
-
- # Add a mapping
- obnam.map.add(m, "pink", "pretty")
-
- # Encode the new mapping, make sure that goes well
- list = obnam.map.encode_new(m)
- self.failUnlessEqual(len(list), 1)
-
- # Make sure the encoding is correct
- list2 = obnam.cmp.Parser(list[0]).decode_all()
- self.failUnlessEqual(len(list2), 1)
- self.failUnlessEqual(list2[0].get_kind(), obnam.cmp.OBJMAP)
-
- list3 = list2[0].get_subcomponents()
- self.failUnlessEqual(len(list3), 2)
- self.failUnlessEqual(list3[0].get_kind(), obnam.cmp.BLOCKREF)
- self.failUnlessEqual(list3[0].get_string_value(), "pretty")
- self.failUnlessEqual(list3[1].get_kind(), obnam.cmp.OBJREF)
- self.failUnlessEqual(list3[1].get_string_value(), "pink")
-
- # Now try decoding with the official function
- block = obnam.map.encode_new_to_block(m, "black")
- m2 = obnam.map.create()
- obnam.map.decode_block(m2, block)
- self.failUnlessEqual(obnam.map.count(m2), 1)
- self.failUnlessEqual(obnam.map.get(m2, "pink"), "pretty")
-
- def testMappingEncodingsForTwoInOneBlock(self):
- m = obnam.map.create()
-
- obnam.map.add(m, "pink", "pretty")
- obnam.map.add(m, "black", "pretty")
-
- list = obnam.map.encode_new(m)
- self.failUnlessEqual(len(list), 1)
-
- block = obnam.map.encode_new_to_block(m, "box")
- m2 = obnam.map.create()
- obnam.map.decode_block(m2, block)
- self.failUnlessEqual(obnam.map.count(m), obnam.map.count(m2))
- self.failUnlessEqual(obnam.map.get(m2, "pink"), "pretty")
- self.failUnlessEqual(obnam.map.get(m2, "black"), "pretty")
diff --git a/obnam/__init__.py b/obnamlib/__init__.py
index 51e5ce15..4a50aa0c 100644
--- a/obnam/__init__.py
+++ b/obnamlib/__init__.py
@@ -24,6 +24,7 @@ VERSION = "0.9.2"
from exception import ObnamException
+import defaultconfig
import backend
import cache
import cfgfile
diff --git a/obnam/app.py b/obnamlib/app.py
index c085a70b..fc8900d6 100644
--- a/obnam/app.py
+++ b/obnamlib/app.py
@@ -24,7 +24,7 @@ import re
import stat
import time
-import obnam
+import obnamlib
@@ -42,7 +42,7 @@ class Application:
self._exclusion_regexps = []
self._filelist = None
self._prev_gen = None
- self._store = obnam.Store(self._context)
+ self._store = obnamlib.Store(self._context)
self._total = 0
# When we traverse the file system tree while making a backup,
@@ -89,7 +89,7 @@ class Application:
def prune(self, dirname, dirnames, filenames):
"""Remove excluded items from dirnames and filenames.
- Because this is called by obnam.walk.depth_first, the lists
+ Because this is called by obnamlib.walk.depth_first, the lists
are modified in place.
"""
@@ -105,7 +105,7 @@ class Application:
"""
- dirname = obnam.io.unsolve(self._context, dirname)
+ dirname = obnamlib.io.unsolve(self._context, dirname)
i = 0
while i < len(basenames):
@@ -218,9 +218,9 @@ class Application:
"""
logging.debug("Computing rsync signature for %s" % filename)
- sigdata = obnam.rsync.compute_signature(self._context, filename)
- id = obnam.obj.object_id_new()
- sig = obnam.obj.SignatureObject(id=id, sigdata=sigdata)
+ sigdata = obnamlib.rsync.compute_signature(self._context, filename)
+ id = obnamlib.obj.object_id_new()
+ sig = obnamlib.obj.SignatureObject(id=id, sigdata=sigdata)
self.get_store().queue_object(sig)
return sig
@@ -266,30 +266,30 @@ class Application:
def _reuse_existing(self, old_file):
logging.debug("Re-using existing file contents: %s" %
- old_file.first_string_by_kind(obnam.cmp.FILENAME))
- return (old_file.first_string_by_kind(obnam.cmp.CONTREF),
- old_file.first_string_by_kind(obnam.cmp.SIGREF),
- old_file.first_string_by_kind(obnam.cmp.DELTAREF))
+ old_file.first_string_by_kind(obnamlib.cmp.FILENAME))
+ return (old_file.first_string_by_kind(obnamlib.cmp.CONTREF),
+ old_file.first_string_by_kind(obnamlib.cmp.SIGREF),
+ old_file.first_string_by_kind(obnamlib.cmp.DELTAREF))
def _get_old_sig(self, old_file):
- old_sigref = old_file.first_string_by_kind(obnam.cmp.SIGREF)
+ old_sigref = old_file.first_string_by_kind(obnamlib.cmp.SIGREF)
if not old_sigref:
return None
old_sig = self.get_store().get_object(old_sigref)
if not old_sig:
return None
- return old_sig.first_string_by_kind(obnam.cmp.SIGDATA)
+ return old_sig.first_string_by_kind(obnamlib.cmp.SIGDATA)
def _compute_delta(self, old_file, filename):
old_sig_data = self._get_old_sig(old_file)
if old_sig_data:
logging.debug("Computing delta for %s" % filename)
- old_contref = old_file.first_string_by_kind(obnam.cmp.CONTREF)
- old_deltaref = old_file.first_string_by_kind(obnam.cmp.DELTAREF)
- deltapart_ids = obnam.rsync.compute_delta(self.get_context(),
+ old_contref = old_file.first_string_by_kind(obnamlib.cmp.CONTREF)
+ old_deltaref = old_file.first_string_by_kind(obnamlib.cmp.DELTAREF)
+ deltapart_ids = obnamlib.rsync.compute_delta(self.get_context(),
old_sig_data, filename)
- delta_id = obnam.obj.object_id_new()
- delta = obnam.obj.DeltaObject(id=delta_id,
+ delta_id = obnamlib.obj.object_id_new()
+ delta = obnamlib.obj.DeltaObject(id=delta_id,
deltapart_refs=deltapart_ids,
cont_ref=old_contref,
delta_ref=old_deltaref)
@@ -305,7 +305,7 @@ class Application:
def _backup_new(self, filename):
logging.debug("Storing new file %s" % filename)
- contref = obnam.io.create_file_contents_object(self._context,
+ contref = obnamlib.io.create_file_contents_object(self._context,
filename)
sig = self.compute_signature(filename)
sigref = sig.get_id()
@@ -318,11 +318,11 @@ class Application:
self._context.progress.update_current_action(filename)
st = os.lstat(filename)
if stat.S_ISREG(st.st_mode):
- unsolved = obnam.io.unsolve(self.get_context(), filename)
+ unsolved = obnamlib.io.unsolve(self.get_context(), filename)
old_file = self.get_file_in_previous_generation(unsolved)
if old_file:
- old_st = old_file.first_by_kind(obnam.cmp.STAT)
- old_st = obnam.cmp.parse_stat_component(old_st)
+ old_st = old_file.first_by_kind(obnamlib.cmp.STAT)
+ old_st = obnamlib.cmp.parse_stat_component(old_st)
if self.file_is_unchanged(old_st, st):
contref, sigref, deltaref = self._reuse_existing(old_file)
else:
@@ -347,8 +347,8 @@ class Application:
for filename in filenames:
if (not list or
len(list[-1].get_files()) >= MAX_PER_FILEGROUP):
- id = obnam.obj.object_id_new()
- list.append(obnam.obj.FileGroupObject(id=id))
+ id = obnamlib.obj.object_id_new()
+ list.append(obnamlib.obj.FileGroupObject(id=id))
self.add_to_filegroup(list[-1], filename)
self.get_store().queue_objects(list)
@@ -378,7 +378,7 @@ class Application:
"""
- unsolved = obnam.io.unsolve(self.get_context(), dirname)
+ unsolved = obnamlib.io.unsolve(self.get_context(), dirname)
logging.debug("Selecting files to backup in %s (unsolved)" % unsolved)
logging.debug("There are %d filenames currently" % len(filenames))
@@ -403,7 +403,7 @@ class Application:
def backup_one_dir(self, dirname, subdirs, filenames, is_root=False):
"""Back up non-recursively one directory.
- Return obnam.obj.DirObject that refers to the directory.
+ Return obnamlib.obj.DirObject that refers to the directory.
subdirs is the list of subdirectories (as DirObject) for this
directory.
@@ -428,16 +428,16 @@ class Application:
assert basename
logging.debug("Creating DirObject, basename: %s" % basename)
if is_root:
- name = obnam.io.unsolve(self.get_context(), dirname)
+ name = obnamlib.io.unsolve(self.get_context(), dirname)
else:
name = basename
- dir = obnam.obj.DirObject(id=obnam.obj.object_id_new(),
+ dir = obnamlib.obj.DirObject(id=obnamlib.obj.object_id_new(),
name=name,
stat=os.lstat(dirname),
dirrefs=dirrefs,
filegrouprefs=filegrouprefs)
- unsolved = obnam.io.unsolve(self.get_context(), dirname)
+ unsolved = obnamlib.io.unsolve(self.get_context(), dirname)
old_dir = self.get_dir_in_previous_generation(unsolved)
if old_dir and self.dir_is_unchanged(old_dir, dir):
logging.debug("Dir is unchanged: %s" % dirname)
@@ -452,17 +452,17 @@ class Application:
logging.debug("Backing up root %s" % root)
- resolved = obnam.io.resolve(self._context, root)
+ resolved = obnamlib.io.resolve(self._context, root)
logging.debug("Root resolves to %s" % resolved)
if not os.path.isdir(resolved):
- raise obnam.ObnamException("Not a directory: %s" % root)
+ raise obnamlib.ObnamException("Not a directory: %s" % root)
# FIXME: This needs to be able to handle non-directories, too!
subdirs_for_dir = {}
root_object = None
- for tuple in obnam.walk.depth_first(resolved, prune=self.prune):
+ for tuple in obnamlib.walk.depth_first(resolved, prune=self.prune):
dirname, dirnames, filenames = tuple
filenames.sort()
logging.debug("Walked to directory %s" % dirname)
@@ -504,7 +504,7 @@ class Application:
end = int(time.time())
dirrefs = [o.get_id() for o in root_objs]
- gen = obnam.obj.GenerationObject(id=obnam.obj.object_id_new(),
+ gen = obnamlib.obj.GenerationObject(id=obnamlib.obj.object_id_new(),
dirrefs=dirrefs, start=start,
end=end)
self.get_store().queue_object(gen)
diff --git a/obnam/appTests.py b/obnamlib/appTests.py
index 3973706d..0e1a171a 100644
--- a/obnam/appTests.py
+++ b/obnamlib/appTests.py
@@ -25,14 +25,14 @@ import socket
import tempfile
import unittest
-import obnam
+import obnamlib
class ApplicationTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
def testReturnsEmptyExclusionListInitially(self):
self.failUnlessEqual(self.app.get_exclusion_regexps(), [])
@@ -79,10 +79,10 @@ class ApplicationTests(unittest.TestCase):
class ApplicationLoadHostBlockTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
+ self.app = obnamlib.Application(context)
def tearDown(self):
for x in ["cache", "store"]:
@@ -98,13 +98,13 @@ class ApplicationLoadHostBlockTests(unittest.TestCase):
self.failUnlessEqual(host.get_contmap_block_ids(), [])
def testLoadsActualHostBlockWhenOneExists(self):
- context = obnam.context.Context()
- cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context = obnamlib.context.Context()
+ cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
host_id = context.config.get("backup", "host-id")
- temp = obnam.obj.HostBlockObject(host_id=host_id,
+ temp = obnamlib.obj.HostBlockObject(host_id=host_id,
gen_ids=["pink", "pretty"])
- obnam.io.upload_host_block(context, temp.encode())
+ obnamlib.io.upload_host_block(context, temp.encode())
host = self.app.load_host()
self.failUnlessEqual(host.get_generation_ids(), ["pink", "pretty"])
@@ -124,11 +124,11 @@ class ApplicationMakeFileGroupsTests(unittest.TestCase):
return list
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.tempdir = tempfile.mkdtemp()
- self.tempfiles = self.make_tempfiles(obnam.app.MAX_PER_FILEGROUP + 1)
+ self.tempfiles = self.make_tempfiles(obnamlib.app.MAX_PER_FILEGROUP + 1)
def tearDown(self):
shutil.rmtree(self.tempdir)
@@ -141,11 +141,11 @@ class ApplicationMakeFileGroupsTests(unittest.TestCase):
self.failUnlessEqual(len(self.app.make_filegroups(filenames)), 1)
def testReturnsOneFileGroupForMaxFilesPerGroup(self):
- filenames = self.tempfiles[:obnam.app.MAX_PER_FILEGROUP]
+ filenames = self.tempfiles[:obnamlib.app.MAX_PER_FILEGROUP]
self.failUnlessEqual(len(self.app.make_filegroups(filenames)), 1)
def testReturnsTwoFileGroupsForMaxFilesPerGroupPlusOne(self):
- filenames = self.tempfiles[:obnam.app.MAX_PER_FILEGROUP + 1]
+ filenames = self.tempfiles[:obnamlib.app.MAX_PER_FILEGROUP + 1]
self.failUnlessEqual(len(self.app.make_filegroups(filenames)), 2)
def testUsesJustBasenames(self):
@@ -157,16 +157,16 @@ class ApplicationMakeFileGroupsTests(unittest.TestCase):
class ApplicationUnchangedFileRecognitionTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
def testSameFileWhenStatIsIdentical(self):
- st = obnam.utils.make_stat_result()
+ st = obnamlib.utils.make_stat_result()
self.failUnless(self.app.file_is_unchanged(st, st))
def testSameFileWhenIrrelevantFieldsChange(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_ino=42,
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_ino=42,
st_atime=42,
st_blocks=42,
st_blksize=42,
@@ -174,50 +174,50 @@ class ApplicationUnchangedFileRecognitionTests(unittest.TestCase):
self.failUnless(self.app.file_is_unchanged(st1, st2))
def testChangedFileWhenDevChanges(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_dev=42)
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_dev=42)
self.failIf(self.app.file_is_unchanged(st1, st2))
def testChangedFileWhenModeChanges(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_mode=42)
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_mode=42)
self.failIf(self.app.file_is_unchanged(st1, st2))
def testChangedFileWhenNlinkChanges(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_nlink=42)
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_nlink=42)
self.failIf(self.app.file_is_unchanged(st1, st2))
def testChangedFileWhenUidChanges(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_uid=42)
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_uid=42)
self.failIf(self.app.file_is_unchanged(st1, st2))
def testChangedFileWhenGidChanges(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_gid=42)
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_gid=42)
self.failIf(self.app.file_is_unchanged(st1, st2))
def testChangedFileWhenSizeChanges(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_size=42)
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_size=42)
self.failIf(self.app.file_is_unchanged(st1, st2))
def testChangedFileWhenMtimeChanges(self):
- st1 = obnam.utils.make_stat_result()
- st2 = obnam.utils.make_stat_result(st_mtime=42)
+ st1 = obnamlib.utils.make_stat_result()
+ st2 = obnamlib.utils.make_stat_result(st_mtime=42)
self.failIf(self.app.file_is_unchanged(st1, st2))
class ApplicationUnchangedFileGroupTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.dir = "dirname"
self.stats = {
- "dirname/pink": obnam.utils.make_stat_result(st_mtime=42),
- "dirname/pretty": obnam.utils.make_stat_result(st_mtime=105),
+ "dirname/pink": obnamlib.utils.make_stat_result(st_mtime=42),
+ "dirname/pretty": obnamlib.utils.make_stat_result(st_mtime=105),
}
def mock_stat(self, filename):
@@ -225,7 +225,7 @@ class ApplicationUnchangedFileGroupTests(unittest.TestCase):
return self.stats[filename]
def mock_filegroup(self, filenames):
- fg = obnam.obj.FileGroupObject(id=obnam.obj.object_id_new())
+ fg = obnamlib.obj.FileGroupObject(id=obnamlib.obj.object_id_new())
for filename in filenames:
st = self.mock_stat(os.path.join(self.dir, filename))
fg.add_file(filename, st, None, None, None)
@@ -241,7 +241,7 @@ class ApplicationUnchangedFileGroupTests(unittest.TestCase):
def testChangedFileGroupWhenFileHasChanged(self):
filenames = ["pink", "pretty"]
fg = self.mock_filegroup(filenames)
- self.stats["dirname/pink"] = obnam.utils.make_stat_result(st_mtime=1)
+ self.stats["dirname/pink"] = obnamlib.utils.make_stat_result(st_mtime=1)
self.failIf(self.app.filegroup_is_unchanged(self.dir, fg, filenames,
stat=self.mock_stat))
@@ -256,13 +256,13 @@ class ApplicationUnchangedFileGroupTests(unittest.TestCase):
class ApplicationUnchangedDirTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
def make_dir(self, name, dirrefs, filegrouprefs, stat=None):
if stat is None:
- stat = obnam.utils.make_stat_result()
- return obnam.obj.DirObject(id=obnam.obj.object_id_new(),
+ stat = obnamlib.utils.make_stat_result()
+ return obnamlib.obj.DirObject(id=obnamlib.obj.object_id_new(),
name=name,
stat=stat,
dirrefs=dirrefs,
@@ -298,7 +298,7 @@ class ApplicationUnchangedDirTests(unittest.TestCase):
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
def testSameDirWhenIrrelevantStatFieldsHaveChanged(self):
- stat = obnam.utils.make_stat_result(st_ino=42,
+ stat = obnamlib.utils.make_stat_result(st_ino=42,
st_atime=42,
st_blocks=42,
st_blksize=42,
@@ -311,55 +311,55 @@ class ApplicationUnchangedDirTests(unittest.TestCase):
def testChangedDirWhenDevHasChanged(self):
dir1 = self.make_dir("name1", [], [])
dir2 = self.make_dir("name2", [], [],
- stat=obnam.utils.make_stat_result(st_dev=105))
+ stat=obnamlib.utils.make_stat_result(st_dev=105))
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
def testChangedDirWhenModeHasChanged(self):
dir1 = self.make_dir("name1", [], [])
dir2 = self.make_dir("name2", [], [],
- stat=obnam.utils.make_stat_result(st_mode=105))
+ stat=obnamlib.utils.make_stat_result(st_mode=105))
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
def testChangedDirWhenNlinkHasChanged(self):
dir1 = self.make_dir("name1", [], [])
dir2 = self.make_dir("name2", [], [],
- stat=obnam.utils.make_stat_result(st_nlink=105))
+ stat=obnamlib.utils.make_stat_result(st_nlink=105))
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
def testChangedDirWhenUidHasChanged(self):
dir1 = self.make_dir("name1", [], [])
dir2 = self.make_dir("name2", [], [],
- stat=obnam.utils.make_stat_result(st_uid=105))
+ stat=obnamlib.utils.make_stat_result(st_uid=105))
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
def testChangedDirWhenGidHasChanged(self):
dir1 = self.make_dir("name1", [], [])
dir2 = self.make_dir("name2", [], [],
- stat=obnam.utils.make_stat_result(st_gid=105))
+ stat=obnamlib.utils.make_stat_result(st_gid=105))
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
def testChangedDirWhenSizeHasChanged(self):
dir1 = self.make_dir("name1", [], [])
dir2 = self.make_dir("name2", [], [],
- stat=obnam.utils.make_stat_result(st_size=105))
+ stat=obnamlib.utils.make_stat_result(st_size=105))
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
def testChangedDirWhenMtimeHasChanged(self):
dir1 = self.make_dir("name1", [], [])
dir2 = self.make_dir("name2", [], [],
- stat=obnam.utils.make_stat_result(st_mtime=105))
+ stat=obnamlib.utils.make_stat_result(st_mtime=105))
self.failIf(self.app.dir_is_unchanged(dir1, dir2))
class ApplicationFindUnchangedFilegroupsTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.dirname = "dirname"
self.stats = {
- "dirname/pink": obnam.utils.make_stat_result(st_mtime=42),
- "dirname/pretty": obnam.utils.make_stat_result(st_mtime=105),
+ "dirname/pink": obnamlib.utils.make_stat_result(st_mtime=42),
+ "dirname/pretty": obnamlib.utils.make_stat_result(st_mtime=105),
}
self.names = ["pink", "pretty"]
self.pink = self.mock_filegroup(["pink"])
@@ -367,7 +367,7 @@ class ApplicationFindUnchangedFilegroupsTests(unittest.TestCase):
self.groups = [self.pink, self.pretty]
def mock_filegroup(self, filenames):
- fg = obnam.obj.FileGroupObject(id=obnam.obj.object_id_new())
+ fg = obnamlib.obj.FileGroupObject(id=obnamlib.obj.object_id_new())
for filename in filenames:
st = self.mock_stat(os.path.join(self.dirname, filename))
fg.add_file(filename, st, None, None, None)
@@ -388,11 +388,11 @@ class ApplicationFindUnchangedFilegroupsTests(unittest.TestCase):
self.failUnlessEqual(self.find(self.groups, []), [])
def testReturnsPinkGroupWhenPrettyIsChanged(self):
- self.stats["dirname/pretty"] = obnam.utils.make_stat_result()
+ self.stats["dirname/pretty"] = obnamlib.utils.make_stat_result()
self.failUnlessEqual(self.find(self.groups, self.names), [self.pink])
def testReturnsPrettyGroupWhenPinkIsChanged(self):
- self.stats["dirname/pink"] = obnam.utils.make_stat_result()
+ self.stats["dirname/pink"] = obnamlib.utils.make_stat_result()
self.failUnlessEqual(self.find(self.groups, self.names), [self.pretty])
def testReturnsPinkAndPrettyWhenBothAreUnchanged(self):
@@ -400,8 +400,8 @@ class ApplicationFindUnchangedFilegroupsTests(unittest.TestCase):
set(self.groups))
def testReturnsEmptyListWhenEverythingIsChanged(self):
- self.stats["dirname/pink"] = obnam.utils.make_stat_result()
- self.stats["dirname/pretty"] = obnam.utils.make_stat_result()
+ self.stats["dirname/pink"] = obnamlib.utils.make_stat_result()
+ self.stats["dirname/pretty"] = obnamlib.utils.make_stat_result()
self.failUnlessEqual(self.find(self.groups, self.names), [])
@@ -411,15 +411,15 @@ class ApplicationGetDirInPreviousGenerationTests(unittest.TestCase):
def __init__(self):
self.dict = {
- "pink": obnam.obj.DirObject(id="id", name="pink"),
+ "pink": obnamlib.obj.DirObject(id="id", name="pink"),
}
def lookup_dir(self, gen, pathname):
return self.dict.get(pathname, None)
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.app._store = self.MockStore()
self.app.set_previous_generation("prevgen")
@@ -438,15 +438,15 @@ class ApplicationGetFileInPreviousGenerationTests(unittest.TestCase):
def __init__(self):
self.dict = {
- "pink": obnam.cmp.Component(obnam.cmp.FILE, [])
+ "pink": obnamlib.cmp.Component(obnamlib.cmp.FILE, [])
}
def lookup_file(self, gen, pathname):
return self.dict.get(pathname, None)
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.app._store = self.MockStore()
self.app.set_previous_generation("prevgen")
@@ -461,7 +461,7 @@ class ApplicationGetFileInPreviousGenerationTests(unittest.TestCase):
def testReturnsFileComponentIfFileDidExist(self):
cmp = self.app.get_file_in_previous_generation("pink")
- self.failUnlessEqual(cmp.get_kind(), obnam.cmp.FILE)
+ self.failUnlessEqual(cmp.get_kind(), obnamlib.cmp.FILE)
class ApplicationSelectFilesToBackUpTests(unittest.TestCase):
@@ -480,22 +480,22 @@ class ApplicationSelectFilesToBackUpTests(unittest.TestCase):
def setUp(self):
self.dirname = "dirname"
self.stats = {
- "dirname/pink": obnam.utils.make_stat_result(st_mtime=42),
- "dirname/pretty": obnam.utils.make_stat_result(st_mtime=105),
+ "dirname/pink": obnamlib.utils.make_stat_result(st_mtime=42),
+ "dirname/pretty": obnamlib.utils.make_stat_result(st_mtime=105),
}
self.names = ["pink", "pretty"]
self.pink = self.mock_filegroup(["pink"])
self.pretty = self.mock_filegroup(["pretty"])
self.groups = [self.pink, self.pretty]
- self.dir = obnam.obj.DirObject(id="id", name=self.dirname,
+ self.dir = obnamlib.obj.DirObject(id="id", name=self.dirname,
filegrouprefs=[x.get_id()
for x in self.groups])
store = self.MockStore(self.groups + [self.dir])
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.app._store = store
self.app.get_dir_in_previous_generation = self.mock_get_dir_in_prevgen
@@ -506,7 +506,7 @@ class ApplicationSelectFilesToBackUpTests(unittest.TestCase):
return None
def mock_filegroup(self, filenames):
- fg = obnam.obj.FileGroupObject(id=obnam.obj.object_id_new())
+ fg = obnamlib.obj.FileGroupObject(id=obnamlib.obj.object_id_new())
for filename in filenames:
st = self.mock_stat(os.path.join(self.dirname, filename))
fg.add_file(filename, st, None, None, None)
@@ -524,12 +524,12 @@ class ApplicationSelectFilesToBackUpTests(unittest.TestCase):
self.failUnlessEqual(self.select(), ([], self.names))
def testReturnsNoOldGroupsIfEverythingIsChanged(self):
- self.stats["dirname/pink"] = obnam.utils.make_stat_result()
- self.stats["dirname/pretty"] = obnam.utils.make_stat_result()
+ self.stats["dirname/pink"] = obnamlib.utils.make_stat_result()
+ self.stats["dirname/pretty"] = obnamlib.utils.make_stat_result()
self.failUnlessEqual(self.select(), ([], self.names))
def testReturnsOneGroupAndOneFileWhenJustOneIsChanged(self):
- self.stats["dirname/pink"] = obnam.utils.make_stat_result()
+ self.stats["dirname/pink"] = obnamlib.utils.make_stat_result()
self.failUnlessEqual(self.select(), ([self.pretty], ["pink"]))
def testReturnsBothGroupsWhenNothingIsChanged(self):
@@ -539,32 +539,32 @@ class ApplicationSelectFilesToBackUpTests(unittest.TestCase):
class ApplicationFindFileByNameTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
def testFindsFileInfoInFilelistFromPreviousGeneration(self):
- stat = obnam.utils.make_stat_result()
- fc = obnam.filelist.create_file_component_from_stat("pink", stat,
+ stat = obnamlib.utils.make_stat_result()
+ fc = obnamlib.filelist.create_file_component_from_stat("pink", stat,
"contref",
"sigref",
"deltaref")
- filelist = obnam.filelist.Filelist()
+ filelist = obnamlib.filelist.Filelist()
filelist.add_file_component("pink", fc)
self.app.set_prevgen_filelist(filelist)
file = self.app.find_file_by_name("pink")
self.failUnlessEqual(
- obnam.cmp.parse_stat_component(
- file.first_by_kind(obnam.cmp.STAT)),
+ obnamlib.cmp.parse_stat_component(
+ file.first_by_kind(obnamlib.cmp.STAT)),
stat)
- self.failUnlessEqual(file.first_string_by_kind(obnam.cmp.CONTREF),
+ self.failUnlessEqual(file.first_string_by_kind(obnamlib.cmp.CONTREF),
"contref")
- self.failUnlessEqual(file.first_string_by_kind(obnam.cmp.SIGREF),
+ self.failUnlessEqual(file.first_string_by_kind(obnamlib.cmp.SIGREF),
"sigref")
- self.failUnlessEqual(file.first_string_by_kind(obnam.cmp.DELTAREF),
+ self.failUnlessEqual(file.first_string_by_kind(obnamlib.cmp.DELTAREF),
"deltaref")
def testFindsNoFileInfoInFilelistForNonexistingFile(self):
- filelist = obnam.filelist.Filelist()
+ filelist = obnamlib.filelist.Filelist()
self.app.set_prevgen_filelist(filelist)
self.failUnlessEqual(self.app.find_file_by_name("pink"), None)
@@ -578,12 +578,12 @@ class ApplicationBackupsOneDirectoryTests(unittest.TestCase):
file(self.abs(name), "w").close()
def make_dirobject(self, relative_name):
- return obnam.obj.DirObject(id=obnam.obj.object_id_new(),
+ return obnamlib.obj.DirObject(id=obnamlib.obj.object_id_new(),
name=self.abs(relative_name))
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.dirname = tempfile.mkdtemp()
def tearDown(self):
@@ -606,7 +606,7 @@ class ApplicationBackupsOneDirectoryTests(unittest.TestCase):
self.failUnlessEqual(dir.get_filegrouprefs(), [])
def _filegroups(self, file_count):
- max = obnam.app.MAX_PER_FILEGROUP
+ max = obnamlib.app.MAX_PER_FILEGROUP
return (file_count + max - 1) / max
def testWithCorrectNumberOfFilegrouprefsWhenSomeAreGiven(self):
@@ -666,8 +666,8 @@ class ApplicationBackupOneRootTests(unittest.TestCase):
return dict
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.real_backup_one_dir = self.app.backup_one_dir
self.app.backup_one_dir = self.mock_backup_one_dir
self.dirs_walked = []
@@ -681,13 +681,13 @@ class ApplicationBackupOneRootTests(unittest.TestCase):
shutil.rmtree(self.dirname)
def testRaisesErrorForNonDirectory(self):
- self.failUnlessRaises(obnam.ObnamException,
+ self.failUnlessRaises(obnamlib.ObnamException,
self.app.backup_one_root,
self.abs("file0"))
def testReturnsDirObject(self):
ret = self.app.backup_one_root(self.dirname)
- self.failUnless(isinstance(ret, obnam.obj.DirObject))
+ self.failUnless(isinstance(ret, obnamlib.obj.DirObject))
def testWalksToTheRightDirectories(self):
self.app.backup_one_root(self.dirname)
@@ -730,8 +730,8 @@ class ApplicationBackupTests(unittest.TestCase):
self.dirname = tempfile.mkdtemp()
self.mktree(self._tree)
self.roots_backed_up = []
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.real_backup_one_root = self.app.backup_one_root
self.app.backup_one_root = self.mock_backup_one_root
@@ -742,7 +742,7 @@ class ApplicationBackupTests(unittest.TestCase):
def testReturnsGenerationObject(self):
ret = self.app.backup([self.abs("pink"), self.abs("pretty")])
- self.failUnless(isinstance(ret, obnam.obj.GenerationObject))
+ self.failUnless(isinstance(ret, obnamlib.obj.GenerationObject))
def testReturnsGenerationWithTheRightRootObjects(self):
gen = self.app.backup([self.abs("pink"), self.abs("pretty")])
diff --git a/obnam/backend.py b/obnamlib/backend.py
index 73c812ad..e380cbf9 100644
--- a/obnam/backend.py
+++ b/obnamlib/backend.py
@@ -27,10 +27,7 @@ import urlparse
import paramiko
import uuid
-import obnam.cache
-import obnam.cmp
-import obnam.map
-import obnam.obj
+import obnamlib
# Block filenames are created using the following scheme:
@@ -169,7 +166,7 @@ class Backend:
logging.debug("Uploading block %s" % block_id)
if self.use_gpg():
logging.debug("Encrypting block %s before upload" % block_id)
- block = obnam.gpg.encrypt(self.config, block)
+ block = obnamlib.gpg.encrypt(self.config, block)
logging.debug("Uploading block %s (%d bytes)" % (block_id, len(block)))
self.progress.update_current_action("Uploading block")
self.really_upload_block(block_id, block)
@@ -191,7 +188,7 @@ class Backend:
if self.use_gpg():
logging.debug("Decrypting downloaded block %s before using it" %
block_id)
- block = obnam.gpg.decrypt(self.config, block)
+ block = obnamlib.gpg.decrypt(self.config, block)
return block
diff --git a/obnam/backendTests.py b/obnamlib/backendTests.py
index 632615b5..8277eeef 100644
--- a/obnam/backendTests.py
+++ b/obnamlib/backendTests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.backend"""
+"""Unit tests for obnamlib.backend"""
import os
@@ -25,7 +25,7 @@ import stat
import tempfile
import unittest
-import obnam
+import obnamlib
class GetDefaultUserTest(unittest.TestCase):
@@ -41,16 +41,16 @@ class GetDefaultUserTest(unittest.TestCase):
def testLogname(self):
os.environ["LOGNAME"] = "pink"
- self.failUnlessEqual(obnam.backend.get_default_user(), "pink")
+ self.failUnlessEqual(obnamlib.backend.get_default_user(), "pink")
def testLognameWhenItIsPink(self):
# Just in case the user's name is "pink"...
os.environ["LOGNAME"] = "pretty"
- self.failUnlessEqual(obnam.backend.get_default_user(), "pretty")
+ self.failUnlessEqual(obnamlib.backend.get_default_user(), "pretty")
def testNoLogname(self):
del os.environ["LOGNAME"]
- user = obnam.backend.get_default_user()
+ user = obnamlib.backend.get_default_user()
uid = pwd.getpwnam(user)[2]
self.failUnlessEqual(uid, os.getuid())
@@ -71,7 +71,7 @@ class ParseStoreUrlTests(unittest.TestCase):
("sftp://host/~/foo", None, "host", None, "foo"),
)
for case in cases:
- user, host, port, path = obnam.backend.parse_store_url(case[0])
+ user, host, port, path = obnamlib.backend.parse_store_url(case[0])
self.failUnlessEqual(user, case[1])
self.failUnlessEqual(host, case[2])
self.failUnlessEqual(port, case[3])
@@ -81,10 +81,10 @@ class ParseStoreUrlTests(unittest.TestCase):
class UseGpgTests(unittest.TestCase):
def setUp(self):
- self.config = obnam.config.default_config()
+ self.config = obnamlib.config.default_config()
self.config.set("backup", "gpg-encrypt-to", "")
- self.cache = obnam.cache.Cache(self.config)
- self.be = obnam.backend.Backend(self.config, self.cache)
+ self.cache = obnamlib.cache.Cache(self.config)
+ self.be = obnamlib.backend.Backend(self.config, self.cache)
def testDoNotUseByDefault(self):
self.failIf(self.be.use_gpg())
@@ -102,13 +102,13 @@ class UseGpgTests(unittest.TestCase):
class DircountTests(unittest.TestCase):
def setUp(self):
- self.config = obnam.config.default_config()
- self.cache = obnam.cache.Cache(self.config)
- self.be = obnam.backend.Backend(self.config, self.cache)
+ self.config = obnamlib.config.default_config()
+ self.cache = obnamlib.cache.Cache(self.config)
+ self.be = obnamlib.backend.Backend(self.config, self.cache)
def testInit(self):
- self.failUnlessEqual(len(self.be.dircounts), obnam.backend.LEVELS)
- for i in range(obnam.backend.LEVELS):
+ self.failUnlessEqual(len(self.be.dircounts), obnamlib.backend.LEVELS)
+ for i in range(obnamlib.backend.LEVELS):
self.failUnlessEqual(self.be.dircounts[i], 0)
def testIncrementOnce(self):
@@ -116,10 +116,10 @@ class DircountTests(unittest.TestCase):
self.failUnlessEqual(self.be.dircounts, [0, 0, 1])
def testIncrementMany(self):
- for i in range(obnam.backend.MAX_BLOCKS_PER_DIR):
+ for i in range(obnamlib.backend.MAX_BLOCKS_PER_DIR):
self.be.increment_dircounts()
self.failUnlessEqual(self.be.dircounts,
- [0, 0, obnam.backend.MAX_BLOCKS_PER_DIR])
+ [0, 0, obnamlib.backend.MAX_BLOCKS_PER_DIR])
self.be.increment_dircounts()
self.failUnlessEqual(self.be.dircounts, [0, 1, 0])
@@ -129,7 +129,7 @@ class DircountTests(unittest.TestCase):
def testIncrementTop(self):
self.be.dircounts = [0] + \
- [obnam.backend.MAX_BLOCKS_PER_DIR] * (obnam.backend.LEVELS -1)
+ [obnamlib.backend.MAX_BLOCKS_PER_DIR] * (obnamlib.backend.LEVELS -1)
self.be.increment_dircounts()
self.failUnlessEqual(self.be.dircounts, [1, 0, 0])
@@ -148,11 +148,11 @@ class LocalBackendBase(unittest.TestCase):
("backup", "store", self.rootdir)
)
- self.config = obnam.config.default_config()
+ self.config = obnamlib.config.default_config()
for section, item, value in config_list:
self.config.set(section, item, value)
- self.cache = obnam.cache.Cache(self.config)
+ self.cache = obnamlib.cache.Cache(self.config)
def tearDown(self):
shutil.rmtree(self.cachedir)
@@ -165,14 +165,14 @@ class LocalBackendBase(unittest.TestCase):
class InitTests(LocalBackendBase):
def testInit(self):
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
self.failUnlessEqual(be.url, self.rootdir)
class IdTests(LocalBackendBase):
def testGenerateBlockId(self):
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
self.failIfEqual(be.blockdir, None)
id = be.generate_block_id()
self.failUnless(id.startswith(be.blockdir))
@@ -186,7 +186,7 @@ class UploadTests(LocalBackendBase):
self.config.set("backup", "gpg-home", "")
self.config.set("backup", "gpg-encrypt-to", "")
self.config.set("backup", "gpg-sign-with", "")
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
id = be.generate_block_id()
block = "pink is pretty"
ret = be.upload_block(id, block, False)
@@ -214,7 +214,7 @@ class UploadTests(LocalBackendBase):
self.config.set("backup", "gpg-sign-with", "")
self.config.set("backup", "cache", cachedir)
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
id = be.generate_block_id()
block = "pink is pretty"
ret = be.upload_block(id, block, True)
@@ -228,7 +228,7 @@ class DownloadTests(LocalBackendBase):
self.config.set("backup", "gpg-encrypt-to", "")
self.config.set("backup", "gpg-sign-with", "")
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
id = be.generate_block_id()
block = "pink is still pretty"
be.upload_block(id, block, False)
@@ -239,7 +239,7 @@ class DownloadTests(LocalBackendBase):
self.failUnlessEqual(be.get_bytes_written(), len(block))
def testError(self):
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
id = be.generate_block_id()
self.failUnlessRaises(IOError, be.download_block, id)
@@ -251,7 +251,7 @@ class FileListTests(LocalBackendBase):
self.config.set("backup", "gpg-encrypt-to", "")
self.config.set("backup", "gpg-sign-with", "")
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
self.failUnlessEqual(be.list(), [])
id = "pink"
@@ -270,7 +270,7 @@ class FileListTests(LocalBackendBase):
class RemoveTests(LocalBackendBase):
def test(self):
- be = obnam.backend.init(self.config, self.cache)
+ be = obnamlib.backend.init(self.config, self.cache)
id = be.generate_block_id()
block = "pink is still pretty"
be.upload_block(id, block, False)
diff --git a/obnam/cache.py b/obnamlib/cache.py
index f7b86f1c..f7b86f1c 100644
--- a/obnam/cache.py
+++ b/obnamlib/cache.py
diff --git a/obnam/cacheTests.py b/obnamlib/cacheTests.py
index fd42ead1..963dc92b 100644
--- a/obnam/cacheTests.py
+++ b/obnamlib/cacheTests.py
@@ -15,14 +15,14 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.cache"""
+"""Unit tests for obnamlib.cache"""
import os
import shutil
import unittest
-import obnam
+import obnamlib
class CacheBase(unittest.TestCase):
@@ -34,7 +34,7 @@ class CacheBase(unittest.TestCase):
("backup", "cache", self.cachedir),
)
- self.config = obnam.cfgfile.ConfigFile()
+ self.config = obnamlib.cfgfile.ConfigFile()
for section, item, value in config_list:
if not self.config.has_section(section):
self.config.add_section(section)
@@ -50,14 +50,14 @@ class CacheBase(unittest.TestCase):
class InitTests(CacheBase):
def testInit(self):
- cache = obnam.cache.Cache(self.config)
+ cache = obnamlib.cache.Cache(self.config)
self.failIf(os.path.isdir(self.cachedir))
class PutTests(CacheBase):
def testPut(self):
- cache = obnam.cache.Cache(self.config)
+ cache = obnamlib.cache.Cache(self.config)
id = "pink"
block = "pretty"
cache.put_block(id, block)
@@ -72,7 +72,7 @@ class PutTests(CacheBase):
class GetTests(CacheBase):
def testGet(self):
- cache = obnam.cache.Cache(self.config)
+ cache = obnamlib.cache.Cache(self.config)
id = "pink"
block = "pretty"
self.failUnlessEqual(cache.get_block(id), None)
diff --git a/obnam/cfgfile.py b/obnamlib/cfgfile.py
index 52994388..e2e5fea6 100644
--- a/obnam/cfgfile.py
+++ b/obnamlib/cfgfile.py
@@ -44,10 +44,10 @@ of ConfigParser. It should otherwise be compatible.
import re
-import obnam
+import obnamlib
-class Error(obnam.ObnamException):
+class Error(obnamlib.ObnamException):
pass
diff --git a/obnam/cfgfileTests.py b/obnamlib/cfgfileTests.py
index af572943..704fb619 100644
--- a/obnam/cfgfileTests.py
+++ b/obnamlib/cfgfileTests.py
@@ -15,34 +15,34 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.cfgfile."""
+"""Unit tests for obnamlib.cfgfile."""
import StringIO
import unittest
-import obnam
+import obnamlib
class ParsingErrorTests(unittest.TestCase):
def testSaysUnnamedFileIfNameIsNone(self):
- e = obnam.cfgfile.ParsingError(None, 42)
+ e = obnamlib.cfgfile.ParsingError(None, 42)
self.failUnless("unnamed file" in str(e))
def testIncludesFilenameInMessage(self):
- e = obnam.cfgfile.ParsingError("pink", 42)
+ e = obnamlib.cfgfile.ParsingError("pink", 42)
self.failUnless("pink" in str(e))
def testIncludesLineNumberInMessage(self):
- e = obnam.cfgfile.ParsingError("pink", 42)
+ e = obnamlib.cfgfile.ParsingError("pink", 42)
self.failUnless("42" in str(e))
class SectionTests(unittest.TestCase):
def setUp(self):
- self.cf = obnam.cfgfile.ConfigFile()
+ self.cf = obnamlib.cfgfile.ConfigFile()
def tearDown(self):
self.cf = None
@@ -56,7 +56,7 @@ class SectionTests(unittest.TestCase):
def testAddSectionExisting(self):
self.cf.add_section("foo")
- self.failUnlessRaises(obnam.cfgfile.DuplicationError,
+ self.failUnlessRaises(obnamlib.cfgfile.DuplicationError,
self.cf.add_section,
"foo")
@@ -91,13 +91,13 @@ class SectionTests(unittest.TestCase):
class OptionsTests(unittest.TestCase):
def setUp(self):
- self.cf = obnam.cfgfile.ConfigFile()
+ self.cf = obnamlib.cfgfile.ConfigFile()
def tearDown(self):
self.cf = None
def testOptionsNonExistentSection(self):
- self.failUnlessRaises(obnam.cfgfile.NoSectionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoSectionError,
self.cf.options,
"foo")
@@ -113,7 +113,7 @@ class OptionsTests(unittest.TestCase):
self.failUnlessEqual(self.cf.options("foo"), sorted(options))
def testHasOptionNonExistingSection(self):
- self.failUnlessRaises(obnam.cfgfile.NoSectionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoSectionError,
self.cf.has_option,
"foo", "bar")
@@ -127,18 +127,18 @@ class OptionsTests(unittest.TestCase):
self.failUnless(self.cf.has_option("foo", "bar"))
def testGetNonExistingSection(self):
- self.failUnlessRaises(obnam.cfgfile.NoSectionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoSectionError,
self.cf.get,
"foo", "bar")
def testGetNonExistingOption(self):
self.cf.add_section("foo")
- self.failUnlessRaises(obnam.cfgfile.NoOptionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoOptionError,
self.cf.get,
"foo", "bar")
def testSetNonExistingSection(self):
- self.failUnlessRaises(obnam.cfgfile.NoSectionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoSectionError,
self.cf.set,
"foo", "bar", "foobar")
@@ -165,7 +165,7 @@ class OptionsTests(unittest.TestCase):
self.failUnlessEqual(self.cf.getvalues("foo", "bar"), [])
def testAppendNonExistingSection(self):
- self.failUnlessRaises(obnam.cfgfile.NoSectionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoSectionError,
self.cf.append,
"foo", "bar", "foobar")
@@ -241,7 +241,7 @@ class OptionsTests(unittest.TestCase):
self.failUnlessEqual(self.cf.getboolean("foo", "bar"), False)
def testItemsNonExistentSection(self):
- self.failUnlessRaises(obnam.cfgfile.NoSectionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoSectionError,
self.cf.items,
"foo")
@@ -262,7 +262,7 @@ class OptionsTests(unittest.TestCase):
("3", ["3", "3"])])
def testRemoveOptionNonExistentSection(self):
- self.failUnlessRaises(obnam.cfgfile.NoSectionError,
+ self.failUnlessRaises(obnamlib.cfgfile.NoSectionError,
self.cf.remove_option,
"foo", "bar")
@@ -280,7 +280,7 @@ class OptionsTests(unittest.TestCase):
class WriteTests(unittest.TestCase):
def testSingleValue(self):
- cf = obnam.cfgfile.ConfigFile()
+ cf = obnamlib.cfgfile.ConfigFile()
cf.add_section("foo")
cf.set("foo", "bar", "foobar")
f = StringIO.StringIO()
@@ -291,7 +291,7 @@ bar = foobar
""")
def testMultiValue(self):
- cf = obnam.cfgfile.ConfigFile()
+ cf = obnamlib.cfgfile.ConfigFile()
cf.add_section("foo")
cf.append("foo", "bar", "foobar")
cf.append("foo", "bar", "baz")
@@ -307,7 +307,7 @@ bar += baz
class ReadTests(unittest.TestCase):
def parse(self, file_contents):
- cf = obnam.cfgfile.ConfigFile()
+ cf = obnamlib.cfgfile.ConfigFile()
f = StringIO.StringIO(file_contents)
cf.readfp(f)
return cf
@@ -325,7 +325,7 @@ class ReadTests(unittest.TestCase):
self.failUnlessEqual(cf.sections(), ["bar", "foo"])
def testParsingError(self):
- self.failUnlessRaises(obnam.cfgfile.ParsingError,
+ self.failUnlessRaises(obnamlib.cfgfile.ParsingError,
self.parse, "xxxx")
def testComment(self):
@@ -357,7 +357,7 @@ store = pink
[backup]
cache = pretty
""")
- cf = obnam.cfgfile.ConfigFile()
+ cf = obnamlib.cfgfile.ConfigFile()
cf.readfp(f1)
cf.readfp(f2)
self.failUnlessEqual(cf.get("backup", "store"), "pink")
@@ -367,14 +367,14 @@ cache = pretty
class ReadWriteTest(unittest.TestCase):
def test(self):
- cf = obnam.cfgfile.ConfigFile()
+ cf = obnamlib.cfgfile.ConfigFile()
cf.add_section("foo")
cf.append("foo", "bar", "foobar")
cf.append("foo", "bar", "baz")
f = StringIO.StringIO()
cf.write(f)
f.seek(0, 0)
- cf2 = obnam.cfgfile.ConfigFile()
+ cf2 = obnamlib.cfgfile.ConfigFile()
cf2.readfp(f)
self.failUnlessEqual(cf2.sections(), ["foo"])
self.failUnlessEqual(cf2.items("foo"), [("bar", ["foobar", "baz"])])
diff --git a/obnam/cmp.py b/obnamlib/cmp.py
index d83092eb..f06f16fa 100644
--- a/obnam/cmp.py
+++ b/obnamlib/cmp.py
@@ -18,7 +18,7 @@
"""Obnam data components"""
-import obnam
+import obnamlib
# Constants for component kinds
@@ -134,7 +134,7 @@ class Component:
def get_varint_value(self):
"""Return integer value of leaf component"""
assert self.str is not None
- return obnam.varint.decode(self.str, 0)[0]
+ return obnamlib.varint.decode(self.str, 0)[0]
def get_subcomponents(self):
"""Return list of subcomponents of composite component"""
@@ -186,8 +186,8 @@ class Component:
encoded = "".join(snippets)
else:
encoded = self.str
- return "%s%s%s" % (obnam.varint.encode(len(encoded)),
- obnam.varint.encode(self.kind),
+ return "%s%s%s" % (obnamlib.varint.encode(len(encoded)),
+ obnamlib.varint.encode(self.kind),
encoded)
@@ -206,8 +206,8 @@ class Parser:
if self.pos >= self.end:
return None
- size, self.pos = obnam.varint.decode(self.encoded, self.pos)
- kind, self.pos = obnam.varint.decode(self.encoded, self.pos)
+ size, self.pos = obnamlib.varint.decode(self.encoded, self.pos)
+ kind, self.pos = obnamlib.varint.decode(self.encoded, self.pos)
if kind_is_composite(kind):
parser = Parser(self.encoded, self.pos, self.pos + size)
@@ -269,40 +269,40 @@ def first_varint_by_kind(components, wanted_kind):
def create_stat_component(st):
"""Create a STAT component, given a stat result"""
- return Component(obnam.cmp.STAT,
- obnam.varint.encode(st.st_mode) +
- obnam.varint.encode(st.st_ino) +
- obnam.varint.encode(st.st_dev) +
- obnam.varint.encode(st.st_nlink) +
- obnam.varint.encode(st.st_uid) +
- obnam.varint.encode(st.st_gid) +
- obnam.varint.encode(st.st_size) +
- obnam.varint.encode(st.st_atime) +
- obnam.varint.encode(st.st_mtime) +
- obnam.varint.encode(st.st_ctime) +
- obnam.varint.encode(st.st_blocks) +
- obnam.varint.encode(st.st_blksize) +
- obnam.varint.encode(st.st_rdev))
+ return Component(obnamlib.cmp.STAT,
+ obnamlib.varint.encode(st.st_mode) +
+ obnamlib.varint.encode(st.st_ino) +
+ obnamlib.varint.encode(st.st_dev) +
+ obnamlib.varint.encode(st.st_nlink) +
+ obnamlib.varint.encode(st.st_uid) +
+ obnamlib.varint.encode(st.st_gid) +
+ obnamlib.varint.encode(st.st_size) +
+ obnamlib.varint.encode(st.st_atime) +
+ obnamlib.varint.encode(st.st_mtime) +
+ obnamlib.varint.encode(st.st_ctime) +
+ obnamlib.varint.encode(st.st_blocks) +
+ obnamlib.varint.encode(st.st_blksize) +
+ obnamlib.varint.encode(st.st_rdev))
def parse_stat_component(stat_component):
"""Return an object like a stat result from a decoded stat_component"""
value = stat_component.get_string_value()
pos = 0
- st_mode, pos = obnam.varint.decode(value, pos)
- st_ino, pos = obnam.varint.decode(value, pos)
- st_dev, pos = obnam.varint.decode(value, pos)
- st_nlink, pos = obnam.varint.decode(value, pos)
- st_uid, pos = obnam.varint.decode(value, pos)
- st_gid, pos = obnam.varint.decode(value, pos)
- st_size, pos = obnam.varint.decode(value, pos)
- st_atime, pos = obnam.varint.decode(value, pos)
- st_mtime, pos = obnam.varint.decode(value, pos)
- st_ctime, pos = obnam.varint.decode(value, pos)
- st_blocks, pos = obnam.varint.decode(value, pos)
- st_blksize, pos = obnam.varint.decode(value, pos)
- st_rdev, pos = obnam.varint.decode(value, pos)
- return obnam.utils.make_stat_result(st_mode=st_mode,
+ st_mode, pos = obnamlib.varint.decode(value, pos)
+ st_ino, pos = obnamlib.varint.decode(value, pos)
+ st_dev, pos = obnamlib.varint.decode(value, pos)
+ st_nlink, pos = obnamlib.varint.decode(value, pos)
+ st_uid, pos = obnamlib.varint.decode(value, pos)
+ st_gid, pos = obnamlib.varint.decode(value, pos)
+ st_size, pos = obnamlib.varint.decode(value, pos)
+ st_atime, pos = obnamlib.varint.decode(value, pos)
+ st_mtime, pos = obnamlib.varint.decode(value, pos)
+ st_ctime, pos = obnamlib.varint.decode(value, pos)
+ st_blocks, pos = obnamlib.varint.decode(value, pos)
+ st_blksize, pos = obnamlib.varint.decode(value, pos)
+ st_rdev, pos = obnamlib.varint.decode(value, pos)
+ return obnamlib.utils.make_stat_result(st_mode=st_mode,
st_ino=st_ino,
st_dev=st_dev,
st_nlink=st_nlink,
diff --git a/obnam/cmpTests.py b/obnamlib/cmpTests.py
index 245b1349..bc427969 100644
--- a/obnam/cmpTests.py
+++ b/obnamlib/cmpTests.py
@@ -15,21 +15,21 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.cmp."""
+"""Unit tests for obnamlib.cmp."""
import os
import unittest
-import obnam
+import obnamlib
class ComponentKindNameTests(unittest.TestCase):
def test(self):
- t = obnam.cmp.kind_name
- c = obnam.cmp
+ t = obnamlib.cmp.kind_name
+ c = obnamlib.cmp
self.failUnlessEqual(t(-12765), "UNKNOWN")
names = (
@@ -70,25 +70,25 @@ class ComponentKindNameTests(unittest.TestCase):
class RefComponentTests(unittest.TestCase):
def test(self):
- kinds = obnam.cmp._component_kinds
+ kinds = obnamlib.cmp._component_kinds
for kind in kinds:
self.failUnlessEqual(kinds[kind][1].endswith("REF"),
- obnam.cmp.kind_is_reference(kind))
+ obnamlib.cmp.kind_is_reference(kind))
class CreateComponentTests(unittest.TestCase):
def testCreateLeaf(self):
- c = obnam.cmp.Component(1, "pink")
+ c = obnamlib.cmp.Component(1, "pink")
self.failIfEqual(c, None)
self.failUnlessEqual(c.get_kind(), 1)
self.failUnlessEqual(c.get_string_value(), "pink")
self.failUnlessEqual(c.is_composite(), False)
def testCreateComposite(self):
- leaf1 = obnam.cmp.Component(1, "pink")
- leaf2 = obnam.cmp.Component(2, "pretty")
- c = obnam.cmp.Component(3, [leaf1, leaf2])
+ leaf1 = obnamlib.cmp.Component(1, "pink")
+ leaf2 = obnamlib.cmp.Component(2, "pretty")
+ c = obnamlib.cmp.Component(3, [leaf1, leaf2])
self.failUnlessEqual(c.get_kind(), 3)
self.failUnlessEqual(c.is_composite(), True)
self.failUnlessEqual(c.get_subcomponents(), [leaf1, leaf2])
@@ -97,37 +97,37 @@ class CreateComponentTests(unittest.TestCase):
class ComponentParserTest(unittest.TestCase):
def testDecodeEmptyString(self):
- parser = obnam.cmp.Parser("")
+ parser = obnamlib.cmp.Parser("")
self.failUnlessEqual(parser.decode(), None)
def testDecodePlainComponent(self):
- c = obnam.cmp.Component(obnam.cmp.OBJID, "pink")
+ c = obnamlib.cmp.Component(obnamlib.cmp.OBJID, "pink")
encoded = c.encode()
- parser = obnam.cmp.Parser(encoded)
+ parser = obnamlib.cmp.Parser(encoded)
c2 = parser.decode()
self.failUnlessEqual(parser.pos, len(encoded))
self.failUnlessEqual(encoded, c2.encode())
def testDecodeCompositeComponent(self):
- subs = [obnam.cmp.Component(obnam.cmp.OBJID, str(i))
+ subs = [obnamlib.cmp.Component(obnamlib.cmp.OBJID, str(i))
for i in range(100)]
- c = obnam.cmp.Component(obnam.cmp.OBJECT, subs)
+ c = obnamlib.cmp.Component(obnamlib.cmp.OBJECT, subs)
encoded = c.encode()
- parser = obnam.cmp.Parser(encoded)
+ parser = obnamlib.cmp.Parser(encoded)
c2 = parser.decode()
self.failUnlessEqual(parser.pos, len(encoded))
self.failUnlessEqual(encoded, c2.encode())
def testDecodeAllEmptyString(self):
- parser = obnam.cmp.Parser("")
+ parser = obnamlib.cmp.Parser("")
self.failUnlessEqual(parser.decode_all(), [])
def testDecodeAllPlainComponents(self):
- list = [obnam.cmp.Component(obnam.cmp.OBJID, str(i))
+ list = [obnamlib.cmp.Component(obnamlib.cmp.OBJID, str(i))
for i in range(100)]
encoded = "".join(c.encode() for c in list)
- parser = obnam.cmp.Parser(encoded)
+ parser = obnamlib.cmp.Parser(encoded)
list2 = parser.decode_all()
self.failUnlessEqual(parser.pos, len(encoded))
@@ -143,12 +143,12 @@ class ComponentDecodeAllTests(unittest.TestCase):
del list[0]
def testDecodeAll(self):
- c1 = obnam.cmp.Component(1, "pink")
- c2 = obnam.cmp.Component(2, "pretty")
+ c1 = obnamlib.cmp.Component(1, "pink")
+ c2 = obnamlib.cmp.Component(2, "pretty")
e1 = c1.encode()
e2 = c2.encode()
e = e1 + e2
- list = obnam.cmp.Parser(e).decode_all()
+ list = obnamlib.cmp.Parser(e).decode_all()
self.remove_component(list, 1, "pink")
self.remove_component(list, 2, "pretty")
self.failUnlessEqual(list, [])
@@ -158,9 +158,9 @@ class ComponentFindTests(unittest.TestCase):
def setUp(self):
list = [(1, "pink"), (2, "pretty"), (3, "black"), (3, "box")]
- list += [(4, obnam.varint.encode(4))]
- list = [obnam.cmp.Component(a, b) for a, b in list]
- self.c = obnam.cmp.Component(42, list)
+ list += [(4, obnamlib.varint.encode(4))]
+ list = [obnamlib.cmp.Component(a, b) for a, b in list]
+ self.c = obnamlib.cmp.Component(42, list)
def match(self, result, kind, value):
self.failUnless(len(result) > 0)
@@ -253,7 +253,7 @@ class FindTests(unittest.TestCase):
def setUp(self):
self.list = [(1, "pink"), (2, "pretty"), (3, "black"), (3, "box")]
- self.list = [obnam.cmp.Component(a, b) for a, b in self.list]
+ self.list = [obnamlib.cmp.Component(a, b) for a, b in self.list]
def tearDown(self):
del self.list
@@ -266,81 +266,81 @@ class FindTests(unittest.TestCase):
del result[0]
def testFindAllOnes(self):
- result = obnam.cmp.find_by_kind(self.list, 1)
+ result = obnamlib.cmp.find_by_kind(self.list, 1)
self.match(result, 1, "pink")
self.failUnlessEqual(result, [])
def testFindAllTwos(self):
- result = obnam.cmp.find_by_kind(self.list, 2)
+ result = obnamlib.cmp.find_by_kind(self.list, 2)
self.match(result, 2, "pretty")
self.failUnlessEqual(result, [])
def testFindAllThrees(self):
- result = obnam.cmp.find_by_kind(self.list, 3)
+ result = obnamlib.cmp.find_by_kind(self.list, 3)
self.match(result, 3, "black")
self.match(result, 3, "box")
self.failUnlessEqual(result, [])
def testFindAllNones(self):
- result = obnam.cmp.find_by_kind(self.list, 0)
+ result = obnamlib.cmp.find_by_kind(self.list, 0)
self.failUnlessEqual(result, [])
def testFindFirstOne(self):
- result = [obnam.cmp.first_by_kind(self.list, 1)]
+ result = [obnamlib.cmp.first_by_kind(self.list, 1)]
self.match(result, 1, "pink")
self.failUnlessEqual(result, [])
def testFindFirstTwo(self):
- result = [obnam.cmp.first_by_kind(self.list, 2)]
+ result = [obnamlib.cmp.first_by_kind(self.list, 2)]
self.match(result, 2, "pretty")
self.failUnlessEqual(result, [])
def testFindFirstThree(self):
- result = [obnam.cmp.first_by_kind(self.list, 3)]
+ result = [obnamlib.cmp.first_by_kind(self.list, 3)]
self.match(result, 3, "black")
self.failUnlessEqual(result, [])
def testFindFirstNone(self):
- result = obnam.cmp.first_by_kind(self.list, 0)
+ result = obnamlib.cmp.first_by_kind(self.list, 0)
self.failUnlessEqual(result, None)
def testFindAllStringOnes(self):
- result = obnam.cmp.find_strings_by_kind(self.list, 1)
+ result = obnamlib.cmp.find_strings_by_kind(self.list, 1)
self.failUnlessEqual(result, ["pink"])
def testFindAllStringTwos(self):
- result = obnam.cmp.find_strings_by_kind(self.list, 2)
+ result = obnamlib.cmp.find_strings_by_kind(self.list, 2)
self.failUnlessEqual(result, ["pretty"])
def testFindAllStringThrees(self):
- result = obnam.cmp.find_strings_by_kind(self.list, 3)
+ result = obnamlib.cmp.find_strings_by_kind(self.list, 3)
self.failUnlessEqual(result, ["black", "box"])
def testFindAllStringNones(self):
- result = obnam.cmp.find_strings_by_kind(self.list, 0)
+ result = obnamlib.cmp.find_strings_by_kind(self.list, 0)
self.failUnlessEqual(result, [])
def testFindFirstStringOne(self):
- result = obnam.cmp.first_string_by_kind(self.list, 1)
+ result = obnamlib.cmp.first_string_by_kind(self.list, 1)
self.failUnlessEqual(result, "pink")
def testFindFirstStringTwo(self):
- result = obnam.cmp.first_string_by_kind(self.list, 2)
+ result = obnamlib.cmp.first_string_by_kind(self.list, 2)
self.failUnlessEqual(result, "pretty")
def testFindFirstStringThree(self):
- result = obnam.cmp.first_string_by_kind(self.list, 3)
+ result = obnamlib.cmp.first_string_by_kind(self.list, 3)
self.failUnlessEqual(result, "black")
def testFindFirstStringNone(self):
- result = obnam.cmp.first_string_by_kind(self.list, 0)
+ result = obnamlib.cmp.first_string_by_kind(self.list, 0)
self.failUnlessEqual(result, None)
class GetVarintVAlueTest(unittest.TestCase):
def test(self):
- c = obnam.cmp.Component(1, obnam.varint.encode(12765))
+ c = obnamlib.cmp.Component(1, obnamlib.varint.encode(12765))
self.failUnlessEqual(c.get_varint_value(), 12765)
@@ -351,21 +351,21 @@ class FindVarintTests(unittest.TestCase):
list = []
for i in values:
- encoded = obnam.varint.encode(i)
- c = obnam.cmp.Component(i, encoded)
+ encoded = obnamlib.varint.encode(i)
+ c = obnamlib.cmp.Component(i, encoded)
list.append(c)
for i in values:
- self.failUnlessEqual(obnam.cmp.first_varint_by_kind(list, i), i)
- self.failUnlessEqual(obnam.cmp.first_varint_by_kind(list, -1), None)
+ self.failUnlessEqual(obnamlib.cmp.first_varint_by_kind(list, i), i)
+ self.failUnlessEqual(obnamlib.cmp.first_varint_by_kind(list, -1), None)
class StatTests(unittest.TestCase):
def testEncodeDecode(self):
st1 = os.stat("Makefile")
- stat = obnam.cmp.create_stat_component(st1)
- st2 = obnam.cmp.parse_stat_component(stat)
+ stat = obnamlib.cmp.create_stat_component(st1)
+ st2 = obnamlib.cmp.parse_stat_component(stat)
names1 = [x for x in dir(st1) if x.startswith("st_")]
names2 = [x for x in dir(st2) if x.startswith("st_")]
diff --git a/obnam/config.py b/obnamlib/config.py
index 4bfd3ab5..32f7ae55 100644
--- a/obnam/config.py
+++ b/obnamlib/config.py
@@ -24,13 +24,13 @@ import pwd
import socket
import sys
-import obnam.defaultconfig
+import obnamlib
def default_config():
- """Return a obnam.cfgfile.ConfigFile with the default builtin config"""
- config = obnam.cfgfile.ConfigFile()
- for section, item, value in obnam.defaultconfig.items:
+ """Return a obnamlib.cfgfile.ConfigFile with the default builtin config"""
+ config = obnamlib.cfgfile.ConfigFile()
+ for section, item, value in obnamlib.defaultconfig.items:
if not config.has_section(section):
config.add_section(section)
config.set(section, item, value)
@@ -44,7 +44,7 @@ def default_config():
def build_parser():
"""Create command line parser"""
parser = optparse.OptionParser(version="%s %s" %
- (obnam.NAME, obnam.VERSION))
+ (obnamlib.NAME, obnamlib.VERSION))
parser.add_option("--host-id",
metavar="ID",
@@ -252,8 +252,8 @@ def write_defaultconfig(config, output=sys.stdout):
# Allow unit tests to override default path list.
_default_paths = None
-if "default_paths" in dir(obnam.defaultconfig):
- _default_paths = obnam.defaultconfig.default_paths
+if "default_paths" in dir(obnamlib.defaultconfig):
+ _default_paths = obnamlib.defaultconfig.default_paths
def set_default_paths(default_paths):
global _default_paths
diff --git a/obnam/configTests.py b/obnamlib/configTests.py
index 567b902a..80e3cd0b 100644
--- a/obnam/configTests.py
+++ b/obnamlib/configTests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.config."""
+"""Unit tests for obnamlib.config."""
import os
@@ -24,16 +24,16 @@ import StringIO
import unittest
-import obnam
+import obnamlib
class CommandLineParsingTests(unittest.TestCase):
def setUp(self):
- obnam.config.set_default_paths([])
+ obnamlib.config.set_default_paths([])
def tearDown(self):
- obnam.config.set_default_paths(None)
+ obnamlib.config.set_default_paths(None)
def config_as_string(self, config):
f = StringIO.StringIO()
@@ -41,7 +41,7 @@ class CommandLineParsingTests(unittest.TestCase):
return f.getvalue()
def testDefaultConfig(self):
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
self.failUnless(config.has_section("backup"))
needed = ["block-size", "cache", "store", "target-dir",
"host-id", "object-cache-size", "log-level", "ssh-key",
@@ -54,124 +54,124 @@ class CommandLineParsingTests(unittest.TestCase):
self.failUnlessEqual(actual, needed)
def testEmpty(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, [])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, [])
self.failUnlessEqual(self.config_as_string(config),
- self.config_as_string(obnam.config.default_config()))
+ self.config_as_string(obnamlib.config.default_config()))
def testHostId(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--host-id=pink"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--host-id=pink"])
self.failUnlessEqual(config.get("backup", "host-id"), "pink")
def testBlockSize(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--block-size=12765"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--block-size=12765"])
self.failUnlessEqual(config.getint("backup", "block-size"), 12765)
- obnam.config.parse_options(config, ["--block-size=42"])
+ obnamlib.config.parse_options(config, ["--block-size=42"])
self.failUnlessEqual(config.getint("backup", "block-size"), 42)
def testCacheDir(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--cache=/tmp/foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--cache=/tmp/foo"])
self.failUnlessEqual(config.get("backup", "cache"), "/tmp/foo")
def testLocalStore(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--store=/tmp/foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--store=/tmp/foo"])
self.failUnlessEqual(config.get("backup", "store"), "/tmp/foo")
def testTargetDir(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--target=/tmp/foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--target=/tmp/foo"])
self.failUnlessEqual(config.get("backup", "target-dir"), "/tmp/foo")
def testObjectCacheSize(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--object-cache-size=42"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--object-cache-size=42"])
self.failUnlessEqual(config.get("backup", "object-cache-size"), "42")
def testOdirectRead(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--odirect-read=x"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--odirect-read=x"])
self.failUnlessEqual(config.get("backup", "odirect-read"), "x")
def testOdirectPipe(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--odirect-pipe=x"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--odirect-pipe=x"])
self.failUnlessEqual(config.get("backup", "odirect-pipe"), "x")
def testLogFile(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--log-file=x"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--log-file=x"])
self.failUnlessEqual(config.get("backup", "log-file"), "x")
def testLogLevel(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--log-level=info"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--log-level=info"])
self.failUnlessEqual(config.get("backup", "log-level"), "info")
def testSshKey(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--ssh-key=foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--ssh-key=foo"])
self.failUnlessEqual(config.get("backup", "ssh-key"), "foo")
def testGpgHome(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--gpg-home=foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--gpg-home=foo"])
self.failUnlessEqual(config.get("backup", "gpg-home"), "foo")
def testGpgEncryptTo(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--gpg-encrypt-to=foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--gpg-encrypt-to=foo"])
self.failUnlessEqual(config.get("backup", "gpg-encrypt-to"), "foo")
def testGpgSignWith(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--gpg-sign-with=foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--gpg-sign-with=foo"])
self.failUnlessEqual(config.get("backup", "gpg-sign-with"), "foo")
def testNoGpgIsUnset(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, [])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, [])
self.failUnlessEqual(config.get("backup", "no-gpg"), "false")
def testNoGpgIsUnsetButDefaultIsTrue(self):
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
config.set("backup", "no-gpg", "true")
- obnam.config.parse_options(config, [])
+ obnamlib.config.parse_options(config, [])
self.failUnlessEqual(config.get("backup", "no-gpg"), "true")
def testNoGpgIsSet(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--no-gpg"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--no-gpg"])
self.failUnlessEqual(config.get("backup", "no-gpg"), "true")
def testGenerationTimes(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--generation-times"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--generation-times"])
self.failUnlessEqual(config.get("backup", "generation-times"), "true")
def testExclude(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--exclude=foo"])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--exclude=foo"])
self.failUnlessEqual(config.get("backup", "exclude"), "foo")
def testReportProgress(self):
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
self.failIf(config.getboolean("backup", "report-progress"))
- obnam.config.parse_options(config, ["--progress"])
+ obnamlib.config.parse_options(config, ["--progress"])
self.failUnless(config.getboolean("backup", "report-progress"))
def testNoConfigs(self):
- parser = obnam.config.build_parser()
+ parser = obnamlib.config.build_parser()
options, args = parser.parse_args([])
self.failUnlessEqual(options.no_configs, False)
options, args = parser.parse_args(["--no-configs"])
self.failUnlessEqual(options.no_configs, True)
def testConfig(self):
- parser = obnam.config.build_parser()
+ parser = obnamlib.config.build_parser()
options, args = parser.parse_args([])
self.failUnlessEqual(options.configs, None)
options, args = parser.parse_args(["--config=pink"])
@@ -183,45 +183,45 @@ class ConfigReadingOptionsTests(unittest.TestCase):
names = ["tmp.1.conf", "tmp.2.conf", "tmp.3.conf"]
def setUp(self):
- obnam.config.forget_config_file_log()
+ obnamlib.config.forget_config_file_log()
for name in self.names:
f = file(name, "w")
f.write("[backup]\nblock-size = 1024\n")
f.close()
- obnam.config.set_default_paths(self.names)
+ obnamlib.config.set_default_paths(self.names)
def tearDown(self):
- obnam.config.set_default_paths(None)
+ obnamlib.config.set_default_paths(None)
for name in self.names:
if os.path.exists(name):
os.remove(name)
def testNoDefaults(self):
- obnam.config.set_default_paths([])
- config = obnam.config.default_config()
- obnam.config.parse_options(config, [])
- self.failUnlessEqual(obnam.config.get_config_file_log(), [])
+ obnamlib.config.set_default_paths([])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, [])
+ self.failUnlessEqual(obnamlib.config.get_config_file_log(), [])
def testDefaults(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, [])
- self.failUnlessEqual(obnam.config.get_config_file_log(), self.names)
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, [])
+ self.failUnlessEqual(obnamlib.config.get_config_file_log(), self.names)
def testNoConfigsOption(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--no-configs"])
- self.failUnlessEqual(obnam.config.get_config_file_log(), [])
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--no-configs"])
+ self.failUnlessEqual(obnamlib.config.get_config_file_log(), [])
def testNoConfigsOptionPlusConfigOption(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--no-configs"] +
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--no-configs"] +
["--config=%s" % x for x in self.names])
- self.failUnlessEqual(obnam.config.get_config_file_log(), self.names)
+ self.failUnlessEqual(obnamlib.config.get_config_file_log(), self.names)
def testDefaultsPlusConfigOption(self):
- config = obnam.config.default_config()
- obnam.config.parse_options(config, ["--config=/dev/null"])
- self.failUnlessEqual(obnam.config.get_config_file_log(),
+ config = obnamlib.config.default_config()
+ obnamlib.config.parse_options(config, ["--config=/dev/null"])
+ self.failUnlessEqual(obnamlib.config.get_config_file_log(),
self.names + ["/dev/null"])
@@ -241,23 +241,23 @@ cache = pretty
os.remove(self.filename)
def testReadConfigFile(self):
- config = obnam.config.default_config()
- obnam.config.read_config_file(config, self.filename)
+ config = obnamlib.config.default_config()
+ obnamlib.config.read_config_file(config, self.filename)
self.failUnlessEqual(config.get("backup", "store"), "pink")
self.failUnlessEqual(config.get("backup", "cache"), "pretty")
def testDefaultConfigsForRoot(self):
- config = obnam.config.default_config()
- obnam.config.set_uid_and_home(0, "/root")
- configs = obnam.config.get_default_paths()
+ config = obnamlib.config.default_config()
+ obnamlib.config.set_uid_and_home(0, "/root")
+ configs = obnamlib.config.get_default_paths()
self.failUnlessEqual(configs,
["/usr/share/obnam/obnam.conf",
"/etc/obnam/obnam.conf"])
def testDefaultConfigsForUser(self):
- config = obnam.config.default_config()
- obnam.config.set_uid_and_home(12765, "/home/pretty")
- configs = obnam.config.get_default_paths()
+ config = obnamlib.config.default_config()
+ obnamlib.config.set_uid_and_home(12765, "/home/pretty")
+ configs = obnamlib.config.get_default_paths()
self.failUnlessEqual(configs,
["/usr/share/obnam/obnam.conf",
"/home/pretty/.obnam/obnam.conf"])
@@ -267,16 +267,16 @@ class PrintOptionsTests(unittest.TestCase):
def test(self):
f = StringIO.StringIO()
- obnam.config.print_option_names(f=f)
+ obnamlib.config.print_option_names(f=f)
self.failIfEqual(f.getvalue(), "")
class WriteDefaultConfigTests(unittest.TestCase):
def test(self):
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
f = StringIO.StringIO()
- obnam.config.write_defaultconfig(config, output=f)
+ obnamlib.config.write_defaultconfig(config, output=f)
s = f.getvalue()
self.failUnless(s.startswith("import socket"))
self.failUnless("\nitems =" in s)
@@ -285,17 +285,17 @@ class WriteDefaultConfigTests(unittest.TestCase):
class GetUidAndHomeTests(unittest.TestCase):
def testGetUid(self):
- obnam.config.set_uid_and_home(None, None)
- self.failIfEqual(obnam.config.get_uid(), None)
+ obnamlib.config.set_uid_and_home(None, None)
+ self.failIfEqual(obnamlib.config.get_uid(), None)
def testGetHome(self):
- obnam.config.set_uid_and_home(None, None)
- self.failIfEqual(obnam.config.get_home(), None)
+ obnamlib.config.set_uid_and_home(None, None)
+ self.failIfEqual(obnamlib.config.get_home(), None)
def testGetUidFaked(self):
- obnam.config.set_uid_and_home(42, "pretty")
- self.failUnlessEqual(obnam.config.get_uid(), 42)
+ obnamlib.config.set_uid_and_home(42, "pretty")
+ self.failUnlessEqual(obnamlib.config.get_uid(), 42)
def testGetHomeFaked(self):
- obnam.config.set_uid_and_home(42, "pink")
- self.failUnlessEqual(obnam.config.get_home(), "pink")
+ obnamlib.config.set_uid_and_home(42, "pink")
+ self.failUnlessEqual(obnamlib.config.get_home(), "pink")
diff --git a/obnam/context.py b/obnamlib/context.py
index b82ee4fe..8c4ebb6c 100644
--- a/obnam/context.py
+++ b/obnamlib/context.py
@@ -18,20 +18,18 @@
"""Processing context for Obnam"""
-import obnam.config
-import obnam.map
-import obnam.obj
+import obnamlib
class Context:
def __init__(self):
- self.config = obnam.config.default_config()
+ self.config = obnamlib.config.default_config()
self.cache = None
self.be = None
- self.map = obnam.map.create()
- self.contmap = obnam.map.create()
- self.oq = obnam.obj.ObjectQueue()
- self.content_oq = obnam.obj.ObjectQueue()
- self.progress = obnam.progress.ProgressReporter(self.config)
+ self.map = obnamlib.map.create()
+ self.contmap = obnamlib.map.create()
+ self.oq = obnamlib.obj.ObjectQueue()
+ self.content_oq = obnamlib.obj.ObjectQueue()
+ self.progress = obnamlib.progress.ProgressReporter(self.config)
self.object_cache = None
diff --git a/obnam/contextTests.py b/obnamlib/contextTests.py
index bd85535a..32858155 100644
--- a/obnam/contextTests.py
+++ b/obnamlib/contextTests.py
@@ -15,19 +15,19 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.context."""
+"""Unit tests for obnamlib.context."""
import unittest
-import obnam
+import obnamlib
class ContextCreateTests(unittest.TestCase):
def test(self):
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
attrs = [x for x in dir(context) if not x.startswith("_")]
attrs.sort()
self.failUnlessEqual(attrs,
diff --git a/obnam/defaultconfig.py b/obnamlib/defaultconfig.py
index 63a5c401..63a5c401 100644
--- a/obnam/defaultconfig.py
+++ b/obnamlib/defaultconfig.py
diff --git a/obnam/exception.py b/obnamlib/exception.py
index 130378dd..130378dd 100644
--- a/obnam/exception.py
+++ b/obnamlib/exception.py
diff --git a/obnam/exceptionTests.py b/obnamlib/exceptionTests.py
index 5b911442..f15d2dd0 100644
--- a/obnam/exceptionTests.py
+++ b/obnamlib/exceptionTests.py
@@ -15,15 +15,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.exception"""
+"""Unit tests for obnamlib.exception"""
import unittest
-import obnam
+import obnamlib
-class SampleException(obnam.ObnamException):
+class SampleException(obnamlib.ObnamException):
def __init__(self, msg):
self._msg = msg
diff --git a/obnam/filelist.py b/obnamlib/filelist.py
index 18aa67df..0c9acd68 100644
--- a/obnam/filelist.py
+++ b/obnamlib/filelist.py
@@ -21,7 +21,7 @@
import os
-import obnam
+import obnamlib
def create_file_component(pathname, contref, sigref, deltaref):
@@ -34,18 +34,18 @@ def create_file_component_from_stat(pathname, st, contref, sigref, deltaref):
"""Create a FILE component given pathname, stat results, etc"""
subs = []
- subs.append(obnam.cmp.Component(obnam.cmp.FILENAME, pathname))
+ subs.append(obnamlib.cmp.Component(obnamlib.cmp.FILENAME, pathname))
- subs.append(obnam.cmp.create_stat_component(st))
+ subs.append(obnamlib.cmp.create_stat_component(st))
if contref:
- subs.append(obnam.cmp.Component(obnam.cmp.CONTREF, contref))
+ subs.append(obnamlib.cmp.Component(obnamlib.cmp.CONTREF, contref))
if sigref:
- subs.append(obnam.cmp.Component(obnam.cmp.SIGREF, sigref))
+ subs.append(obnamlib.cmp.Component(obnamlib.cmp.SIGREF, sigref))
if deltaref:
- subs.append(obnam.cmp.Component(obnam.cmp.DELTAREF, deltaref))
+ subs.append(obnamlib.cmp.Component(obnamlib.cmp.DELTAREF, deltaref))
- return obnam.cmp.Component(obnam.cmp.FILE, subs)
+ return obnamlib.cmp.Component(obnamlib.cmp.FILE, subs)
class Filelist:
@@ -82,8 +82,8 @@ class Filelist:
"""Find the FILE component that matches stat_result"""
prev = self.find(pathname)
if prev:
- prev_stat = prev.first_by_kind(obnam.cmp.STAT)
- prev_st = obnam.cmp.parse_stat_component(prev_stat)
+ prev_stat = prev.first_by_kind(obnamlib.cmp.STAT)
+ prev_st = obnamlib.cmp.parse_stat_component(prev_stat)
fields = ["st_dev",
"st_mode",
"st_nlink",
@@ -102,13 +102,13 @@ class Filelist:
def to_object(self, object_id):
"""Create an unencoded FILELIST object from a file list"""
- o = obnam.obj.FileListObject(id=object_id)
+ o = obnamlib.obj.FileListObject(id=object_id)
for pathname in self.dict:
o.add(self.dict[pathname])
return o
def from_object(self, o):
"""Add to file list data from a backup object"""
- for file in o.find_by_kind(obnam.cmp.FILE):
- pathname = file.first_string_by_kind(obnam.cmp.FILENAME)
+ for file in o.find_by_kind(obnamlib.cmp.FILE):
+ pathname = file.first_string_by_kind(obnamlib.cmp.FILENAME)
self.dict[pathname] = file
diff --git a/obnam/filelistTests.py b/obnamlib/filelistTests.py
index 6215ad50..77c7b9a4 100644
--- a/obnam/filelistTests.py
+++ b/obnamlib/filelistTests.py
@@ -15,14 +15,14 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.filelist."""
+"""Unit tests for obnamlib.filelist."""
import os
import unittest
-import obnam
+import obnamlib
class FileComponentTests(unittest.TestCase):
@@ -30,24 +30,24 @@ class FileComponentTests(unittest.TestCase):
filename = "README"
def testCreate(self):
- c = obnam.filelist.create_file_component(self.filename, "pink",
+ c = obnamlib.filelist.create_file_component(self.filename, "pink",
"pretty", "black")
self.check(c)
def testCreateFromStatResult(self):
st = os.lstat(self.filename)
- c = obnam.filelist.create_file_component_from_stat(self.filename, st,
+ c = obnamlib.filelist.create_file_component_from_stat(self.filename, st,
"pink", "pretty",
"black")
self.check(c)
def check(self, c):
self.failIfEqual(c, None)
- self.failUnlessEqual(c.first_string_by_kind(obnam.cmp.FILENAME),
+ self.failUnlessEqual(c.first_string_by_kind(obnamlib.cmp.FILENAME),
self.filename)
- c_stat = c.first_by_kind(obnam.cmp.STAT)
- c_st = obnam.cmp.parse_stat_component(c_stat)
+ c_stat = c.first_by_kind(obnamlib.cmp.STAT)
+ c_st = obnamlib.cmp.parse_stat_component(c_stat)
st = os.lstat(self.filename)
self.failUnlessEqual(c_st.st_mode, st.st_mode)
@@ -64,48 +64,48 @@ class FileComponentTests(unittest.TestCase):
self.failUnlessEqual(c_st.st_blksize, st.st_blksize)
self.failUnlessEqual(c_st.st_rdev, st.st_rdev)
- self.failUnlessEqual(c.first_string_by_kind(obnam.cmp.CONTREF),
+ self.failUnlessEqual(c.first_string_by_kind(obnamlib.cmp.CONTREF),
"pink")
- self.failUnlessEqual(c.first_string_by_kind(obnam.cmp.SIGREF),
+ self.failUnlessEqual(c.first_string_by_kind(obnamlib.cmp.SIGREF),
"pretty")
- self.failUnlessEqual(c.first_string_by_kind(obnam.cmp.DELTAREF),
+ self.failUnlessEqual(c.first_string_by_kind(obnamlib.cmp.DELTAREF),
"black")
class FilelistTests(unittest.TestCase):
def testCreate(self):
- fl = obnam.filelist.Filelist()
+ fl = obnamlib.filelist.Filelist()
self.failUnlessEqual(fl.num_files(), 0)
def testAddFind(self):
- fl = obnam.filelist.Filelist()
+ fl = obnamlib.filelist.Filelist()
fl.add(".", "pink", None, None)
self.failUnlessEqual(fl.num_files(), 1)
c = fl.find(".")
- self.failUnlessEqual(c.get_kind(), obnam.cmp.FILE)
+ self.failUnlessEqual(c.get_kind(), obnamlib.cmp.FILE)
def testListFiles(self):
- fl = obnam.filelist.Filelist()
+ fl = obnamlib.filelist.Filelist()
fl.add(".", "pink", None, None)
self.failUnlessEqual(fl.list_files(), ["."])
def testAddFileComponent(self):
- fl = obnam.filelist.Filelist()
- fc = obnam.filelist.create_file_component(".", "pink", None, None)
+ fl = obnamlib.filelist.Filelist()
+ fc = obnamlib.filelist.create_file_component(".", "pink", None, None)
fl.add_file_component(".", fc)
self.failUnlessEqual(fl.num_files(), 1)
c = fl.find(".")
- self.failUnlessEqual(c.get_kind(), obnam.cmp.FILE)
+ self.failUnlessEqual(c.get_kind(), obnamlib.cmp.FILE)
def testToFromObject(self):
- fl = obnam.filelist.Filelist()
+ fl = obnamlib.filelist.Filelist()
fl.add(".", "pretty", None, None)
o = fl.to_object("pink")
- self.failUnlessEqual(o.get_kind(), obnam.obj.FILELIST)
+ self.failUnlessEqual(o.get_kind(), obnamlib.obj.FILELIST)
self.failUnlessEqual(o.get_id(), "pink")
- fl2 = obnam.filelist.Filelist()
+ fl2 = obnamlib.filelist.Filelist()
fl2.from_object(o)
self.failIfEqual(fl2, None)
self.failUnlessEqual(type(fl), type(fl2))
@@ -113,24 +113,24 @@ class FilelistTests(unittest.TestCase):
c = fl2.find(".")
self.failIfEqual(c, None)
- self.failUnlessEqual(c.get_kind(), obnam.cmp.FILE)
+ self.failUnlessEqual(c.get_kind(), obnamlib.cmp.FILE)
class FindTests(unittest.TestCase):
def testFindInodeSuccessful(self):
pathname = "Makefile"
- fl = obnam.filelist.Filelist()
+ fl = obnamlib.filelist.Filelist()
fl.add(pathname, "pink", None, None)
st = os.lstat(pathname)
c = fl.find_matching_inode(pathname, st)
- stat = c.first_by_kind(obnam.cmp.STAT)
- st2 = obnam.cmp.parse_stat_component(stat)
+ stat = c.first_by_kind(obnamlib.cmp.STAT)
+ st2 = obnamlib.cmp.parse_stat_component(stat)
self.failUnlessEqual(st.st_mtime, st2.st_mtime)
def testFindInodeUnsuccessful(self):
pathname = "Makefile"
- fl = obnam.filelist.Filelist()
+ fl = obnamlib.filelist.Filelist()
fl.add(pathname, "pink", None, None)
st = os.lstat(".")
c = fl.find_matching_inode(pathname, st)
diff --git a/obnam/format.py b/obnamlib/format.py
index d383733f..e031ce10 100644
--- a/obnam/format.py
+++ b/obnamlib/format.py
@@ -23,7 +23,7 @@ import stat
import time
-import obnam
+import obnamlib
def permissions(mode):
@@ -103,8 +103,8 @@ def inode_fields(file_component):
]
list = []
- stat_component = file_component.first_by_kind(obnam.cmp.STAT)
- st = obnam.cmp.parse_stat_component(stat_component)
+ stat_component = file_component.first_by_kind(obnamlib.cmp.STAT)
+ st = obnamlib.cmp.parse_stat_component(stat_component)
for kind, func in fields:
list.append(func(st.__getattribute__(kind)))
return list
@@ -126,7 +126,7 @@ class Listing:
def __init__(self, context, output_file):
self._context = context
self._output = output_file
- self._get_object = obnam.io.get_object
+ self._get_object = obnamlib.io.get_object
def get_objects(self, refs):
list = []
diff --git a/obnam/formatTests.py b/obnamlib/formatTests.py
index 5d97b470..0f1534ac 100644
--- a/obnam/formatTests.py
+++ b/obnamlib/formatTests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.format."""
+"""Unit tests for obnamlib.format."""
import re
@@ -24,7 +24,7 @@ import StringIO
import unittest
-import obnam
+import obnamlib
class Fake:
@@ -54,7 +54,7 @@ class FormatPermissionsTests(unittest.TestCase):
(04000, "--S------"), # Set user id (upper case since no x)
)
for mode, correct in facit:
- self.failUnlessEqual(obnam.format.permissions(mode), correct)
+ self.failUnlessEqual(obnamlib.format.permissions(mode), correct)
class FormatFileTypeTests(unittest.TestCase):
@@ -71,13 +71,13 @@ class FormatFileTypeTests(unittest.TestCase):
(stat.S_IFIFO, "p"), # FIFO
)
for mode, correct in facit:
- self.failUnlessEqual(obnam.format.filetype(mode), correct)
+ self.failUnlessEqual(obnamlib.format.filetype(mode), correct)
class FormatFileModeTest(unittest.TestCase):
def test(self):
- self.failUnlessEqual(obnam.format.filemode(0100777), "-rwxrwxrwx")
+ self.failUnlessEqual(obnamlib.format.filemode(0100777), "-rwxrwxrwx")
class FormatInodeFieldsTest(unittest.TestCase):
@@ -98,10 +98,10 @@ class FormatInodeFieldsTest(unittest.TestCase):
st.st_blksize = 1
st.st_rdev = 1
file_component = \
- obnam.filelist.create_file_component_from_stat("Makefile", st,
+ obnamlib.filelist.create_file_component_from_stat("Makefile", st,
None, None, None)
- list = obnam.format.inode_fields(file_component)
+ list = obnamlib.format.inode_fields(file_component)
self.failUnlessEqual(list, ["?--------x"] + ["1"] * 4 +
["1970-01-01 00:00:01"])
@@ -110,7 +110,7 @@ class FormatInodeFieldsTest(unittest.TestCase):
class FormatTimeTests(unittest.TestCase):
def test(self):
- self.failUnlessEqual(obnam.format.timestamp(1), "1970-01-01 00:00:01")
+ self.failUnlessEqual(obnamlib.format.timestamp(1), "1970-01-01 00:00:01")
@@ -120,9 +120,9 @@ class ListingTests(unittest.TestCase):
filepat = re.compile(r"^-rw-rw-rw- 0 0 0 0 1970-01-01 00:00:00 pink$")
def make_filegroup(self, filenames):
- fg = obnam.obj.FileGroupObject(id=obnam.obj.object_id_new())
+ fg = obnamlib.obj.FileGroupObject(id=obnamlib.obj.object_id_new())
mode = 0666 | stat.S_IFREG
- st = obnam.utils.make_stat_result(st_mode=mode)
+ st = obnamlib.utils.make_stat_result(st_mode=mode)
for filename in filenames:
fg.add_file(filename, st, None, None, None)
@@ -131,8 +131,8 @@ class ListingTests(unittest.TestCase):
def make_dir(self, name, dirs, filegroups):
mode = 0777 | stat.S_IFDIR
- st = obnam.utils.make_stat_result(st_mode=mode)
- dir = obnam.obj.DirObject(id=obnam.obj.object_id_new(),
+ st = obnamlib.utils.make_stat_result(st_mode=mode)
+ dir = obnamlib.obj.DirObject(id=obnamlib.obj.object_id_new(),
name=name,
stat=st,
dirrefs=[x.get_id() for x in dirs],
@@ -147,7 +147,7 @@ class ListingTests(unittest.TestCase):
def setUp(self):
self.objects = {}
self.file = StringIO.StringIO()
- self.listing = obnam.format.Listing(None, self.file)
+ self.listing = obnamlib.format.Listing(None, self.file)
self.listing._get_object = self.mock_get_object
def testWritesNothingForNothing(self):
diff --git a/obnam/gpg.py b/obnamlib/gpg.py
index 1212dac4..262cd823 100644
--- a/obnam/gpg.py
+++ b/obnamlib/gpg.py
@@ -24,10 +24,10 @@ import subprocess
import tempfile
-import obnam
+import obnamlib
-class GpgEncryptionFailure(obnam.ObnamException):
+class GpgEncryptionFailure(obnamlib.ObnamException):
def __init__(self, returncode, stderr):
self._msg = "GPG failed to encrypt: exit code %d" % returncode
@@ -35,7 +35,7 @@ class GpgEncryptionFailure(obnam.ObnamException):
self._msg += "\n%s" % indent_string(stderr)
-class GpgDecryptionFailure(obnam.ObnamException):
+class GpgDecryptionFailure(obnamlib.ObnamException):
def __init__(self, returncode, stderr):
self._msg = "GPG failed to decrypt: exit code %d" % returncode
diff --git a/obnam/gpgTests.py b/obnamlib/gpgTests.py
index 68d286ba..66dd526e 100644
--- a/obnam/gpgTests.py
+++ b/obnamlib/gpgTests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.gpg."""
+"""Unit tests for obnamlib.gpg."""
import os
@@ -24,28 +24,28 @@ import tempfile
import unittest
-import obnam
+import obnamlib
class GpgEncryptionFailureTests(unittest.TestCase):
def testIncludesExitCodeInMessage(self):
- e = obnam.gpg.GpgEncryptionFailure(42, "")
+ e = obnamlib.gpg.GpgEncryptionFailure(42, "")
self.failUnless("42" in str(e))
def testIncludesStderrInMessage(self):
- e = obnam.gpg.GpgEncryptionFailure(42, "pink")
+ e = obnamlib.gpg.GpgEncryptionFailure(42, "pink")
self.failUnless("pink" in str(e))
class GpgDecryptionFailureTests(unittest.TestCase):
def testIncludesExitCodeInMessage(self):
- e = obnam.gpg.GpgDecryptionFailure(42, "")
+ e = obnamlib.gpg.GpgDecryptionFailure(42, "")
self.failUnless("42" in str(e))
def testIncludesStderrInMessage(self):
- e = obnam.gpg.GpgDecryptionFailure(42, "pink")
+ e = obnamlib.gpg.GpgDecryptionFailure(42, "pink")
self.failUnless("pink" in str(e))
@@ -53,30 +53,30 @@ class GpgTests(unittest.TestCase):
def test(self):
block = "pink"
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
config.set("backup", "gpg-home", "sample-gpg-home")
config.set("backup", "gpg-encrypt-to", "490C9ED1")
config.set("backup", "gpg-sign-with", "490C9ED1")
- encrypted = obnam.gpg.encrypt(config, block)
+ encrypted = obnamlib.gpg.encrypt(config, block)
self.failIf(block in encrypted)
- decrypted = obnam.gpg.decrypt(config, encrypted)
+ decrypted = obnamlib.gpg.decrypt(config, encrypted)
self.failUnlessEqual(block, decrypted)
def testEncryptionWithInvalidKey(self):
block = "pink"
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
config.set("backup", "gpg-home", "sample-gpg-home")
config.set("backup", "gpg-encrypt-to", "pretty")
- self.failUnlessRaises(obnam.gpg.GpgEncryptionFailure,
- obnam.gpg.encrypt, config, block)
+ self.failUnlessRaises(obnamlib.gpg.GpgEncryptionFailure,
+ obnamlib.gpg.encrypt, config, block)
def testDecryptionWithInvalidData(self):
encrypted = "pink"
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
config.set("backup", "gpg-home", "sample-gpg-home")
- self.failUnlessRaises(obnam.gpg.GpgDecryptionFailure,
- obnam.gpg.decrypt, config, encrypted)
+ self.failUnlessRaises(obnamlib.gpg.GpgDecryptionFailure,
+ obnamlib.gpg.decrypt, config, encrypted)
diff --git a/obnam/io.py b/obnamlib/io.py
index 7bc95434..59c14976 100644
--- a/obnam/io.py
+++ b/obnamlib/io.py
@@ -25,7 +25,7 @@ import subprocess
import tempfile
-import obnam
+import obnamlib
def resolve(context, pathname):
@@ -59,7 +59,7 @@ def flush_object_queue(context, oq, map, to_cache):
block = oq.as_block(block_id)
context.be.upload_block(block_id, block, to_cache)
for id in oq.ids():
- obnam.map.add(map, id, block_id)
+ obnamlib.map.add(map, id, block_id)
oq.clear()
@@ -76,11 +76,11 @@ def get_block(context, block_id):
block = context.be.download_block(block_id)
elif context.be.use_gpg():
logging.debug("Decrypting cached block %s before using it", block_id)
- block = obnam.gpg.decrypt(context.config, block)
+ block = obnamlib.gpg.decrypt(context.config, block)
return block
-class MissingBlock(obnam.ObnamException):
+class MissingBlock(obnamlib.ObnamException):
def __init__(self, block_id, object_id):
self._msg = "Block %s for object %s is missing" % \
@@ -137,9 +137,9 @@ def get_object(context, object_id):
return o
logging.debug("Object not in cache, looking up mapping")
- block_id = obnam.map.get(context.map, object_id)
+ block_id = obnamlib.map.get(context.map, object_id)
if not block_id:
- block_id = obnam.map.get(context.contmap, object_id)
+ block_id = obnamlib.map.get(context.contmap, object_id)
if not block_id:
return None
@@ -147,18 +147,18 @@ def get_object(context, object_id):
block = get_block(context, block_id)
logging.debug("Decoding block")
- list = obnam.obj.block_decode(block)
+ list = obnamlib.obj.block_decode(block)
logging.debug("Finding objects in block")
- list = obnam.cmp.find_by_kind(list, obnam.cmp.OBJECT)
+ list = obnamlib.cmp.find_by_kind(list, obnamlib.cmp.OBJECT)
logging.debug("Putting objects into object cache")
the_one = None
- factory = obnam.obj.StorageObjectFactory()
+ factory = obnamlib.obj.StorageObjectFactory()
for component in list:
subs = component.get_subcomponents()
o = factory.get_object(subs)
- if o.get_kind() != obnam.obj.FILEPART:
+ if o.get_kind() != obnamlib.obj.FILEPART:
context.object_cache.put(o)
if o.get_id() == object_id:
the_one = o
@@ -187,14 +187,14 @@ def enqueue_object(context, oq, map, object_id, object, to_cache):
block_size = context.config.getint("backup", "block-size")
cur_size = oq.combined_size()
if len(object) + cur_size > block_size:
- obnam.io.flush_object_queue(context, oq, map, to_cache)
+ obnamlib.io.flush_object_queue(context, oq, map, to_cache)
oq.clear()
oq.add(object_id, object)
def create_file_contents_object(context, filename):
"""Create and queue objects to hold a file's contents"""
- object_id = obnam.obj.object_id_new()
+ object_id = obnamlib.obj.object_id_new()
part_ids = []
odirect_read = context.config.get("backup", "odirect-read")
block_size = context.config.getint("backup", "block-size")
@@ -204,17 +204,17 @@ def create_file_contents_object(context, filename):
data = f.stdout.read(block_size)
if not data:
break
- c = obnam.cmp.Component(obnam.cmp.FILECHUNK, data)
- part_id = obnam.obj.object_id_new()
- o = obnam.obj.FilePartObject(id=part_id, components=[c])
+ c = obnamlib.cmp.Component(obnamlib.cmp.FILECHUNK, data)
+ part_id = obnamlib.obj.object_id_new()
+ o = obnamlib.obj.FilePartObject(id=part_id, components=[c])
o = o.encode()
enqueue_object(context, context.content_oq, context.contmap,
part_id, o, False)
part_ids.append(part_id)
- o = obnam.obj.FileContentsObject(id=object_id)
+ o = obnamlib.obj.FileContentsObject(id=object_id)
for part_id in part_ids:
- c = obnam.cmp.Component(obnam.cmp.FILEPARTREF, part_id)
+ c = obnamlib.cmp.Component(obnamlib.cmp.FILEPARTREF, part_id)
o.add(c)
o = o.encode()
enqueue_object(context, context.oq, context.map, object_id, o, True)
@@ -224,7 +224,7 @@ def create_file_contents_object(context, filename):
return object_id
-class FileContentsObjectMissing(obnam.ObnamException):
+class FileContentsObjectMissing(obnamlib.ObnamException):
def __init__(self, id):
self._msg = "Missing file contents object: %s" % id
@@ -232,13 +232,13 @@ class FileContentsObjectMissing(obnam.ObnamException):
def copy_file_contents(context, fd, cont_id):
"""Write contents of a file in backup to a file descriptor"""
- cont = obnam.io.get_object(context, cont_id)
+ cont = obnamlib.io.get_object(context, cont_id)
if not cont:
raise FileContentsObjectMissing(cont_id)
- part_ids = cont.find_strings_by_kind(obnam.cmp.FILEPARTREF)
+ part_ids = cont.find_strings_by_kind(obnamlib.cmp.FILEPARTREF)
for part_id in part_ids:
- part = obnam.io.get_object(context, part_id)
- chunk = part.first_string_by_kind(obnam.cmp.FILECHUNK)
+ part = obnamlib.io.get_object(context, part_id)
+ chunk = part.first_string_by_kind(obnamlib.cmp.FILECHUNK)
os.write(fd, chunk)
@@ -248,23 +248,23 @@ def reconstruct_file_contents(context, fd, delta_id):
logging.debug("Finding chain of DELTAs")
- delta = obnam.io.get_object(context, delta_id)
+ delta = obnamlib.io.get_object(context, delta_id)
if not delta:
logging.error("Can't find DELTA object to reconstruct: %s" % delta_id)
return
stack = [delta]
while True:
- prev_delta_id = stack[-1].first_string_by_kind(obnam.cmp.DELTAREF)
+ prev_delta_id = stack[-1].first_string_by_kind(obnamlib.cmp.DELTAREF)
if not prev_delta_id:
break
- prev_delta = obnam.io.get_object(context, prev_delta_id)
+ prev_delta = obnamlib.io.get_object(context, prev_delta_id)
if not prev_delta:
logging.error("Can't find DELTA object %s" % prev_delta_id)
return
stack.append(prev_delta)
- cont_id = stack[-1].first_string_by_kind(obnam.cmp.CONTREF)
+ cont_id = stack[-1].first_string_by_kind(obnamlib.cmp.CONTREF)
if not cont_id:
logging.error("DELTA object chain does not end in CONTREF")
return
@@ -278,10 +278,10 @@ def reconstruct_file_contents(context, fd, delta_id):
stack = stack[:-1]
logging.debug("Applying DELTA %s" % delta.get_id())
- deltapart_ids = delta.find_strings_by_kind(obnam.cmp.DELTAPARTREF)
+ deltapart_ids = delta.find_strings_by_kind(obnamlib.cmp.DELTAPARTREF)
(temp_fd2, temp_name2) = tempfile.mkstemp()
- obnam.rsync.apply_delta(context, temp_name1, deltapart_ids,
+ obnamlib.rsync.apply_delta(context, temp_name1, deltapart_ids,
temp_name2)
os.remove(temp_name1)
os.close(temp_fd1)
@@ -300,13 +300,13 @@ def reconstruct_file_contents(context, fd, delta_id):
def set_inode(full_pathname, file_component):
- stat_component = file_component.first_by_kind(obnam.cmp.STAT)
- st = obnam.cmp.parse_stat_component(stat_component)
+ stat_component = file_component.first_by_kind(obnamlib.cmp.STAT)
+ st = obnamlib.cmp.parse_stat_component(stat_component)
os.utime(full_pathname, (st.st_atime, st.st_mtime))
os.chmod(full_pathname, stat.S_IMODE(st.st_mode))
-_interesting = set([obnam.cmp.OBJECT, obnam.cmp.FILE])
+_interesting = set([obnamlib.cmp.OBJECT, obnamlib.cmp.FILE])
def _find_refs(components, refs=None):
"""Return set of all references (recursively) in a list of components"""
if refs is None:
@@ -314,7 +314,7 @@ def _find_refs(components, refs=None):
for c in components:
kind = c.get_kind()
- if obnam.cmp.kind_is_reference(kind):
+ if obnamlib.cmp.kind_is_reference(kind):
refs.add(c.get_string_value())
elif kind in _interesting:
subs = c.get_subcomponents()
@@ -326,7 +326,7 @@ def _find_refs(components, refs=None):
def find_reachable_data_blocks(context, host_block):
"""Find all blocks with data that can be reached from host block"""
logging.debug("Finding reachable data")
- host = obnam.obj.create_host_from_block(host_block)
+ host = obnamlib.obj.create_host_from_block(host_block)
gen_ids = host.get_generation_ids()
object_ids = set(gen_ids)
reachable_block_ids = set()
@@ -334,9 +334,9 @@ def find_reachable_data_blocks(context, host_block):
logging.debug("find_reachable_data_blocks: %d remaining" %
len(object_ids))
object_id = object_ids.pop()
- block_id = obnam.map.get(context.map, object_id)
+ block_id = obnamlib.map.get(context.map, object_id)
if not block_id:
- block_id = obnam.map.get(context.contmap, object_id)
+ block_id = obnamlib.map.get(context.contmap, object_id)
if not block_id:
logging.warning("Can't find object %s in any block" % object_id)
elif block_id not in reachable_block_ids:
@@ -345,7 +345,7 @@ def find_reachable_data_blocks(context, host_block):
reachable_block_ids.add(block_id)
block = get_block(context, block_id)
logging.debug("Finding references within block")
- refs = _find_refs(obnam.obj.block_decode(block))
+ refs = _find_refs(obnamlib.obj.block_decode(block))
logging.debug("This block contains %d refs" % len(refs))
refs = [ref for ref in refs if ref not in reachable_block_ids]
logging.debug("This block contains %d refs not already reachable"
@@ -358,17 +358,17 @@ def find_reachable_data_blocks(context, host_block):
def find_map_blocks_in_use(context, host_block, data_block_ids):
"""Given data blocks in use, return map blocks they're mentioned in"""
data_block_ids = set(data_block_ids)
- host = obnam.obj.create_host_from_block(host_block)
+ host = obnamlib.obj.create_host_from_block(host_block)
map_block_ids = host.get_map_block_ids()
contmap_block_ids = host.get_contmap_block_ids()
used_map_block_ids = set()
for map_block_id in map_block_ids + contmap_block_ids:
block = get_block(context, map_block_id)
- list = obnam.obj.block_decode(block)
+ list = obnamlib.obj.block_decode(block)
assert type(list) == type([])
- list = obnam.cmp.find_by_kind(list, obnam.cmp.OBJMAP)
+ list = obnamlib.cmp.find_by_kind(list, obnamlib.cmp.OBJMAP)
for c in list:
- id = c.first_string_by_kind(obnam.cmp.BLOCKREF)
+ id = c.first_string_by_kind(obnamlib.cmp.BLOCKREF)
if id in data_block_ids:
used_map_block_ids.add(map_block_id)
break # We already know this entire map block is used
@@ -403,5 +403,5 @@ def load_maps(context, map, block_ids):
for i in range(num_blocks):
id = block_ids[i]
logging.debug("Loading map block %d/%d: %s" % (i+1, num_blocks, id))
- block = obnam.io.get_block(context, id)
- obnam.map.decode_block(map, block)
+ block = obnamlib.io.get_block(context, id)
+ obnamlib.map.decode_block(map, block)
diff --git a/obnam/ioTests.py b/obnamlib/ioTests.py
index 4e878566..4e036096 100644
--- a/obnam/ioTests.py
+++ b/obnamlib/ioTests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.io"""
+"""Unit tests for obnamlib.io"""
import os
@@ -24,25 +24,25 @@ import tempfile
import unittest
-import obnam
+import obnamlib
class ExceptionTests(unittest.TestCase):
def testMissingBlock(self):
- e = obnam.io.MissingBlock("pink", "pretty")
+ e = obnamlib.io.MissingBlock("pink", "pretty")
self.failUnless("pink" in str(e))
self.failUnless("pretty" in str(e))
def testFileContentsObjectMissing(self):
- e = obnam.io.FileContentsObjectMissing("pink")
+ e = obnamlib.io.FileContentsObjectMissing("pink")
self.failUnless("pink" in str(e))
class ResolveTests(unittest.TestCase):
def test(self):
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
# We don't need the fields that are usually initialized manually.
facit = (
@@ -60,11 +60,11 @@ class ResolveTests(unittest.TestCase):
for target, pathname, resolved in facit:
context.config.set("backup", "target-dir", target)
- x = obnam.io.resolve(context, pathname)
+ x = obnamlib.io.resolve(context, pathname)
self.failUnlessEqual(x, resolved)
- self.failUnlessEqual(obnam.io.unsolve(context, x), pathname)
+ self.failUnlessEqual(obnamlib.io.unsolve(context, x), pathname)
- self.failUnlessEqual(obnam.io.unsolve(context, "/pink"), "pink")
+ self.failUnlessEqual(obnamlib.io.unsolve(context, "/pink"), "pink")
class IoBase(unittest.TestCase):
@@ -81,13 +81,13 @@ class IoBase(unittest.TestCase):
("backup", "store", self.rootdir)
)
- self.context = obnam.context.Context()
+ self.context = obnamlib.context.Context()
for section, item, value in config_list:
self.context.config.set(section, item, value)
- self.context.cache = obnam.cache.Cache(self.context.config)
- self.context.be = obnam.backend.init(self.context.config,
+ self.context.cache = obnamlib.cache.Cache(self.context.config)
+ self.context.be = obnamlib.backend.init(self.context.config,
self.context.cache)
def tearDown(self):
@@ -101,7 +101,7 @@ class IoBase(unittest.TestCase):
class ObjectQueueFlushing(IoBase):
def testEmptyQueue(self):
- obnam.io.flush_object_queue(self.context, self.context.oq,
+ obnamlib.io.flush_object_queue(self.context, self.context.oq,
self.context.map, False)
list = self.context.be.list()
self.failUnlessEqual(list, [])
@@ -111,20 +111,20 @@ class ObjectQueueFlushing(IoBase):
self.failUnlessEqual(self.context.be.list(), [])
- obnam.io.flush_object_queue(self.context, self.context.oq,
+ obnamlib.io.flush_object_queue(self.context, self.context.oq,
self.context.map, False)
list = self.context.be.list()
self.failUnlessEqual(len(list), 1)
- b1 = os.path.basename(obnam.map.get(self.context.map, "pink"))
+ b1 = os.path.basename(obnamlib.map.get(self.context.map, "pink"))
b2 = os.path.basename(list[0])
self.failUnlessEqual(b1, b2)
def testFlushAll(self):
self.context.oq.add("pink", "pretty")
self.context.content_oq.add("x", "y")
- obnam.io.flush_all_object_queues(self.context)
+ obnamlib.io.flush_all_object_queues(self.context)
self.failUnlessEqual(len(self.context.be.list()), 2)
self.failUnless(self.context.oq.is_empty())
self.failUnless(self.context.content_oq.is_empty())
@@ -136,76 +136,76 @@ class GetBlockTests(IoBase):
self.context.be.upload_block("pink", "pretty", to_cache)
def testRaisesIoErrorForNonExistentBlock(self):
- self.failUnlessRaises(IOError, obnam.io.get_block, self.context, "pink")
+ self.failUnlessRaises(IOError, obnamlib.io.get_block, self.context, "pink")
def testFindsBlockWhenNotInCache(self):
self.setup_pink_block(to_cache=False)
- self.failUnless(obnam.io.get_block(self.context, "pink"))
+ self.failUnless(obnamlib.io.get_block(self.context, "pink"))
def testFindsBlockWhenInCache(self):
self.setup_pink_block(to_cache=True)
- obnam.io.get_block(self.context, "pink")
- self.failUnless(obnam.io.get_block(self.context, "pink"))
+ obnamlib.io.get_block(self.context, "pink")
+ self.failUnless(obnamlib.io.get_block(self.context, "pink"))
class GetObjectTests(IoBase):
def upload_object(self, object_id, object):
self.context.oq.add(object_id, object)
- obnam.io.flush_object_queue(self.context, self.context.oq,
+ obnamlib.io.flush_object_queue(self.context, self.context.oq,
self.context.map, False)
def testGetObject(self):
id = "pink"
- component = obnam.cmp.Component(42, "pretty")
- object = obnam.obj.FilePartObject(id=id)
+ component = obnamlib.cmp.Component(42, "pretty")
+ object = obnamlib.obj.FilePartObject(id=id)
object.add(component)
object = object.encode()
self.upload_object(id, object)
- o = obnam.io.get_object(self.context, id)
+ o = obnamlib.io.get_object(self.context, id)
self.failUnlessEqual(o.get_id(), id)
- self.failUnlessEqual(o.get_kind(), obnam.obj.FILEPART)
+ self.failUnlessEqual(o.get_kind(), obnamlib.obj.FILEPART)
list = o.get_components()
- list = [c for c in list if c.get_kind() not in [obnam.cmp.OBJID,
- obnam.cmp.OBJKIND]]
+ list = [c for c in list if c.get_kind() not in [obnamlib.cmp.OBJID,
+ obnamlib.cmp.OBJKIND]]
self.failUnlessEqual(len(list), 1)
self.failUnlessEqual(list[0].get_kind(), 42)
self.failUnlessEqual(list[0].get_string_value(), "pretty")
def testGetObjectTwice(self):
id = "pink"
- component = obnam.cmp.Component(42, "pretty")
- object = obnam.obj.FileContentsObject(id=id)
+ component = obnamlib.cmp.Component(42, "pretty")
+ object = obnamlib.obj.FileContentsObject(id=id)
object.add(component)
object = object.encode()
self.upload_object(id, object)
- o = obnam.io.get_object(self.context, id)
- o2 = obnam.io.get_object(self.context, id)
+ o = obnamlib.io.get_object(self.context, id)
+ o2 = obnamlib.io.get_object(self.context, id)
self.failUnlessEqual(o, o2)
def testReturnsNoneForNonexistentObject(self):
- self.failUnlessEqual(obnam.io.get_object(self.context, "pink"), None)
+ self.failUnlessEqual(obnamlib.io.get_object(self.context, "pink"), None)
class HostBlock(IoBase):
def testFetchHostBlock(self):
host_id = self.context.config.get("backup", "host-id")
- host = obnam.obj.HostBlockObject(host_id=host_id,
+ host = obnamlib.obj.HostBlockObject(host_id=host_id,
gen_ids=["gen1", "gen2"],
map_block_ids=["map1", "map2"],
contmap_block_ids=["contmap1",
"contmap2"])
host = host.encode()
- be = obnam.backend.init(self.context.config, self.context.cache)
+ be = obnamlib.backend.init(self.context.config, self.context.cache)
- obnam.io.upload_host_block(self.context, host)
- host2 = obnam.io.get_host_block(self.context)
+ obnamlib.io.upload_host_block(self.context, host)
+ host2 = obnamlib.io.get_host_block(self.context)
self.failUnlessEqual(host, host2)
def testFetchNonexistingHostBlockReturnsNone(self):
- self.failUnlessEqual(obnam.io.get_host_block(self.context), None)
+ self.failUnlessEqual(obnamlib.io.get_host_block(self.context), None)
class ObjectQueuingTests(unittest.TestCase):
@@ -219,16 +219,16 @@ class ObjectQueuingTests(unittest.TestCase):
return files
def testEnqueue(self):
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
object_id = "pink"
object = "pretty"
context.config.set("backup", "block-size", "%d" % 128)
- context.cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context.cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
self.failUnlessEqual(self.find_block_files(context.config), [])
- obnam.io.enqueue_object(context, context.oq, context.map,
+ obnamlib.io.enqueue_object(context, context.oq, context.map,
object_id, object, False)
self.failUnlessEqual(self.find_block_files(context.config), [])
@@ -237,7 +237,7 @@ class ObjectQueuingTests(unittest.TestCase):
object_id2 = "pink2"
object2 = "x" * 1024
- obnam.io.enqueue_object(context, context.oq, context.map,
+ obnamlib.io.enqueue_object(context, context.oq, context.map,
object_id2, object2, False)
self.failUnlessEqual(len(self.find_block_files(context.config)), 1)
@@ -250,9 +250,9 @@ class ObjectQueuingTests(unittest.TestCase):
class FileContentsTests(unittest.TestCase):
def setUp(self):
- self.context = obnam.context.Context()
- self.context.cache = obnam.cache.Cache(self.context.config)
- self.context.be = obnam.backend.init(self.context.config,
+ self.context = obnamlib.context.Context()
+ self.context.cache = obnamlib.cache.Cache(self.context.config)
+ self.context.be = obnamlib.backend.init(self.context.config,
self.context.cache)
def tearDown(self):
@@ -264,11 +264,11 @@ class FileContentsTests(unittest.TestCase):
(fd, filename) = tempfile.mkstemp()
os.close(fd)
- id = obnam.io.create_file_contents_object(self.context, filename)
+ id = obnamlib.io.create_file_contents_object(self.context, filename)
self.failIfEqual(id, None)
self.failUnlessEqual(self.context.oq.ids(), [id])
- self.failUnlessEqual(obnam.map.count(self.context.map), 0)
+ self.failUnlessEqual(obnamlib.map.count(self.context.map), 0)
# there's no mapping yet, because the queue is small enough
# that there has been no need to flush it
@@ -279,7 +279,7 @@ class FileContentsTests(unittest.TestCase):
self.context.config.set("backup", "block-size", "%d" % block_size)
filename = "Makefile"
- id = obnam.io.create_file_contents_object(self.context, filename)
+ id = obnamlib.io.create_file_contents_object(self.context, filename)
self.failIfEqual(id, None)
self.failUnlessEqual(self.context.oq.ids(), [id])
@@ -289,14 +289,14 @@ class FileContentsTests(unittest.TestCase):
self.context.config.set("backup", "block-size", "%d" % block_size)
filename = "Makefile"
- id = obnam.io.create_file_contents_object(self.context, filename)
- obnam.io.flush_object_queue(self.context, self.context.oq,
+ id = obnamlib.io.create_file_contents_object(self.context, filename)
+ obnamlib.io.flush_object_queue(self.context, self.context.oq,
self.context.map, False)
- obnam.io.flush_object_queue(self.context, self.context.content_oq,
+ obnamlib.io.flush_object_queue(self.context, self.context.content_oq,
self.context.contmap, False)
(fd, name) = tempfile.mkstemp()
- obnam.io.copy_file_contents(self.context, fd, id)
+ obnamlib.io.copy_file_contents(self.context, fd, id)
os.close(fd)
f = file(name, "r")
@@ -311,8 +311,8 @@ class FileContentsTests(unittest.TestCase):
self.failUnlessEqual(data1, data2)
def testRestoreNonexistingFile(self):
- self.failUnlessRaises(obnam.io.FileContentsObjectMissing,
- obnam.io.copy_file_contents, self.context, None, "pink")
+ self.failUnlessRaises(obnamlib.io.FileContentsObjectMissing,
+ obnamlib.io.copy_file_contents, self.context, None, "pink")
class MetaDataTests(unittest.TestCase):
@@ -322,13 +322,13 @@ class MetaDataTests(unittest.TestCase):
os.close(fd)
st1 = os.stat(name)
- inode = obnam.filelist.create_file_component_from_stat(name, st1,
+ inode = obnamlib.filelist.create_file_component_from_stat(name, st1,
None, None,
None)
os.chmod(name, 0)
- obnam.io.set_inode(name, inode)
+ obnamlib.io.set_inode(name, inode)
st2 = os.stat(name)
@@ -340,26 +340,26 @@ class MetaDataTests(unittest.TestCase):
class ObjectCacheTests(unittest.TestCase):
def setUp(self):
- self.object = obnam.obj.FilePartObject(id="pink")
- self.object2 = obnam.obj.FilePartObject(id="pretty")
- self.object3 = obnam.obj.FilePartObject(id="beautiful")
+ self.object = obnamlib.obj.FilePartObject(id="pink")
+ self.object2 = obnamlib.obj.FilePartObject(id="pretty")
+ self.object3 = obnamlib.obj.FilePartObject(id="beautiful")
def testCreate(self):
- context = obnam.context.Context()
- oc = obnam.io.ObjectCache(context)
+ context = obnamlib.context.Context()
+ oc = obnamlib.io.ObjectCache(context)
self.failUnlessEqual(oc.size(), 0)
self.failUnless(oc.MAX > 0)
def testPut(self):
- context = obnam.context.Context()
- oc = obnam.io.ObjectCache(context)
+ context = obnamlib.context.Context()
+ oc = obnamlib.io.ObjectCache(context)
self.failUnlessEqual(oc.get("pink"), None)
oc.put(self.object)
self.failUnlessEqual(oc.get("pink"), self.object)
def testPutWithOverflow(self):
- context = obnam.context.Context()
- oc = obnam.io.ObjectCache(context)
+ context = obnamlib.context.Context()
+ oc = obnamlib.io.ObjectCache(context)
oc.MAX = 1
oc.put(self.object)
self.failUnlessEqual(oc.size(), 1)
@@ -370,8 +370,8 @@ class ObjectCacheTests(unittest.TestCase):
self.failUnlessEqual(oc.get("pretty"), self.object2)
def testPutWithOverflowPart2(self):
- context = obnam.context.Context()
- oc = obnam.io.ObjectCache(context)
+ context = obnamlib.context.Context()
+ oc = obnamlib.io.ObjectCache(context)
oc.MAX = 2
oc.put(self.object)
@@ -392,63 +392,63 @@ class ReachabilityTests(IoBase):
def testNoDataNoMaps(self):
host_id = self.context.config.get("backup", "host-id")
- host = obnam.obj.HostBlockObject(host_id=host_id).encode()
- obnam.io.upload_host_block(self.context, host)
+ host = obnamlib.obj.HostBlockObject(host_id=host_id).encode()
+ obnamlib.io.upload_host_block(self.context, host)
- list = obnam.io.find_reachable_data_blocks(self.context, host)
+ list = obnamlib.io.find_reachable_data_blocks(self.context, host)
self.failUnlessEqual(list, [])
- list2 = obnam.io.find_map_blocks_in_use(self.context, host, list)
+ list2 = obnamlib.io.find_map_blocks_in_use(self.context, host, list)
self.failUnlessEqual(list2, [])
def testNoDataExtraMaps(self):
- obnam.map.add(self.context.map, "pink", "pretty")
+ obnamlib.map.add(self.context.map, "pink", "pretty")
map_block_id = "box"
- map_block = obnam.map.encode_new_to_block(self.context.map,
+ map_block = obnamlib.map.encode_new_to_block(self.context.map,
map_block_id)
self.context.be.upload_block(map_block_id, map_block, False)
- obnam.map.add(self.context.contmap, "black", "beautiful")
+ obnamlib.map.add(self.context.contmap, "black", "beautiful")
contmap_block_id = "fiddly"
- contmap_block = obnam.map.encode_new_to_block(
+ contmap_block = obnamlib.map.encode_new_to_block(
self.context.contmap, contmap_block_id)
self.context.be.upload_block(contmap_block_id, contmap_block, False)
host_id = self.context.config.get("backup", "host-id")
- host = obnam.obj.HostBlockObject(host_id=host_id,
+ host = obnamlib.obj.HostBlockObject(host_id=host_id,
map_block_ids=[map_block_id],
contmap_block_ids=[contmap_block_id])
host = host.encode()
- obnam.io.upload_host_block(self.context, host)
+ obnamlib.io.upload_host_block(self.context, host)
- list = obnam.io.find_map_blocks_in_use(self.context, host, [])
+ list = obnamlib.io.find_map_blocks_in_use(self.context, host, [])
self.failUnlessEqual(list, [])
def testDataAndMap(self):
- o = obnam.obj.FilePartObject(id="rouge")
- c = obnam.cmp.Component(obnam.cmp.FILECHUNK, "moulin")
+ o = obnamlib.obj.FilePartObject(id="rouge")
+ c = obnamlib.cmp.Component(obnamlib.cmp.FILECHUNK, "moulin")
o.add(c)
encoded_o = o.encode()
block_id = "pink"
- oq = obnam.obj.ObjectQueue()
+ oq = obnamlib.obj.ObjectQueue()
oq.add("rouge", encoded_o)
block = oq.as_block(block_id)
self.context.be.upload_block(block_id, block, False)
- obnam.map.add(self.context.contmap, "rouge", block_id)
+ obnamlib.map.add(self.context.contmap, "rouge", block_id)
map_block_id = "pretty"
- map_block = obnam.map.encode_new_to_block(self.context.contmap,
+ map_block = obnamlib.map.encode_new_to_block(self.context.contmap,
map_block_id)
self.context.be.upload_block(map_block_id, map_block, False)
host_id = self.context.config.get("backup", "host-id")
- host = obnam.obj.HostBlockObject(host_id=host_id,
+ host = obnamlib.obj.HostBlockObject(host_id=host_id,
map_block_ids=[map_block_id])
host = host.encode()
- obnam.io.upload_host_block(self.context, host)
+ obnamlib.io.upload_host_block(self.context, host)
- list = obnam.io.find_map_blocks_in_use(self.context, host,
+ list = obnamlib.io.find_map_blocks_in_use(self.context, host,
[block_id])
self.failUnlessEqual(list, [map_block_id])
@@ -457,8 +457,8 @@ class GarbageCollectionTests(IoBase):
def testFindUnreachableFiles(self):
host_id = self.context.config.get("backup", "host-id")
- host = obnam.obj.HostBlockObject(host_id=host_id).encode()
- obnam.io.upload_host_block(self.context, host)
+ host = obnamlib.obj.HostBlockObject(host_id=host_id).encode()
+ obnamlib.io.upload_host_block(self.context, host)
block_id = self.context.be.generate_block_id()
self.context.be.upload_block(block_id, "pink", False)
@@ -466,14 +466,14 @@ class GarbageCollectionTests(IoBase):
files = self.context.be.list()
self.failUnlessEqual(files, [host_id, block_id])
- obnam.io.collect_garbage(self.context, host)
+ obnamlib.io.collect_garbage(self.context, host)
files = self.context.be.list()
self.failUnlessEqual(files, [host_id])
class ObjectCacheRegressionTest(unittest.TestCase):
- # This test case is for a bug in obnam.io.ObjectCache: with the
+ # This test case is for a bug in obnamlib.io.ObjectCache: with the
# right sequence of operations, the cache can end up in a state where
# the MRU list is too long, but contains two instances of the same
# object ID. When the list is shortened, the first instance of the
@@ -502,13 +502,13 @@ class ObjectCacheRegressionTest(unittest.TestCase):
# list.)
def test(self):
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
context.config.set("backup", "object-cache-size", "3")
- oc = obnam.io.ObjectCache(context)
- a = obnam.obj.FilePartObject(id="a")
- b = obnam.obj.FilePartObject(id="b")
- c = obnam.obj.FilePartObject(id="c")
- d = obnam.obj.FilePartObject(id="d")
+ oc = obnamlib.io.ObjectCache(context)
+ a = obnamlib.obj.FilePartObject(id="a")
+ b = obnamlib.obj.FilePartObject(id="b")
+ c = obnamlib.obj.FilePartObject(id="c")
+ d = obnamlib.obj.FilePartObject(id="d")
oc.put(a)
oc.put(b)
oc.put(c)
@@ -521,14 +521,14 @@ class ObjectCacheRegressionTest(unittest.TestCase):
class LoadMapTests(IoBase):
def test(self):
- map = obnam.map.create()
- obnam.map.add(map, "pink", "pretty")
+ map = obnamlib.map.create()
+ obnamlib.map.add(map, "pink", "pretty")
block_id = self.context.be.generate_block_id()
- block = obnam.map.encode_new_to_block(map, block_id)
+ block = obnamlib.map.encode_new_to_block(map, block_id)
self.context.be.upload_block(block_id, block, False)
- obnam.io.load_maps(self.context, self.context.map, [block_id])
- self.failUnlessEqual(obnam.map.get(self.context.map, "pink"),
+ obnamlib.io.load_maps(self.context, self.context.map, [block_id])
+ self.failUnlessEqual(obnamlib.map.get(self.context.map, "pink"),
"pretty")
- self.failUnlessEqual(obnam.map.get(self.context.map, "black"),
+ self.failUnlessEqual(obnamlib.map.get(self.context.map, "black"),
None)
diff --git a/obnam/log.py b/obnamlib/log.py
index a10f91cd..a10f91cd 100644
--- a/obnam/log.py
+++ b/obnamlib/log.py
diff --git a/obnam/logTests.py b/obnamlib/logTests.py
index b866381d..a9071d4f 100644
--- a/obnam/logTests.py
+++ b/obnamlib/logTests.py
@@ -15,14 +15,14 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.log"""
+"""Unit tests for obnamlib.log"""
import os
import stat
import unittest
-import obnam
+import obnamlib
class LogTests(unittest.TestCase):
@@ -38,10 +38,10 @@ class LogTests(unittest.TestCase):
def testCreateNew(self):
self.failIf(os.path.exists(self.filename))
- config = obnam.config.default_config()
+ config = obnamlib.config.default_config()
config.set("backup", "log-file", self.filename)
- obnam.log.setup(config)
+ obnamlib.log.setup(config)
self.failUnless(os.path.exists(self.filename))
st = os.stat(self.filename)
diff --git a/obnam/map.py b/obnamlib/map.py
index ac8d02ea..16beda68 100644
--- a/obnam/map.py
+++ b/obnamlib/map.py
@@ -19,7 +19,7 @@
import logging
-import obnam.cmp
+import obnamlib
class Mappings:
@@ -79,10 +79,10 @@ def encode_new(mapping):
dict[block_id] = [object_id]
for block_id in dict:
object_ids = dict[block_id]
- object_ids = [obnam.cmp.Component(obnam.cmp.OBJREF, x)
+ object_ids = [obnamlib.cmp.Component(obnamlib.cmp.OBJREF, x)
for x in object_ids]
- block_id = obnam.cmp.Component(obnam.cmp.BLOCKREF, block_id)
- c = obnam.cmp.Component(obnam.cmp.OBJMAP,
+ block_id = obnamlib.cmp.Component(obnamlib.cmp.BLOCKREF, block_id)
+ c = obnamlib.cmp.Component(obnamlib.cmp.OBJMAP,
[block_id] + object_ids)
list.append(c.encode())
return list
@@ -90,14 +90,14 @@ def encode_new(mapping):
def encode_new_to_block(mapping, block_id):
"""Encode new mappings into a block"""
- c = obnam.cmp.Component(obnam.cmp.BLKID, block_id)
+ c = obnamlib.cmp.Component(obnamlib.cmp.BLKID, block_id)
list = encode_new(mapping)
- block = "".join([obnam.obj.BLOCK_COOKIE, c.encode()] + list)
+ block = "".join([obnamlib.obj.BLOCK_COOKIE, c.encode()] + list)
return block
# This function used to use the block and component parsing code in
-# obnam.obj and obnam.cmp, namely the obnam.obj.block_decode function.
+# obnamlib.obj and obnamlib.cmp, namely the obnamlib.obj.block_decode function.
# However, it turned out to be pretty slow, and since we load maps at
# the beginning of pretty much any backup run, the following version was
# written, and measured with benchmarks to run in about a quarter of the
@@ -108,29 +108,29 @@ def decode_block(mapping, block):
"""Decode a block with mappings, add them to mapping object"""
logging.debug("Decoding mapping block")
- if not block.startswith(obnam.obj.BLOCK_COOKIE):
- raise obnam.obj.BlockWithoutCookie(block)
+ if not block.startswith(obnamlib.obj.BLOCK_COOKIE):
+ raise obnamlib.obj.BlockWithoutCookie(block)
- pos = len(obnam.obj.BLOCK_COOKIE)
+ pos = len(obnamlib.obj.BLOCK_COOKIE)
end = len(block)
while pos < end:
- size, pos = obnam.varint.decode(block, pos)
- kind, pos = obnam.varint.decode(block, pos)
+ size, pos = obnamlib.varint.decode(block, pos)
+ kind, pos = obnamlib.varint.decode(block, pos)
- if kind == obnam.cmp.OBJMAP:
+ if kind == obnamlib.cmp.OBJMAP:
pos2 = pos
end2 = pos + size
block_id = None
object_ids = []
while pos2 < end2:
- size2, pos2 = obnam.varint.decode(block, pos2)
- kind2, pos2 = obnam.varint.decode(block, pos2)
+ size2, pos2 = obnamlib.varint.decode(block, pos2)
+ kind2, pos2 = obnamlib.varint.decode(block, pos2)
data2 = block[pos2:pos2+size2]
pos2 += size2
- if kind2 == obnam.cmp.BLOCKREF:
+ if kind2 == obnamlib.cmp.BLOCKREF:
block_id = data2
- elif kind2 == obnam.cmp.OBJREF:
+ elif kind2 == obnamlib.cmp.OBJREF:
object_ids.append(data2)
if object_ids and block_id:
for object_id in object_ids:
diff --git a/obnamlib/mapTests.py b/obnamlib/mapTests.py
new file mode 100644
index 00000000..aac5082a
--- /dev/null
+++ b/obnamlib/mapTests.py
@@ -0,0 +1,113 @@
+# Copyright (C) 2006 Lars Wirzenius <liw@iki.fi>
+#
+# 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 2 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+"""Unit tests for obnamlib.map."""
+
+
+import unittest
+
+
+import obnamlib
+
+
+class ObjectMappingTests(unittest.TestCase):
+
+ def testInvalidBlockRaisesException(self):
+ m = obnamlib.map.create()
+ self.failUnlessRaises(obnamlib.obj.BlockWithoutCookie,
+ obnamlib.map.decode_block, m, "pink")
+
+ def testEmpty(self):
+ m = obnamlib.map.create()
+ self.failUnlessEqual(obnamlib.map.count(m), 0)
+
+ def testGetNonexisting(self):
+ m = obnamlib.map.create()
+ self.failUnlessEqual(obnamlib.map.get(m, "pink"), None)
+
+ def testAddOneMapping(self):
+ m = obnamlib.map.create()
+ obnamlib.map.add(m, "pink", "pretty")
+ self.failUnlessEqual(obnamlib.map.count(m), 1)
+
+ self.failUnlessEqual(obnamlib.map.get(m, "pink"), "pretty")
+
+ def testAddTwoMappings(self):
+ m = obnamlib.map.create()
+ obnamlib.map.add(m, "pink", "pretty")
+ self.failUnlessRaises(AssertionError, obnamlib.map.add,
+ m, "pink", "beautiful")
+
+ def testGetNewMappings(self):
+ m = obnamlib.map.create()
+ self.failUnlessEqual(obnamlib.map.get_new(m), [])
+ obnamlib.map.add(m, "pink", "pretty")
+ self.failUnlessEqual(obnamlib.map.get_new(m), ["pink"])
+ obnamlib.map.reset_new(m)
+ self.failUnlessEqual(obnamlib.map.get_new(m), [])
+ obnamlib.map.add(m, "black", "beautiful")
+ self.failUnlessEqual(obnamlib.map.get_new(m), ["black"])
+
+ def testMappingEncodings(self):
+ # Set up a mapping
+ m = obnamlib.map.create()
+
+ # It's empty; make sure encoding new ones returns an empty list
+ list = obnamlib.map.encode_new(m)
+ self.failUnlessEqual(list, [])
+
+ # Add a mapping
+ obnamlib.map.add(m, "pink", "pretty")
+
+ # Encode the new mapping, make sure that goes well
+ list = obnamlib.map.encode_new(m)
+ self.failUnlessEqual(len(list), 1)
+
+ # Make sure the encoding is correct
+ list2 = obnamlib.cmp.Parser(list[0]).decode_all()
+ self.failUnlessEqual(len(list2), 1)
+ self.failUnlessEqual(list2[0].get_kind(), obnamlib.cmp.OBJMAP)
+
+ list3 = list2[0].get_subcomponents()
+ self.failUnlessEqual(len(list3), 2)
+ self.failUnlessEqual(list3[0].get_kind(), obnamlib.cmp.BLOCKREF)
+ self.failUnlessEqual(list3[0].get_string_value(), "pretty")
+ self.failUnlessEqual(list3[1].get_kind(), obnamlib.cmp.OBJREF)
+ self.failUnlessEqual(list3[1].get_string_value(), "pink")
+
+ # Now try decoding with the official function
+ block = obnamlib.map.encode_new_to_block(m, "black")
+ m2 = obnamlib.map.create()
+ obnamlib.map.decode_block(m2, block)
+ self.failUnlessEqual(obnamlib.map.count(m2), 1)
+ self.failUnlessEqual(obnamlib.map.get(m2, "pink"), "pretty")
+
+ def testMappingEncodingsForTwoInOneBlock(self):
+ m = obnamlib.map.create()
+
+ obnamlib.map.add(m, "pink", "pretty")
+ obnamlib.map.add(m, "black", "pretty")
+
+ list = obnamlib.map.encode_new(m)
+ self.failUnlessEqual(len(list), 1)
+
+ block = obnamlib.map.encode_new_to_block(m, "box")
+ m2 = obnamlib.map.create()
+ obnamlib.map.decode_block(m2, block)
+ self.failUnlessEqual(obnamlib.map.count(m), obnamlib.map.count(m2))
+ self.failUnlessEqual(obnamlib.map.get(m2, "pink"), "pretty")
+ self.failUnlessEqual(obnamlib.map.get(m2, "black"), "pretty")
diff --git a/obnam/obj.py b/obnamlib/obj.py
index 5168900c..f4ee6983 100644
--- a/obnam/obj.py
+++ b/obnamlib/obj.py
@@ -21,8 +21,7 @@ import logging
import uuid
-import obnam.cmp
-import obnam.varint
+import obnamlib
# Magic cookie at the beginning of every block
@@ -96,9 +95,9 @@ class StorageObject(object):
if id:
self.set_id(id)
- if self.first_varint_by_kind(obnam.cmp.OBJKIND) is None and self.kind:
- self.add(obnam.cmp.Component(obnam.cmp.OBJKIND,
- obnam.varint.encode(self.kind)))
+ if self.first_varint_by_kind(obnamlib.cmp.OBJKIND) is None and self.kind:
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.OBJKIND,
+ obnamlib.varint.encode(self.kind)))
def remove(self, kind):
"""Remove all components of a given kind."""
@@ -116,15 +115,15 @@ class StorageObject(object):
def get_kind(self):
"""Return the kind of an object"""
- return self.first_varint_by_kind(obnam.cmp.OBJKIND)
+ return self.first_varint_by_kind(obnamlib.cmp.OBJKIND)
def get_id(self):
"""Return the identifier for an object"""
- return self.first_string_by_kind(obnam.cmp.OBJID)
+ return self.first_string_by_kind(obnamlib.cmp.OBJID)
def set_id(self, id):
"""Set the identifier for this object."""
- self.replace(obnam.cmp.Component(obnam.cmp.OBJID, id))
+ self.replace(obnamlib.cmp.Component(obnamlib.cmp.OBJID, id))
def get_components(self):
"""Return list of all components in an object"""
@@ -174,7 +173,7 @@ class StorageObject(object):
# This function is only used during testing.
def decode(encoded):
"""Decode an object from a string"""
- parser = obnam.cmp.Parser(encoded)
+ parser = obnamlib.cmp.Parser(encoded)
list = parser.decode_all()
return StorageObject(components=list)
@@ -209,21 +208,21 @@ class ObjectQueue:
def as_block(self, blkid):
"""Create a block from an object queue"""
logging.debug("Creating block %s" % blkid)
- blkid = obnam.cmp.Component(obnam.cmp.BLKID, blkid)
- objects = [obnam.cmp.Component(obnam.cmp.OBJECT, x[1])
+ blkid = obnamlib.cmp.Component(obnamlib.cmp.BLKID, blkid)
+ objects = [obnamlib.cmp.Component(obnamlib.cmp.OBJECT, x[1])
for x in self.queue]
return "".join([BLOCK_COOKIE] +
[c.encode() for c in [blkid] + objects])
-class BlockWithoutCookie(obnam.ObnamException):
+class BlockWithoutCookie(obnamlib.ObnamException):
def __init__(self, block):
self._msg = ("Block does not start with cookie: %s" %
" ".join("%02x" % ord(c) for c in block[:32]))
-class EmptyBlock(obnam.ObnamException):
+class EmptyBlock(obnamlib.ObnamException):
def __init__(self):
self._msg = "Block has no components."
@@ -232,7 +231,7 @@ class EmptyBlock(obnam.ObnamException):
def block_decode(block):
"""Return list of decoded components in block, or None on error"""
if block.startswith(BLOCK_COOKIE):
- parser = obnam.cmp.Parser(block, len(BLOCK_COOKIE))
+ parser = obnamlib.cmp.Parser(block, len(BLOCK_COOKIE))
list = parser.decode_all()
if not list:
raise EmptyBlock()
@@ -248,7 +247,7 @@ class SignatureObject(StorageObject):
def __init__(self, components=None, id=None, sigdata=None):
StorageObject.__init__(self, components=components, id=id)
if sigdata:
- c = obnam.cmp.Component(obnam.cmp.SIGDATA, sigdata)
+ c = obnamlib.cmp.Component(obnamlib.cmp.SIGDATA, sigdata)
self.add(c)
@@ -261,13 +260,13 @@ class DeltaObject(StorageObject):
StorageObject.__init__(self, components=components, id=id)
if deltapart_refs:
for deltapart_ref in deltapart_refs:
- c = obnam.cmp.Component(obnam.cmp.DELTAPARTREF, deltapart_ref)
+ c = obnamlib.cmp.Component(obnamlib.cmp.DELTAPARTREF, deltapart_ref)
self.add(c)
if cont_ref:
- c = obnam.cmp.Component(obnam.cmp.CONTREF, cont_ref)
+ c = obnamlib.cmp.Component(obnamlib.cmp.CONTREF, cont_ref)
self.add(c)
elif delta_ref:
- c = obnam.cmp.Component(obnam.cmp.DELTAREF, delta_ref)
+ c = obnamlib.cmp.Component(obnamlib.cmp.DELTAREF, delta_ref)
self.add(c)
@@ -279,34 +278,34 @@ class GenerationObject(StorageObject):
dirrefs=None, filegrouprefs=None, start=None, end=None):
StorageObject.__init__(self, components=components, id=id)
if filelist_id:
- self.add(obnam.cmp.Component(obnam.cmp.FILELISTREF, filelist_id))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.FILELISTREF, filelist_id))
if dirrefs:
for ref in dirrefs:
- self.add(obnam.cmp.Component(obnam.cmp.DIRREF, ref))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.DIRREF, ref))
if filegrouprefs:
for ref in filegrouprefs:
- self.add(obnam.cmp.Component(obnam.cmp.FILEGROUPREF, ref))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.FILEGROUPREF, ref))
if start:
- self.add(obnam.cmp.Component(obnam.cmp.GENSTART,
- obnam.varint.encode(start)))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.GENSTART,
+ obnamlib.varint.encode(start)))
if end:
- self.add(obnam.cmp.Component(obnam.cmp.GENEND,
- obnam.varint.encode(end)))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.GENEND,
+ obnamlib.varint.encode(end)))
def get_filelistref(self):
- return self.first_string_by_kind(obnam.cmp.FILELISTREF)
+ return self.first_string_by_kind(obnamlib.cmp.FILELISTREF)
def get_dirrefs(self):
- return self.find_strings_by_kind(obnam.cmp.DIRREF)
+ return self.find_strings_by_kind(obnamlib.cmp.DIRREF)
def get_filegrouprefs(self):
- return self.find_strings_by_kind(obnam.cmp.FILEGROUPREF)
+ return self.find_strings_by_kind(obnamlib.cmp.FILEGROUPREF)
def get_start_time(self):
- return self.first_varint_by_kind(obnam.cmp.GENSTART)
+ return self.first_varint_by_kind(obnamlib.cmp.GENSTART)
def get_end_time(self):
- return self.first_varint_by_kind(obnam.cmp.GENEND)
+ return self.first_varint_by_kind(obnamlib.cmp.GENEND)
# This is used only by testing.
@@ -315,11 +314,11 @@ def generation_object_decode(gen):
o = decode(gen)
return o.get_id(), \
- o.first_string_by_kind(obnam.cmp.FILELISTREF), \
- o.find_strings_by_kind(obnam.cmp.DIRREF), \
- o.find_strings_by_kind(obnam.cmp.FILEGROUPREF), \
- o.first_varint_by_kind(obnam.cmp.GENSTART), \
- o.first_varint_by_kind(obnam.cmp.GENEND)
+ o.first_string_by_kind(obnamlib.cmp.FILELISTREF), \
+ o.find_strings_by_kind(obnamlib.cmp.DIRREF), \
+ o.find_strings_by_kind(obnamlib.cmp.FILEGROUPREF), \
+ o.first_varint_by_kind(obnamlib.cmp.GENSTART), \
+ o.first_varint_by_kind(obnamlib.cmp.GENEND)
class HostBlockObject(StorageObject):
@@ -331,35 +330,35 @@ class HostBlockObject(StorageObject):
StorageObject.__init__(self, components=components, id=host_id)
if components is None:
- c = obnam.cmp.Component(obnam.cmp.FORMATVERSION, FORMAT_VERSION)
+ c = obnamlib.cmp.Component(obnamlib.cmp.FORMATVERSION, FORMAT_VERSION)
self.add(c)
if gen_ids:
for gen_id in gen_ids:
- c = obnam.cmp.Component(obnam.cmp.GENREF, gen_id)
+ c = obnamlib.cmp.Component(obnamlib.cmp.GENREF, gen_id)
self.add(c)
if map_block_ids:
for map_block_id in map_block_ids:
- c = obnam.cmp.Component(obnam.cmp.MAPREF, map_block_id)
+ c = obnamlib.cmp.Component(obnamlib.cmp.MAPREF, map_block_id)
self.add(c)
if contmap_block_ids:
for map_block_id in contmap_block_ids:
- c = obnam.cmp.Component(obnam.cmp.CONTMAPREF, map_block_id)
+ c = obnamlib.cmp.Component(obnamlib.cmp.CONTMAPREF, map_block_id)
self.add(c)
def get_generation_ids(self):
"""Return IDs of all generations for this host."""
- return self.find_strings_by_kind(obnam.cmp.GENREF)
+ return self.find_strings_by_kind(obnamlib.cmp.GENREF)
def get_map_block_ids(self):
"""Return IDs of all map blocks for this host."""
- return self.find_strings_by_kind(obnam.cmp.MAPREF)
+ return self.find_strings_by_kind(obnamlib.cmp.MAPREF)
def get_contmap_block_ids(self):
"""Return IDs of all map blocks for this host."""
- return self.find_strings_by_kind(obnam.cmp.CONTMAPREF)
+ return self.find_strings_by_kind(obnamlib.cmp.CONTMAPREF)
def encode(self):
oq = ObjectQueue()
@@ -372,17 +371,17 @@ def create_host_from_block(block):
list = block_decode(block)
- host_id = obnam.cmp.first_string_by_kind(list, obnam.cmp.BLKID)
+ host_id = obnamlib.cmp.first_string_by_kind(list, obnamlib.cmp.BLKID)
gen_ids = []
map_ids = []
contmap_ids = []
- objparts = obnam.cmp.find_by_kind(list, obnam.cmp.OBJECT)
+ objparts = obnamlib.cmp.find_by_kind(list, obnamlib.cmp.OBJECT)
for objpart in objparts:
- gen_ids += objpart.find_strings_by_kind(obnam.cmp.GENREF)
- map_ids += objpart.find_strings_by_kind(obnam.cmp.MAPREF)
- contmap_ids += objpart.find_strings_by_kind(obnam.cmp.CONTMAPREF)
+ gen_ids += objpart.find_strings_by_kind(obnamlib.cmp.GENREF)
+ map_ids += objpart.find_strings_by_kind(obnamlib.cmp.MAPREF)
+ contmap_ids += objpart.find_strings_by_kind(obnamlib.cmp.CONTMAPREF)
return HostBlockObject(host_id=host_id, gen_ids=gen_ids,
map_block_ids=map_ids,
@@ -397,30 +396,30 @@ class DirObject(StorageObject):
dirrefs=None, filegrouprefs=None):
StorageObject.__init__(self, components=components, id=id)
if name:
- self.add(obnam.cmp.Component(obnam.cmp.FILENAME, name))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.FILENAME, name))
if stat:
- self.add(obnam.cmp.create_stat_component(stat))
+ self.add(obnamlib.cmp.create_stat_component(stat))
if dirrefs:
for ref in dirrefs:
- self.add(obnam.cmp.Component(obnam.cmp.DIRREF, ref))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.DIRREF, ref))
if filegrouprefs:
for ref in filegrouprefs:
- self.add(obnam.cmp.Component(obnam.cmp.FILEGROUPREF, ref))
+ self.add(obnamlib.cmp.Component(obnamlib.cmp.FILEGROUPREF, ref))
def get_name(self):
- return self.first_by_kind(obnam.cmp.FILENAME).get_string_value()
+ return self.first_by_kind(obnamlib.cmp.FILENAME).get_string_value()
def get_stat(self):
- st = self.first_by_kind(obnam.cmp.STAT)
- return obnam.cmp.parse_stat_component(st)
+ st = self.first_by_kind(obnamlib.cmp.STAT)
+ return obnamlib.cmp.parse_stat_component(st)
def get_dirrefs(self):
return [c.get_string_value()
- for c in self.find_by_kind(obnam.cmp.DIRREF)]
+ for c in self.find_by_kind(obnamlib.cmp.DIRREF)]
def get_filegrouprefs(self):
return [c.get_string_value()
- for c in self.find_by_kind(obnam.cmp.FILEGROUPREF)]
+ for c in self.find_by_kind(obnamlib.cmp.FILEGROUPREF)]
class FileGroupObject(StorageObject):
@@ -428,17 +427,17 @@ class FileGroupObject(StorageObject):
kind = FILEGROUP
def add_file(self, name, stat, contref, sigref, deltaref):
- c = obnam.filelist.create_file_component_from_stat(name, stat,
+ c = obnamlib.filelist.create_file_component_from_stat(name, stat,
contref, sigref,
deltaref)
self.add(c)
def get_files(self):
- return self.find_by_kind(obnam.cmp.FILE)
+ return self.find_by_kind(obnamlib.cmp.FILE)
def get_file(self, name):
for file in self.get_files():
- fname = file.first_string_by_kind(obnam.cmp.FILENAME)
+ fname = file.first_string_by_kind(obnamlib.cmp.FILENAME)
if name == fname:
return file
return None
@@ -447,11 +446,11 @@ class FileGroupObject(StorageObject):
return file.first_string_by_kind(kind)
def get_stat_from_file(self, file):
- c = file.first_by_kind(obnam.cmp.STAT)
- return obnam.cmp.parse_stat_component(c)
+ c = file.first_by_kind(obnamlib.cmp.STAT)
+ return obnamlib.cmp.parse_stat_component(c)
def get_names(self):
- return [self.get_string_from_file(x, obnam.cmp.FILENAME)
+ return [self.get_string_from_file(x, obnamlib.cmp.FILENAME)
for x in self.get_files()]
def get_stat(self, filename):
@@ -459,15 +458,15 @@ class FileGroupObject(StorageObject):
def get_contref(self, filename):
return self.get_string_from_file(self.get_file(filename),
- obnam.cmp.CONTREF)
+ obnamlib.cmp.CONTREF)
def get_sigref(self, filename):
return self.get_string_from_file(self.get_file(filename),
- obnam.cmp.SIGREF)
+ obnamlib.cmp.SIGREF)
def get_deltaref(self, filename):
return self.get_string_from_file(self.get_file(filename),
- obnam.cmp.DELTAREF)
+ obnamlib.cmp.DELTAREF)
class FileListObject(StorageObject):
@@ -490,7 +489,7 @@ class DeltaPartObject(StorageObject):
kind = DELTAPART
-class UnknownStorageObjectKind(obnam.ObnamException):
+class UnknownStorageObjectKind(obnamlib.ObnamException):
def __init__(self, kind):
self._msg = "Unknown storage object kind %s" % kind
@@ -514,7 +513,7 @@ class StorageObjectFactory:
self._classes.append(klass)
def get_object(self, components):
- kind = obnam.cmp.first_varint_by_kind(components, obnam.cmp.OBJKIND)
+ kind = obnamlib.cmp.first_varint_by_kind(components, obnamlib.cmp.OBJKIND)
for klass in self._classes:
if klass.kind == kind:
return klass(components=components)
diff --git a/obnam/objTests.py b/obnamlib/objTests.py
index f6c333be..1facd253 100644
--- a/obnam/objTests.py
+++ b/obnamlib/objTests.py
@@ -15,15 +15,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.obj."""
+"""Unit tests for obnamlib.obj."""
import os
import unittest
-from obnam.obj import *
-import obnam
+from obnamlib.obj import *
+import obnamlib
class ObjectKindNameTests(unittest.TestCase):
@@ -45,22 +45,22 @@ class ObjectKindNameTests(unittest.TestCase):
class ObjectIdTests(unittest.TestCase):
def testHasCorrectProperties(self):
- id = obnam.obj.object_id_new()
+ id = obnamlib.obj.object_id_new()
self.failUnlessEqual(type(id), type(""))
class StorageObjectTests(unittest.TestCase):
components = [
- obnam.cmp.Component(obnam.cmp.OBJID, "pink"),
- obnam.cmp.Component(obnam.cmp.OBJKIND,
- obnam.varint.encode(obnam.obj.HOST)),
- obnam.cmp.Component(0xdeadbeef, "hello"),
- obnam.cmp.Component(0xcafebabe, "world"),
+ obnamlib.cmp.Component(obnamlib.cmp.OBJID, "pink"),
+ obnamlib.cmp.Component(obnamlib.cmp.OBJKIND,
+ obnamlib.varint.encode(obnamlib.obj.HOST)),
+ obnamlib.cmp.Component(0xdeadbeef, "hello"),
+ obnamlib.cmp.Component(0xcafebabe, "world"),
]
def setUp(self):
- self.o = obnam.obj.StorageObject(components=self.components)
+ self.o = obnamlib.obj.StorageObject(components=self.components)
def testInitializesComponentListCorrectlyFromComponents(self):
self.failUnlessEqual(len(self.o.get_components()),
@@ -70,38 +70,38 @@ class StorageObjectTests(unittest.TestCase):
self.failUnlessEqual(self.o.get_id(), "pink")
def testInitalizesKindCorrectlyFromComponents(self):
- self.failUnlessEqual(self.o.get_kind(), obnam.obj.HOST)
+ self.failUnlessEqual(self.o.get_kind(), obnamlib.obj.HOST)
def testInitializesIdCorrectlyFromArguments(self):
- o = obnam.obj.StorageObject(id="pink")
+ o = obnamlib.obj.StorageObject(id="pink")
self.failUnlessEqual(o.get_id(), "pink")
def testEncodesAndDecodesToIdenticalObject(self):
- o = obnam.obj.StorageObject(components=self.components)
+ o = obnamlib.obj.StorageObject(components=self.components)
encoded = o.encode()
- o2 = obnam.obj.decode(encoded)
+ o2 = obnamlib.obj.decode(encoded)
encoded2 = o2.encode()
self.failUnlessEqual(encoded, encoded2)
def testAddsComponentCorrectly(self):
- c = obnam.cmp.Component(obnam.cmp.FILENAME, "pretty")
+ c = obnamlib.cmp.Component(obnamlib.cmp.FILENAME, "pretty")
self.o.add(c)
- self.failUnless(self.o.find_by_kind(obnam.cmp.FILENAME), [c])
+ self.failUnless(self.o.find_by_kind(obnamlib.cmp.FILENAME), [c])
class ObjectQueueTests(unittest.TestCase):
def testCreate(self):
- oq = obnam.obj.ObjectQueue()
+ oq = obnamlib.obj.ObjectQueue()
self.failUnlessEqual(oq.combined_size(), 0)
def testAdd(self):
- oq = obnam.obj.ObjectQueue()
+ oq = obnamlib.obj.ObjectQueue()
oq.add("xx", "abc")
self.failUnlessEqual(oq.combined_size(), 3)
def testSize(self):
- oq = obnam.obj.ObjectQueue()
+ oq = obnamlib.obj.ObjectQueue()
self.failUnless(oq.is_empty())
oq.add("xx", "abc")
self.failUnlessEqual(oq.combined_size(), 3)
@@ -109,7 +109,7 @@ class ObjectQueueTests(unittest.TestCase):
self.failUnlessEqual(oq.combined_size(), 6)
def testClear(self):
- oq = obnam.obj.ObjectQueue()
+ oq = obnamlib.obj.ObjectQueue()
oq_orig = oq
self.failUnless(oq.is_empty())
oq.clear()
@@ -124,7 +124,7 @@ class ObjectQueueTests(unittest.TestCase):
class BlockWithoutCookieTests(unittest.TestCase):
def setUp(self):
- self.e = obnam.obj.BlockWithoutCookie("\x01\x02\x03")
+ self.e = obnamlib.obj.BlockWithoutCookie("\x01\x02\x03")
def testIncludesBlockHexDumpInMessage(self):
self.failUnless("01 02 03" in str(self.e))
@@ -133,36 +133,36 @@ class BlockWithoutCookieTests(unittest.TestCase):
class BlockCreateTests(unittest.TestCase):
def testDecodeInvalidObject(self):
- self.failUnlessRaises(obnam.obj.BlockWithoutCookie,
- obnam.obj.block_decode, "pink")
+ self.failUnlessRaises(obnamlib.obj.BlockWithoutCookie,
+ obnamlib.obj.block_decode, "pink")
def testDecodeEmptyBlock(self):
- self.failUnlessRaises(obnam.obj.EmptyBlock,
- obnam.obj.block_decode, obnam.obj.BLOCK_COOKIE)
+ self.failUnlessRaises(obnamlib.obj.EmptyBlock,
+ obnamlib.obj.block_decode, obnamlib.obj.BLOCK_COOKIE)
def testEmptyObjectQueue(self):
- oq = obnam.obj.ObjectQueue()
+ oq = obnamlib.obj.ObjectQueue()
block = oq.as_block("blkid")
- list = obnam.obj.block_decode(block)
+ list = obnamlib.obj.block_decode(block)
self.failUnlessEqual(
- obnam.cmp.first_string_by_kind(list, obnam.cmp.BLKID),
+ obnamlib.cmp.first_string_by_kind(list, obnamlib.cmp.BLKID),
"blkid")
self.failUnlessEqual(len(list), 1)
self.failUnlessEqual(oq.ids(), [])
def testObjectQueue(self):
- o = obnam.obj.StorageObject(id="pink")
- o.add(obnam.cmp.Component(2, "pretty"))
- oq = obnam.obj.ObjectQueue()
+ o = obnamlib.obj.StorageObject(id="pink")
+ o.add(obnamlib.cmp.Component(2, "pretty"))
+ oq = obnamlib.obj.ObjectQueue()
oq.add("pink", o.encode())
block = oq.as_block("blkid")
- list = obnam.obj.block_decode(block)
+ list = obnamlib.obj.block_decode(block)
self.failUnlessEqual(
- obnam.cmp.first_string_by_kind(list, obnam.cmp.BLKID),
+ obnamlib.cmp.first_string_by_kind(list, obnamlib.cmp.BLKID),
"blkid")
self.failUnlessEqual(len(list), 2)
- o2 = obnam.cmp.first_by_kind(list, obnam.cmp.OBJECT)
+ o2 = obnamlib.cmp.first_by_kind(list, obnamlib.cmp.OBJECT)
self.failUnlessEqual(o.first_string_by_kind(2), "pretty")
self.failUnlessEqual(oq.ids(), ["pink"])
@@ -176,7 +176,7 @@ class GenerationTests(unittest.TestCase):
fg1 = ["fg1", "fg2"]
start1 = 12765
end1 = 37337
- gen = obnam.obj.GenerationObject(id=id1, filelist_id=fl1,
+ gen = obnamlib.obj.GenerationObject(id=id1, filelist_id=fl1,
dirrefs=dirs1, filegrouprefs=fg1,
start=start1, end=end1).encode()
(id2, fl2, dirs2, fg2, start2, end2) = generation_object_decode(gen)
@@ -214,45 +214,45 @@ class GenerationTests(unittest.TestCase):
class OldStorageObjectTests(unittest.TestCase):
def testCreateSignatureObject(self):
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
id = "pink"
- sig = obnam.rsync.compute_signature(context, "Makefile")
- sig_object = obnam.obj.SignatureObject(id=id, sigdata=sig)
+ sig = obnamlib.rsync.compute_signature(context, "Makefile")
+ sig_object = obnamlib.obj.SignatureObject(id=id, sigdata=sig)
encoded = sig_object.encode()
- o = obnam.obj.decode(encoded)
+ o = obnamlib.obj.decode(encoded)
self.failUnlessEqual(o.get_id(), "pink")
- self.failUnlessEqual(o.get_kind(), obnam.obj.SIG)
+ self.failUnlessEqual(o.get_kind(), obnamlib.obj.SIG)
self.failUnlessEqual(len(o.get_components()), 1+2)
- self.failUnlessEqual(o.first_string_by_kind(obnam.cmp.SIGDATA), sig)
+ self.failUnlessEqual(o.first_string_by_kind(obnamlib.cmp.SIGDATA), sig)
def testCreateDeltaObjectWithContRef(self):
id = "pink"
deltapart_ref = "xyzzy"
- do = obnam.obj.DeltaObject(id=id, deltapart_refs=[deltapart_ref],
+ do = obnamlib.obj.DeltaObject(id=id, deltapart_refs=[deltapart_ref],
cont_ref="pretty")
encoded = do.encode()
- o = obnam.obj.decode(encoded)
+ o = obnamlib.obj.decode(encoded)
self.failUnlessEqual(o.get_id(), "pink")
- self.failUnlessEqual(o.get_kind(), obnam.obj.DELTA)
+ self.failUnlessEqual(o.get_kind(), obnamlib.obj.DELTA)
self.failUnlessEqual(len(o.get_components()), 2+2)
- self.failUnlessEqual(o.first_string_by_kind(obnam.cmp.DELTAPARTREF),
+ self.failUnlessEqual(o.first_string_by_kind(obnamlib.cmp.DELTAPARTREF),
deltapart_ref)
- self.failUnlessEqual(o.first_string_by_kind(obnam.cmp.CONTREF),
+ self.failUnlessEqual(o.first_string_by_kind(obnamlib.cmp.CONTREF),
"pretty")
def testCreateDeltaObjectWithDeltaRef(self):
id = "pink"
deltapart_ref = "xyzzy"
- do = obnam.obj.DeltaObject(id=id, deltapart_refs=[deltapart_ref],
+ do = obnamlib.obj.DeltaObject(id=id, deltapart_refs=[deltapart_ref],
delta_ref="pretty")
encoded = do.encode()
- o = obnam.obj.decode(encoded)
+ o = obnamlib.obj.decode(encoded)
self.failUnlessEqual(o.get_id(), "pink")
- self.failUnlessEqual(o.get_kind(), obnam.obj.DELTA)
+ self.failUnlessEqual(o.get_kind(), obnamlib.obj.DELTA)
self.failUnlessEqual(len(o.get_components()), 2+2)
- self.failUnlessEqual(o.first_string_by_kind(obnam.cmp.DELTAPARTREF),
+ self.failUnlessEqual(o.first_string_by_kind(obnamlib.cmp.DELTAPARTREF),
deltapart_ref)
- self.failUnlessEqual(o.first_string_by_kind(obnam.cmp.DELTAREF),
+ self.failUnlessEqual(o.first_string_by_kind(obnamlib.cmp.DELTAREF),
"pretty")
@@ -263,62 +263,62 @@ class HostBlockTests(unittest.TestCase):
gen_ids = ["pretty", "beautiful"]
map_ids = ["black", "box"]
contmap_ids = ["tilu", "lii"]
- host = obnam.obj.HostBlockObject(host_id=host_id, gen_ids=gen_ids,
+ host = obnamlib.obj.HostBlockObject(host_id=host_id, gen_ids=gen_ids,
map_block_ids=map_ids,
contmap_block_ids=contmap_ids)
host = host.encode()
- self.failUnless(host.startswith(obnam.obj.BLOCK_COOKIE))
- host2 = obnam.obj.create_host_from_block(host)
+ self.failUnless(host.startswith(obnamlib.obj.BLOCK_COOKIE))
+ host2 = obnamlib.obj.create_host_from_block(host)
self.failUnlessEqual(host_id, host2.get_id())
self.failUnlessEqual(gen_ids, host2.get_generation_ids())
self.failUnlessEqual(map_ids, host2.get_map_block_ids())
self.failUnlessEqual(contmap_ids, host2.get_contmap_block_ids())
def testFormatVersion(self):
- encoded = obnam.obj.HostBlockObject(host_id="pink", gen_ids=[],
+ encoded = obnamlib.obj.HostBlockObject(host_id="pink", gen_ids=[],
map_block_ids=[],
contmap_block_ids=[]).encode()
- decoded = obnam.obj.block_decode(encoded)
- c = obnam.cmp.first_by_kind(decoded, obnam.cmp.OBJECT)
- id = c.first_string_by_kind(obnam.cmp.OBJID)
+ decoded = obnamlib.obj.block_decode(encoded)
+ c = obnamlib.cmp.first_by_kind(decoded, obnamlib.cmp.OBJECT)
+ id = c.first_string_by_kind(obnamlib.cmp.OBJID)
self.failUnlessEqual(id, "pink")
- ver = c.first_string_by_kind(obnam.cmp.FORMATVERSION)
+ ver = c.first_string_by_kind(obnamlib.cmp.FORMATVERSION)
self.failUnlessEqual(ver, "1")
def make_block(self, gen_ids=None, map_ids=None, contmap_ids=None):
- host = obnam.obj.HostBlockObject(host_id="pink", gen_ids=gen_ids,
+ host = obnamlib.obj.HostBlockObject(host_id="pink", gen_ids=gen_ids,
map_block_ids=map_ids,
contmap_block_ids=contmap_ids)
return host.encode()
def testReturnsEmtpyListForBlockWithNoGenerations(self):
block = self.make_block()
- host = obnam.obj.create_host_from_block(block)
+ host = obnamlib.obj.create_host_from_block(block)
self.failUnlessEqual(host.get_generation_ids(), [])
def testReturnsCorrectListForBlockWithSomeGenerations(self):
block = self.make_block(gen_ids=["pretty", "black"])
- host = obnam.obj.create_host_from_block(block)
+ host = obnamlib.obj.create_host_from_block(block)
self.failUnlessEqual(host.get_generation_ids(), ["pretty", "black"])
def testReturnsEmtpyListForBlockWithNoMaps(self):
block = self.make_block()
- host = obnam.obj.create_host_from_block(block)
+ host = obnamlib.obj.create_host_from_block(block)
self.failUnlessEqual(host.get_map_block_ids(), [])
def testReturnsCorrectListForBlockWithSomeMaps(self):
block = self.make_block(map_ids=["pretty", "black"])
- host = obnam.obj.create_host_from_block(block)
+ host = obnamlib.obj.create_host_from_block(block)
self.failUnlessEqual(host.get_map_block_ids(), ["pretty", "black"])
def testReturnsEmtpyListForBlockWithNoContentMaps(self):
block = self.make_block()
- host = obnam.obj.create_host_from_block(block)
+ host = obnamlib.obj.create_host_from_block(block)
self.failUnlessEqual(host.get_contmap_block_ids(), [])
def testReturnsCorrectListForBlockWithSomeContentMaps(self):
block = self.make_block(contmap_ids=["pretty", "black"])
- host = obnam.obj.create_host_from_block(block)
+ host = obnamlib.obj.create_host_from_block(block)
self.failUnlessEqual(host.get_contmap_block_ids(),
["pretty", "black"])
@@ -326,11 +326,11 @@ class HostBlockTests(unittest.TestCase):
class GetComponentTests(unittest.TestCase):
def setUp(self):
- self.o = obnam.obj.StorageObject([
- obnam.cmp.Component(1, "pink"),
- obnam.cmp.Component(2, "pretty"),
- obnam.cmp.Component(3, "red"),
- obnam.cmp.Component(3, "too"),
+ self.o = obnamlib.obj.StorageObject([
+ obnamlib.cmp.Component(1, "pink"),
+ obnamlib.cmp.Component(2, "pretty"),
+ obnamlib.cmp.Component(3, "red"),
+ obnamlib.cmp.Component(3, "too"),
])
def testGetByKind(self):
@@ -370,16 +370,16 @@ class GetComponentTests(unittest.TestCase):
def testGetVarintsByKind(self):
numbers = range(1024)
- components = [obnam.cmp.Component(0, obnam.varint.encode(i))
+ components = [obnamlib.cmp.Component(0, obnamlib.varint.encode(i))
for i in numbers]
- o = obnam.obj.StorageObject(components=components)
+ o = obnamlib.obj.StorageObject(components=components)
self.failUnlessEqual(o.find_varints_by_kind(0), numbers)
def testGetFirstSVarintByKind(self):
numbers = range(0, 1024, 17)
- components = [obnam.cmp.Component(i, obnam.varint.encode(i))
+ components = [obnamlib.cmp.Component(i, obnamlib.varint.encode(i))
for i in numbers]
- o = obnam.obj.StorageObject(components=components)
+ o = obnamlib.obj.StorageObject(components=components)
for i in numbers:
self.failUnlessEqual(o.first_varint_by_kind(i), i)
self.failUnlessEqual(o.first_varint_by_kind(-1), None)
@@ -453,16 +453,16 @@ class StorageObjectFactoryTests(unittest.TestCase):
def make_component(self, objkind):
list = []
- list.append(obnam.cmp.Component(obnam.cmp.OBJID, "objid"))
- list.append(obnam.cmp.Component(obnam.cmp.OBJKIND,
- obnam.varint.encode(objkind)))
+ list.append(obnamlib.cmp.Component(obnamlib.cmp.OBJID, "objid"))
+ list.append(obnamlib.cmp.Component(obnamlib.cmp.OBJKIND,
+ obnamlib.varint.encode(objkind)))
- if objkind == obnam.obj.GEN:
- list.append(obnam.cmp.Component(obnam.cmp.GENSTART,
- obnam.varint.encode(1)))
- list.append(obnam.cmp.Component(obnam.cmp.GENEND,
- obnam.varint.encode(2)))
+ if objkind == obnamlib.obj.GEN:
+ list.append(obnamlib.cmp.Component(obnamlib.cmp.GENSTART,
+ obnamlib.varint.encode(1)))
+ list.append(obnamlib.cmp.Component(obnamlib.cmp.GENEND,
+ obnamlib.varint.encode(2)))
return list
@@ -470,53 +470,53 @@ class StorageObjectFactoryTests(unittest.TestCase):
return self.factory.get_object(self.make_component(objkind))
def testCreatesFilePartObjectCorrectly(self):
- o = self.make_object(obnam.obj.FILEPART)
- self.failUnlessEqual(type(o), obnam.obj.FilePartObject)
+ o = self.make_object(obnamlib.obj.FILEPART)
+ self.failUnlessEqual(type(o), obnamlib.obj.FilePartObject)
def testCreatesGenerationObjectCorrectly(self):
- o = self.make_object(obnam.obj.GEN)
- self.failUnlessEqual(type(o), obnam.obj.GenerationObject)
+ o = self.make_object(obnamlib.obj.GEN)
+ self.failUnlessEqual(type(o), obnamlib.obj.GenerationObject)
self.failUnlessEqual(o.get_start_time(), 1)
self.failUnlessEqual(o.get_end_time(), 2)
def testCreatesSignatureObjectCorrectly(self):
- o = self.make_object(obnam.obj.SIG)
- self.failUnlessEqual(type(o), obnam.obj.SignatureObject)
+ o = self.make_object(obnamlib.obj.SIG)
+ self.failUnlessEqual(type(o), obnamlib.obj.SignatureObject)
def testCreatesHostBlockObjectCorrectly(self):
- o = self.make_object(obnam.obj.HOST)
- self.failUnlessEqual(type(o), obnam.obj.HostBlockObject)
+ o = self.make_object(obnamlib.obj.HOST)
+ self.failUnlessEqual(type(o), obnamlib.obj.HostBlockObject)
def testCreatesHostBlockObjectCorrectlyFromParsedBlock(self):
- host = obnam.obj.HostBlockObject(host_id="pink")
+ host = obnamlib.obj.HostBlockObject(host_id="pink")
block = host.encode()
- host2 = obnam.obj.create_host_from_block(block)
+ host2 = obnamlib.obj.create_host_from_block(block)
self.failUnlessEqual(host.get_id(), host2.get_id())
def testCreatesFileContentsObjectCorrectly(self):
- o = self.make_object(obnam.obj.FILECONTENTS)
- self.failUnlessEqual(type(o), obnam.obj.FileContentsObject)
+ o = self.make_object(obnamlib.obj.FILECONTENTS)
+ self.failUnlessEqual(type(o), obnamlib.obj.FileContentsObject)
def testCreatesFileListObjectCorrectly(self):
- o = self.make_object(obnam.obj.FILELIST)
- self.failUnlessEqual(type(o), obnam.obj.FileListObject)
+ o = self.make_object(obnamlib.obj.FILELIST)
+ self.failUnlessEqual(type(o), obnamlib.obj.FileListObject)
def testCreatesDeltaObjectCorrectly(self):
- o = self.make_object(obnam.obj.DELTA)
- self.failUnlessEqual(type(o), obnam.obj.DeltaObject)
+ o = self.make_object(obnamlib.obj.DELTA)
+ self.failUnlessEqual(type(o), obnamlib.obj.DeltaObject)
def testCreatesDeltaPartObjectCorrectly(self):
- o = self.make_object(obnam.obj.DELTAPART)
- self.failUnlessEqual(type(o), obnam.obj.DeltaPartObject)
+ o = self.make_object(obnamlib.obj.DELTAPART)
+ self.failUnlessEqual(type(o), obnamlib.obj.DeltaPartObject)
def testCreatesDirObjectCorrectly(self):
- o = self.make_object(obnam.obj.DIR)
- self.failUnlessEqual(type(o), obnam.obj.DirObject)
+ o = self.make_object(obnamlib.obj.DIR)
+ self.failUnlessEqual(type(o), obnamlib.obj.DirObject)
def testCreatesFileGroupObjectCorrectly(self):
- o = self.make_object(obnam.obj.FILEGROUP)
- self.failUnlessEqual(type(o), obnam.obj.FileGroupObject)
+ o = self.make_object(obnamlib.obj.FILEGROUP)
+ self.failUnlessEqual(type(o), obnamlib.obj.FileGroupObject)
def testRaisesExceptionForUnknownObjectKind(self):
- self.failUnlessRaises(obnam.ObnamException,
+ self.failUnlessRaises(obnamlib.ObnamException,
self.make_object, 0xdeadbeef)
diff --git a/obnam/oper.py b/obnamlib/oper.py
index bc4d999c..b2ad82b2 100644
--- a/obnam/oper.py
+++ b/obnamlib/oper.py
@@ -20,7 +20,7 @@
import inspect
-import obnam
+import obnamlib
class Operation:
@@ -65,14 +65,14 @@ class Operation:
"""
-class NoArguments(obnam.ObnamException):
+class NoArguments(obnamlib.ObnamException):
def __init__(self):
self._msg = ("Command line argument list is empty. "
"Need at least the operation name.")
-class OperationNotFound(obnam.ObnamException):
+class OperationNotFound(obnamlib.ObnamException):
def __init__(self, name):
self._msg = "Unknown operation %s" % name
@@ -86,10 +86,10 @@ class OperationFactory:
self._app = app
def find_operations(self):
- """Find operations defined in obnam."""
+ """Find operations defined in obnamlib."""
list = []
- for name in dir(obnam):
- x = getattr(obnam, name)
+ for name in dir(obnamlib):
+ x = getattr(obnamlib, name)
if inspect.isclass(x) and issubclass(x, Operation):
list.append(x)
return list
diff --git a/obnam/operTests.py b/obnamlib/operTests.py
index a2edaf9c..64237b54 100644
--- a/obnam/operTests.py
+++ b/obnamlib/operTests.py
@@ -15,21 +15,21 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Tests for obnam.oper."""
+"""Tests for obnamlib.oper."""
import unittest
-import obnam
+import obnamlib
class OperationTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
self.args = ["pink", "pretty"]
- self.op = obnam.Operation(self.app, self.args)
+ self.op = obnamlib.Operation(self.app, self.args)
def testNameIsNone(self):
self.failUnlessEqual(self.op.name, None)
@@ -44,19 +44,19 @@ class OperationTests(unittest.TestCase):
class OperationFactoryTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.app = obnam.Application(context)
- self.factory = obnam.OperationFactory(self.app)
+ context = obnamlib.context.Context()
+ self.app = obnamlib.Application(context)
+ self.factory = obnamlib.OperationFactory(self.app)
def testFindsOperations(self):
self.failUnless(self.factory.find_operations())
def testRaisesErrorForNoArguments(self):
- self.failUnlessRaises(obnam.ObnamException,
+ self.failUnlessRaises(obnamlib.ObnamException,
self.factory.get_operation, [])
def testRaisesErrorForUnknownArgument(self):
- self.failUnlessRaises(obnam.ObnamException,
+ self.failUnlessRaises(obnamlib.ObnamException,
self.factory.get_operation, ["pink"])
def testFindsBackupOperation(self):
diff --git a/obnam/oper_backup.py b/obnamlib/oper_backup.py
index ec59a6b2..9156cd0c 100644
--- a/obnam/oper_backup.py
+++ b/obnamlib/oper_backup.py
@@ -15,15 +15,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""A backup operation for Obnam."""
+"""A backup operation for obnamlib."""
import logging
-import obnam
+import obnamlib
-class Backup(obnam.Operation):
+class Backup(obnamlib.Operation):
"""Backup files the user has specified."""
@@ -44,7 +44,7 @@ class Backup(obnam.Operation):
app.set_previous_generation(prev_gen)
filelist_id = prev_gen.get_filelistref()
if filelist_id:
- filelist = obnam.filelist.Filelist()
+ filelist = obnamlib.filelist.Filelist()
o = app.get_store().get_object(filelist_id)
filelist.from_object(o)
app.set_prevgen_filelist(filelist)
diff --git a/obnam/oper_forget.py b/obnamlib/oper_forget.py
index 40d98f41..62bf7661 100644
--- a/obnam/oper_forget.py
+++ b/obnamlib/oper_forget.py
@@ -20,10 +20,10 @@
import logging
-import obnam
+import obnamlib
-class Forget(obnam.Operation):
+class Forget(obnamlib.Operation):
"""Forget specified generations."""
@@ -52,11 +52,11 @@ class Forget(obnam.Operation):
logging.debug("forget: Uploading new host block")
host_id = context.config.get("backup", "host-id")
- host2 = obnam.obj.HostBlockObject(host_id=host_id, gen_ids=gen_ids,
+ host2 = obnamlib.obj.HostBlockObject(host_id=host_id, gen_ids=gen_ids,
map_block_ids=map_block_ids,
contmap_block_ids=contmap_block_ids)
block = host2.encode()
- obnam.io.upload_host_block(context, block)
+ obnamlib.io.upload_host_block(context, block)
logging.debug("forget: Forgetting garbage")
- obnam.io.collect_garbage(context, block)
+ obnamlib.io.collect_garbage(context, block)
diff --git a/obnam/oper_generations.py b/obnamlib/oper_generations.py
index 3ca1a293..e5cf51d3 100644
--- a/obnam/oper_generations.py
+++ b/obnamlib/oper_generations.py
@@ -20,10 +20,10 @@
import logging
-import obnam
+import obnamlib
-class ListGenerations(obnam.Operation):
+class ListGenerations(obnamlib.Operation):
"""List generations in the store."""
@@ -40,13 +40,13 @@ class ListGenerations(obnam.Operation):
gen_ids = host.get_generation_ids()
for id in gen_ids:
if gentimes:
- gen = obnam.io.get_object(context, id)
+ gen = obnamlib.io.get_object(context, id)
if not gen:
logging.warning("Can't find info about generation %s" % id)
else:
start = gen.get_start_time()
end = gen.get_end_time()
- print id, obnam.format.timestamp(start), "--", \
- obnam.format.timestamp(end)
+ print id, obnamlib.format.timestamp(start), "--", \
+ obnamlib.format.timestamp(end)
else:
print id
diff --git a/obnam/oper_restore.py b/obnamlib/oper_restore.py
index a4a161e1..361e2302 100644
--- a/obnam/oper_restore.py
+++ b/obnamlib/oper_restore.py
@@ -22,16 +22,16 @@ import logging
import os
import stat
-import obnam
+import obnamlib
-class UnknownGeneration(obnam.ObnamException):
+class UnknownGeneration(obnamlib.ObnamException):
def __init__(self, gen_id):
self._msg = "Can't find generation %s" % gen_id
-class Restore(obnam.Operation):
+class Restore(obnamlib.Operation):
"""Restore specified files (or all) from a specified generation."""
@@ -44,8 +44,8 @@ class Restore(obnam.Operation):
def create_filesystem_object(self, hardlinks, full_pathname, inode):
context = self.get_application().get_context()
logging.debug("Creating filesystem object %s" % full_pathname)
- stat_component = inode.first_by_kind(obnam.cmp.STAT)
- st = obnam.cmp.parse_stat_component(stat_component)
+ stat_component = inode.first_by_kind(obnamlib.cmp.STAT)
+ st = obnamlib.cmp.parse_stat_component(stat_component)
mode = st.st_mode
if st.st_nlink > 1 and not stat.S_ISDIR(mode):
@@ -65,12 +65,12 @@ class Restore(obnam.Operation):
if not os.path.exists(basedir):
os.makedirs(basedir, 0700)
fd = os.open(full_pathname, os.O_WRONLY | os.O_CREAT, 0)
- cont_id = inode.first_string_by_kind(obnam.cmp.CONTREF)
+ cont_id = inode.first_string_by_kind(obnamlib.cmp.CONTREF)
if cont_id:
- obnam.io.copy_file_contents(context, fd, cont_id)
+ obnamlib.io.copy_file_contents(context, fd, cont_id)
else:
- delta_id = inode.first_string_by_kind(obnam.cmp.DELTAREF)
- obnam.io.reconstruct_file_contents(context, fd, delta_id)
+ delta_id = inode.first_string_by_kind(obnamlib.cmp.DELTAREF)
+ obnamlib.io.reconstruct_file_contents(context, fd, delta_id)
os.close(fd)
def restore_requested(self, files, pathname):
@@ -111,15 +111,15 @@ class Restore(obnam.Operation):
logging.debug("Fixing permissions")
list.sort()
for full_pathname, inode in list:
- obnam.io.set_inode(full_pathname, inode)
+ obnamlib.io.set_inode(full_pathname, inode)
def restore_from_filelist(self, target, fl, files):
logging.debug("Restoring files from FILELIST")
list = []
hardlinks = {}
- for c in fl.find_by_kind(obnam.cmp.FILE):
- pathname = c.first_string_by_kind(obnam.cmp.FILENAME)
+ for c in fl.find_by_kind(obnamlib.cmp.FILE):
+ pathname = c.first_string_by_kind(obnamlib.cmp.FILENAME)
if not self.restore_requested(files, pathname):
logging.debug("Restore of %s not requested" % pathname)
@@ -134,7 +134,7 @@ class Restore(obnam.Operation):
def restore_from_filegroups(self, target, hardlinks, list, parent,
filegrouprefs, files):
for ref in filegrouprefs:
- fg = obnam.io.get_object(self.app.get_context(), ref)
+ fg = obnamlib.io.get_object(self.app.get_context(), ref)
if not fg:
logging.warning("Cannot find FILEGROUP object %s" % ref)
else:
@@ -152,7 +152,7 @@ class Restore(obnam.Operation):
def restore_from_dirs(self, target, hardlinks, list, parent, dirrefs,
files):
for ref in dirrefs:
- dir = obnam.io.get_object(self.app.get_context(), ref)
+ dir = obnamlib.io.get_object(self.app.get_context(), ref)
if not dir:
logging.warning("Cannot find DIR object %s" % ref)
else:
@@ -160,10 +160,10 @@ class Restore(obnam.Operation):
if parent:
name = os.path.join(parent, name)
if self.restore_requested(files, name):
- st = dir.first_by_kind(obnam.cmp.STAT)
- st = obnam.cmp.parse_stat_component(st)
+ st = dir.first_by_kind(obnamlib.cmp.STAT)
+ st = obnamlib.cmp.parse_stat_component(st)
file = \
- obnam.filelist.create_file_component_from_stat(
+ obnamlib.filelist.create_file_component_from_stat(
dir.get_name(), st, None, None, None)
full_pathname = self.restore_single_item(hardlinks,
target, name,
@@ -201,7 +201,7 @@ class Restore(obnam.Operation):
app.get_store().load_content_maps()
logging.debug("Getting generation object")
- gen = obnam.io.get_object(context, gen_id)
+ gen = obnamlib.io.get_object(context, gen_id)
if gen is None:
raise UnknownGeneration(gen_id)
@@ -211,7 +211,7 @@ class Restore(obnam.Operation):
fl_id = gen.get_filelistref()
if fl_id:
logging.debug("Getting list of files in generation")
- fl = obnam.io.get_object(context, fl_id)
+ fl = obnamlib.io.get_object(context, fl_id)
if not fl:
logging.warning("Cannot find file list object %s" % fl_id)
else:
diff --git a/obnam/oper_show_generations.py b/obnamlib/oper_show_generations.py
index e22d9510..ffca0698 100644
--- a/obnam/oper_show_generations.py
+++ b/obnamlib/oper_show_generations.py
@@ -22,10 +22,10 @@ import logging
import sys
import time
-import obnam
+import obnamlib
-class ShowGenerations(obnam.Operation):
+class ShowGenerations(obnamlib.Operation):
"""Show contents of generations specified by user."""
@@ -56,12 +56,12 @@ class ShowGenerations(obnam.Operation):
def show_filelist(self, fl):
pretty = True
list = []
- for c in fl.find_by_kind(obnam.cmp.FILE):
- filename = c.first_string_by_kind(obnam.cmp.FILENAME)
+ for c in fl.find_by_kind(obnamlib.cmp.FILE):
+ filename = c.first_string_by_kind(obnamlib.cmp.FILENAME)
if pretty:
- list.append((obnam.format.inode_fields(c), filename))
+ list.append((obnamlib.format.inode_fields(c), filename))
else:
- print " ".join(obnam.format.inode_fields(c)), filename
+ print " ".join(obnamlib.format.inode_fields(c)), filename
if pretty:
widths = []
@@ -82,7 +82,7 @@ class ShowGenerations(obnam.Operation):
print " ", " ".join(cols), filename
def show_dirs_and_filegroups(self, context, gen):
- listing = obnam.format.Listing(context, sys.stdout)
+ listing = obnamlib.format.Listing(context, sys.stdout)
listing.walk(listing.get_objects(gen.get_dirrefs()),
listing.get_objects(gen.get_filegrouprefs()))
@@ -93,7 +93,7 @@ class ShowGenerations(obnam.Operation):
app.get_store().load_maps()
for gen_id in gen_ids:
- gen = obnam.io.get_object(context, gen_id)
+ gen = obnamlib.io.get_object(context, gen_id)
if not gen:
logging.warning("Can't find generation %s" % gen_id)
continue
@@ -102,7 +102,7 @@ class ShowGenerations(obnam.Operation):
fl_id = gen.get_filelistref()
if fl_id:
- fl = obnam.io.get_object(context, fl_id)
+ fl = obnamlib.io.get_object(context, fl_id)
if fl:
self.show_filelist(fl)
else:
diff --git a/obnam/progress.py b/obnamlib/progress.py
index e8cd7ad2..e8cd7ad2 100644
--- a/obnam/progress.py
+++ b/obnamlib/progress.py
diff --git a/obnam/rsync.py b/obnamlib/rsync.py
index cd083677..8deaa562 100644
--- a/obnam/rsync.py
+++ b/obnamlib/rsync.py
@@ -24,22 +24,22 @@ import subprocess
import tempfile
-import obnam
+import obnamlib
-class UnknownCommand(obnam.ObnamException):
+class UnknownCommand(obnamlib.ObnamException):
def __init__(self, argv, errno):
self._msg = "Unknown command (error %d): %s" % (errno, " ".join(argv))
-class CommandFailure(obnam.ObnamException):
+class CommandFailure(obnamlib.ObnamException):
def __init__(self, argv, returncode, stderr):
self._msg = "Command failed: %s\nError code: %d\n%s" % \
(" ".join(argv),
returncode,
- obnam.gpg.indent_string(stderr))
+ obnamlib.gpg.indent_string(stderr))
def run_command(argv, stdin=None, stdout=None, stderr=None):
@@ -95,11 +95,11 @@ def compute_delta(context, signature, filename):
data = p.stdout.read(block_size)
if not data:
break
- id = obnam.obj.object_id_new()
- o = obnam.obj.DeltaPartObject(id=id)
- o.add(obnam.cmp.Component(obnam.cmp.DELTADATA, data))
+ id = obnamlib.obj.object_id_new()
+ o = obnamlib.obj.DeltaPartObject(id=id)
+ o.add(obnamlib.cmp.Component(obnamlib.cmp.DELTADATA, data))
o = o.encode()
- obnam.io.enqueue_object(context, context.content_oq,
+ obnamlib.io.enqueue_object(context, context.content_oq,
context.contmap, id, o, False)
list.append(id)
exit = p.wait()
@@ -121,8 +121,8 @@ def apply_delta(context, basis, deltaparts, new, open=os.open, cmd="rdiff"):
ret = True
for id in deltaparts:
- deltapart = obnam.io.get_object(context, id)
- deltadata = deltapart.first_string_by_kind(obnam.cmp.DELTADATA)
+ deltapart = obnamlib.io.get_object(context, id)
+ deltadata = deltapart.first_string_by_kind(obnamlib.cmp.DELTADATA)
p.stdin.write(deltadata)
stdout_data, stderr_data = p.communicate(input="")
diff --git a/obnam/rsyncTests.py b/obnamlib/rsyncTests.py
index 8209a833..c85c16ef 100644
--- a/obnam/rsyncTests.py
+++ b/obnamlib/rsyncTests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.rsync."""
+"""Unit tests for obnamlib.rsync."""
import os
@@ -24,7 +24,7 @@ import tempfile
import unittest
-import obnam
+import obnamlib
class RsyncTests(unittest.TestCase):
@@ -33,8 +33,8 @@ class RsyncTests(unittest.TestCase):
(fd, empty_file) = tempfile.mkstemp()
os.close(fd)
- context = obnam.context.Context()
- sig = obnam.rsync.compute_signature(context, empty_file)
+ context = obnamlib.context.Context()
+ sig = obnamlib.rsync.compute_signature(context, empty_file)
os.system("rdiff signature %s empty_file.sig.temp" % empty_file)
f = file("empty_file.sig.temp")
data = f.read()
@@ -47,10 +47,10 @@ class RsyncTests(unittest.TestCase):
(fd, empty_file) = tempfile.mkstemp()
os.close(fd)
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
context.config.set("backup", "odirect-pipe", "/notexist")
- self.failUnlessRaises(obnam.rsync.UnknownCommand,
- obnam.rsync.compute_signature,
+ self.failUnlessRaises(obnamlib.rsync.UnknownCommand,
+ obnamlib.rsync.compute_signature,
context, empty_file)
os.remove(empty_file)
@@ -59,10 +59,10 @@ class RsyncTests(unittest.TestCase):
(fd, empty_file) = tempfile.mkstemp()
os.close(fd)
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
context.config.set("backup", "odirect-pipe", "false")
- self.failUnlessRaises(obnam.rsync.CommandFailure,
- obnam.rsync.compute_signature,
+ self.failUnlessRaises(obnamlib.rsync.CommandFailure,
+ obnamlib.rsync.compute_signature,
context, empty_file)
os.remove(empty_file)
@@ -71,10 +71,10 @@ class RsyncTests(unittest.TestCase):
(fd, empty_file) = tempfile.mkstemp()
os.close(fd)
- context = obnam.context.Context()
+ context = obnamlib.context.Context()
context.config.set("backup", "odirect-pipe", "false")
- self.failUnlessRaises(obnam.rsync.CommandFailure,
- obnam.rsync.compute_delta,
+ self.failUnlessRaises(obnamlib.rsync.CommandFailure,
+ obnamlib.rsync.compute_delta,
context, "pink", empty_file)
os.remove(empty_file)
@@ -83,20 +83,20 @@ class RsyncTests(unittest.TestCase):
(fd, empty_file) = tempfile.mkstemp()
os.close(fd)
- context = obnam.context.Context()
- context.cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context = obnamlib.context.Context()
+ context.cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
- sig = obnam.rsync.compute_signature(context, empty_file)
- deltapart_ids = obnam.rsync.compute_delta(context, sig, empty_file)
+ sig = obnamlib.rsync.compute_signature(context, empty_file)
+ deltapart_ids = obnamlib.rsync.compute_delta(context, sig, empty_file)
os.remove(empty_file)
self.failUnlessEqual(len(deltapart_ids), 1)
- obnam.io.flush_all_object_queues(context)
- delta = obnam.io.get_object(context, deltapart_ids[0])
+ obnamlib.io.flush_all_object_queues(context)
+ delta = obnamlib.io.get_object(context, deltapart_ids[0])
self.failIfEqual(delta, None)
- delta = delta.first_string_by_kind(obnam.cmp.DELTADATA)
+ delta = delta.first_string_by_kind(obnamlib.cmp.DELTADATA)
# The hex string below is what rdiff outputs. I've no idea what
# the format is, and the empty delta is expressed differently
@@ -113,19 +113,19 @@ class RsyncTests(unittest.TestCase):
return filename
def testApplyDelta(self):
- context = obnam.context.Context()
- context.cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context = obnamlib.context.Context()
+ context.cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
first = self.create_file("pink")
second = self.create_file("pretty")
- sig = obnam.rsync.compute_signature(context, first)
- deltapart_ids = obnam.rsync.compute_delta(context, sig, second)
- obnam.io.flush_all_object_queues(context)
+ sig = obnamlib.rsync.compute_signature(context, first)
+ deltapart_ids = obnamlib.rsync.compute_delta(context, sig, second)
+ obnamlib.io.flush_all_object_queues(context)
(fd, third) = tempfile.mkstemp()
os.close(fd)
- obnam.rsync.apply_delta(context, first, deltapart_ids, third)
+ obnamlib.rsync.apply_delta(context, first, deltapart_ids, third)
f = file(third, "r")
third_data = f.read()
@@ -140,23 +140,23 @@ class RsyncTests(unittest.TestCase):
def testApplyDeltaWithoutDevNull(self):
self.failUnlessRaises(os.error,
- obnam.rsync.apply_delta,
+ obnamlib.rsync.apply_delta,
None, None, None, None,
open=self.raise_os_error)
def testApplyDeltaRaisesExceptionWhenCommandFails(self):
- context = obnam.context.Context()
- context.cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context = obnamlib.context.Context()
+ context.cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
first = self.create_file("pink")
second = self.create_file("pretty")
- sig = obnam.rsync.compute_signature(context, first)
- deltapart_ids = obnam.rsync.compute_delta(context, sig, second)
- obnam.io.flush_all_object_queues(context)
+ sig = obnamlib.rsync.compute_signature(context, first)
+ deltapart_ids = obnamlib.rsync.compute_delta(context, sig, second)
+ obnamlib.io.flush_all_object_queues(context)
- self.failUnlessRaises(obnam.rsync.CommandFailure,
- obnam.rsync.apply_delta,
+ self.failUnlessRaises(obnamlib.rsync.CommandFailure,
+ obnamlib.rsync.apply_delta,
context, first, deltapart_ids, "/dev/null",
cmd="./badcat")
diff --git a/obnam/store.py b/obnamlib/store.py
index 3ca6ba55..8e503c83 100644
--- a/obnam/store.py
+++ b/obnamlib/store.py
@@ -15,16 +15,16 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Abstraction for storing backup data, for Obnam."""
+"""Abstraction for storing backup data, for obnamlib."""
import logging
import os
-import obnam
+import obnamlib
-class ObjectNotFoundInStore(obnam.exception.ObnamException):
+class ObjectNotFoundInStore(obnamlib.exception.ObnamException):
def __init__(self, id):
self._msg = "Object %s not found in store" % id
@@ -64,12 +64,12 @@ class Store:
"""
if not self._host:
- host_block = obnam.io.get_host_block(self._context)
+ host_block = obnamlib.io.get_host_block(self._context)
if host_block:
- self._host = obnam.obj.create_host_from_block(host_block)
+ self._host = obnamlib.obj.create_host_from_block(host_block)
else:
id = self._context.config.get("backup", "host-id")
- self._host = obnam.obj.HostBlockObject(host_id=id)
+ self._host = obnamlib.obj.HostBlockObject(host_id=id)
return self._host
@@ -77,13 +77,13 @@ class Store:
"""Load non-content map blocks."""
ids = self._host.get_map_block_ids()
logging.info("Decoding %d mapping blocks" % len(ids))
- obnam.io.load_maps(self._context, self._context.map, ids)
+ obnamlib.io.load_maps(self._context, self._context.map, ids)
def load_content_maps(self):
"""Load content map blocks."""
ids = self._host.get_contmap_block_ids()
logging.info("Decoding %d content mapping blocks" % len(ids))
- obnam.io.load_maps(self._context, self._context.contmap, ids)
+ obnamlib.io.load_maps(self._context, self._context.contmap, ids)
def _update_map_helper(self, map):
"""Create new mapping blocks of a given kind, and upload them.
@@ -92,10 +92,10 @@ class Store:
"""
- if obnam.map.get_new(map):
+ if obnamlib.map.get_new(map):
id = self._context.be.generate_block_id()
logging.debug("Creating mapping block %s" % id)
- block = obnam.map.encode_new_to_block(map, id)
+ block = obnamlib.map.encode_new_to_block(map, id)
self._context.be.upload_block(id, block, True)
return [id]
else:
@@ -123,7 +123,7 @@ class Store:
"""
- obnam.io.flush_all_object_queues(self._context)
+ obnamlib.io.flush_all_object_queues(self._context)
logging.info("Creating new mapping blocks")
host = self.get_host_block()
@@ -134,11 +134,11 @@ class Store:
logging.info("Creating new host block")
gen_ids = (host.get_generation_ids() +
[gen.get_id() for gen in new_generations])
- host2 = obnam.obj.HostBlockObject(host_id=host.get_id(),
+ host2 = obnamlib.obj.HostBlockObject(host_id=host.get_id(),
gen_ids=gen_ids,
map_block_ids=map_ids,
contmap_block_ids=contmap_ids)
- obnam.io.upload_host_block(self._context, host2.encode())
+ obnamlib.io.upload_host_block(self._context, host2.encode())
self._host = host2
@@ -151,7 +151,7 @@ class Store:
"""
- obnam.io.enqueue_object(self._context, self._context.oq,
+ obnamlib.io.enqueue_object(self._context, self._context.oq,
self._context.map, object.get_id(),
object.encode(), True)
@@ -172,7 +172,7 @@ class Store:
"""
- object = obnam.io.get_object(self._context, id)
+ object = obnamlib.io.get_object(self._context, id)
if object:
return object
raise ObjectNotFoundInStore(id)
diff --git a/obnam/storeTests.py b/obnamlib/storeTests.py
index 4a2c732f..108ebda5 100644
--- a/obnam/storeTests.py
+++ b/obnamlib/storeTests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for abstraction for storing backup data, for Obnam."""
+"""Unit tests for abstraction for storing backup data, for obnamlib."""
import os
@@ -24,16 +24,16 @@ import socket
import tempfile
import unittest
-import obnam
+import obnamlib
class StoreTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- context.cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
- self.store = obnam.Store(context)
+ context = obnamlib.context.Context()
+ context.cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
+ self.store = obnamlib.Store(context)
def tearDown(self):
shutil.rmtree(self.store._context.config.get("backup", "store"),
@@ -47,18 +47,18 @@ class StoreTests(unittest.TestCase):
def testReturnsAnActualHostBlockAfterFetch(self):
self.store.fetch_host_block()
host = self.store.get_host_block()
- self.failUnless(isinstance(host, obnam.obj.HostBlockObject))
+ self.failUnless(isinstance(host, obnamlib.obj.HostBlockObject))
def testReturnsActualHostBlockWhenOneExists(self):
self.store.fetch_host_block()
self.store.commit_host_block([])
- context = obnam.context.Context()
- context.be = obnam.backend.init(context.config, context.cache)
- store = obnam.Store(context)
+ context = obnamlib.context.Context()
+ context.be = obnamlib.backend.init(context.config, context.cache)
+ store = obnamlib.Store(context)
store.fetch_host_block()
host = store.get_host_block()
- self.failUnless(isinstance(host, obnam.obj.HostBlockObject))
+ self.failUnless(isinstance(host, obnamlib.obj.HostBlockObject))
def testReplacesHostObjectInMemory(self):
self.store.fetch_host_block()
@@ -75,32 +75,32 @@ class StoreTests(unittest.TestCase):
self.failUnlessEqual(host.get_contmap_block_ids(), [])
def testLoadsActualHostBlockWhenOneExists(self):
- context = obnam.context.Context()
- cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context = obnamlib.context.Context()
+ cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
host_id = context.config.get("backup", "host-id")
- temp = obnam.obj.HostBlockObject(host_id=host_id,
+ temp = obnamlib.obj.HostBlockObject(host_id=host_id,
gen_ids=["pink", "pretty"])
- obnam.io.upload_host_block(context, temp.encode())
+ obnamlib.io.upload_host_block(context, temp.encode())
self.store.fetch_host_block()
host = self.store.get_host_block()
self.failUnlessEqual(host.get_generation_ids(), ["pink", "pretty"])
def testGettingNonExistentObjectRaisesException(self):
- self.failUnlessRaises(obnam.exception.ObnamException,
+ self.failUnlessRaises(obnamlib.exception.ObnamException,
self.store.get_object, "pink")
def testAddsObjectToStore(self):
- o = obnam.obj.GenerationObject(id="pink")
+ o = obnamlib.obj.GenerationObject(id="pink")
self.store.fetch_host_block()
self.store.queue_object(o)
self.store.commit_host_block([])
- context2 = obnam.context.Context()
- context2.cache = obnam.cache.Cache(context2.config)
- context2.be = obnam.backend.init(context2.config, context2.cache)
- store2 = obnam.Store(context2)
+ context2 = obnamlib.context.Context()
+ context2.cache = obnamlib.cache.Cache(context2.config)
+ context2.be = obnamlib.backend.init(context2.config, context2.cache)
+ store2 = obnamlib.Store(context2)
store2.fetch_host_block()
store2.load_maps()
self.failUnless(store2.get_object(o.get_id()))
@@ -121,35 +121,35 @@ class StoreMapTests(unittest.TestCase):
def setUp(self):
# First, set up two mappings.
- context = obnam.context.Context()
- context.cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context = obnamlib.context.Context()
+ context.cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
- obnam.map.add(context.map, "pink", "pretty")
- obnam.map.add(context.contmap, "black", "beautiful")
+ obnamlib.map.add(context.map, "pink", "pretty")
+ obnamlib.map.add(context.contmap, "black", "beautiful")
map_id = context.be.generate_block_id()
- map_block = obnam.map.encode_new_to_block(context.map, map_id)
+ map_block = obnamlib.map.encode_new_to_block(context.map, map_id)
context.be.upload_block(map_id, map_block, True)
contmap_id = context.be.generate_block_id()
- contmap_block = obnam.map.encode_new_to_block(context.contmap,
+ contmap_block = obnamlib.map.encode_new_to_block(context.contmap,
contmap_id)
context.be.upload_block(contmap_id, contmap_block, True)
host_id = context.config.get("backup", "host-id")
- host = obnam.obj.HostBlockObject(host_id=host_id,
+ host = obnamlib.obj.HostBlockObject(host_id=host_id,
map_block_ids=[map_id],
contmap_block_ids=[contmap_id])
- obnam.io.upload_host_block(context, host.encode())
+ obnamlib.io.upload_host_block(context, host.encode())
# Then set up the real context and app.
- self.context = obnam.context.Context()
- self.context.cache = obnam.cache.Cache(self.context.config)
- self.context.be = obnam.backend.init(self.context.config,
+ self.context = obnamlib.context.Context()
+ self.context.cache = obnamlib.cache.Cache(self.context.config)
+ self.context.be = obnamlib.backend.init(self.context.config,
self.context.cache)
- self.store = obnam.Store(self.context)
+ self.store = obnamlib.Store(self.context)
self.store.fetch_host_block()
def tearDown(self):
@@ -159,43 +159,43 @@ class StoreMapTests(unittest.TestCase):
ignore_errors=True)
def testHasNoMapsLoadedByDefault(self):
- self.failUnlessEqual(obnam.map.count(self.context.map), 0)
+ self.failUnlessEqual(obnamlib.map.count(self.context.map), 0)
def testHasNoContentMapsLoadedByDefault(self):
- self.failUnlessEqual(obnam.map.count(self.context.contmap), 0)
+ self.failUnlessEqual(obnamlib.map.count(self.context.contmap), 0)
def testLoadsMapsWhenRequested(self):
self.store.load_maps()
- self.failUnlessEqual(obnam.map.count(self.context.map), 1)
+ self.failUnlessEqual(obnamlib.map.count(self.context.map), 1)
def testLoadsContentMapsWhenRequested(self):
self.store.load_content_maps()
- self.failUnlessEqual(obnam.map.count(self.context.contmap), 1)
+ self.failUnlessEqual(obnamlib.map.count(self.context.contmap), 1)
def testAddsNoNewMapsWhenNothingHasChanged(self):
self.store.update_maps()
- self.failUnlessEqual(obnam.map.count(self.context.map), 0)
+ self.failUnlessEqual(obnamlib.map.count(self.context.map), 0)
def testAddsANewMapsWhenSomethingHasChanged(self):
- obnam.map.add(self.context.map, "pink", "pretty")
+ obnamlib.map.add(self.context.map, "pink", "pretty")
self.store.update_maps()
- self.failUnlessEqual(obnam.map.count(self.context.map), 1)
+ self.failUnlessEqual(obnamlib.map.count(self.context.map), 1)
def testAddsNoNewContentMapsWhenNothingHasChanged(self):
self.store.update_content_maps()
- self.failUnlessEqual(obnam.map.count(self.context.contmap), 0)
+ self.failUnlessEqual(obnamlib.map.count(self.context.contmap), 0)
def testAddsANewContentMapsWhenSomethingHasChanged(self):
- obnam.map.add(self.context.contmap, "pink", "pretty")
+ obnamlib.map.add(self.context.contmap, "pink", "pretty")
self.store.update_content_maps()
- self.failUnlessEqual(obnam.map.count(self.context.contmap), 1)
+ self.failUnlessEqual(obnamlib.map.count(self.context.contmap), 1)
class StorePathnameParserTests(unittest.TestCase):
def setUp(self):
- context = obnam.context.Context()
- self.store = obnam.Store(context)
+ context = obnamlib.context.Context()
+ self.store = obnamlib.Store(context)
def testReturnsRootForRoot(self):
self.failUnlessEqual(self.store.parse_pathname("/"), ["/"])
@@ -230,20 +230,20 @@ class StoreLookupTests(unittest.TestCase):
return dirname
def create_context(self):
- context = obnam.context.Context()
- context.cache = obnam.cache.Cache(context.config)
- context.be = obnam.backend.init(context.config, context.cache)
+ context = obnamlib.context.Context()
+ context.cache = obnamlib.cache.Cache(context.config)
+ context.be = obnamlib.backend.init(context.config, context.cache)
return context
def setUp(self):
self.datadir = self.create_data_dir()
- app = obnam.Application(self.create_context())
+ app = obnamlib.Application(self.create_context())
app.load_host()
gen = app.backup([self.datadir])
app.get_store().commit_host_block([gen])
- self.store = obnam.Store(self.create_context())
+ self.store = obnamlib.Store(self.create_context())
self.store.fetch_host_block()
self.store.load_maps()
gen_ids = self.store.get_host_block().get_generation_ids()
@@ -287,7 +287,7 @@ class StoreLookupTests(unittest.TestCase):
self.failUnlessEqual(file, None)
def filename(self, file):
- return file.first_string_by_kind(obnam.cmp.FILENAME)
+ return file.first_string_by_kind(obnamlib.cmp.FILENAME)
def testFindsFileInRootDirectory(self):
pathname = os.path.join(self.datadir, "file1")
diff --git a/obnam/utils.py b/obnamlib/utils.py
index f6747867..f6747867 100644
--- a/obnam/utils.py
+++ b/obnamlib/utils.py
diff --git a/obnam/varint.py b/obnamlib/varint.py
index 3174b1da..3174b1da 100644
--- a/obnam/varint.py
+++ b/obnamlib/varint.py
diff --git a/obnam/varintTests.py b/obnamlib/varintTests.py
index 79d68f9c..c5964fe3 100644
--- a/obnam/varintTests.py
+++ b/obnamlib/varintTests.py
@@ -15,13 +15,13 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.varint."""
+"""Unit tests for obnamlib.varint."""
import unittest
-import obnam.varint
+import obnamlib
class VarintEncodeDecodeTests(unittest.TestCase):
@@ -29,13 +29,13 @@ class VarintEncodeDecodeTests(unittest.TestCase):
def test(self):
numbers = (0, 1, 127, 128, 0xff00)
for i in numbers:
- str = obnam.varint.encode(i)
- (i2, pos) = obnam.varint.decode(str, 0)
+ str = obnamlib.varint.encode(i)
+ (i2, pos) = obnamlib.varint.decode(str, 0)
self.failUnlessEqual(i, i2)
self.failUnlessEqual(pos, len(str))
def testError(self):
str = "asdf"
- n, pos = obnam.varint.decode(str, 0)
+ n, pos = obnamlib.varint.decode(str, 0)
self.failUnlessEqual(n, -1)
self.failUnlessEqual(pos, 0)
diff --git a/obnam/walk.py b/obnamlib/walk.py
index 4a2d0e23..4a2d0e23 100644
--- a/obnam/walk.py
+++ b/obnamlib/walk.py
diff --git a/obnam/walk_tests.py b/obnamlib/walk_tests.py
index 747c1b97..a0759305 100644
--- a/obnam/walk_tests.py
+++ b/obnamlib/walk_tests.py
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Unit tests for obnam.walk."""
+"""Unit tests for obnamlib.walk."""
import os
@@ -23,7 +23,7 @@ import shutil
import tempfile
import unittest
-import obnam
+import obnamlib
class DepthFirstTests(unittest.TestCase):
@@ -40,7 +40,7 @@ class DepthFirstTests(unittest.TestCase):
shutil.rmtree(self.root)
def testFindsAllDirs(self):
- dirs = [x[0] for x in obnam.walk.depth_first(self.root)]
+ dirs = [x[0] for x in obnamlib.walk.depth_first(self.root)]
self.failUnlessEqual(sorted(dirs), sorted(self.dirs))
def prune(self, dirname, dirnames, filenames):
@@ -52,5 +52,5 @@ class DepthFirstTests(unittest.TestCase):
for x in self.dirs
if not x.endswith("/foo") and not "/foo/" in x]
dirs = [x[0]
- for x in obnam.walk.depth_first(self.root, prune=self.prune)]
+ for x in obnamlib.walk.depth_first(self.root, prune=self.prune)]
self.failUnlessEqual(sorted(dirs), sorted(correct))