summaryrefslogtreecommitdiff
path: root/obnam
diff options
context:
space:
mode:
authorLars Wirzenius <liw@gytha>2008-03-23 00:33:21 +0200
committerLars Wirzenius <liw@gytha>2008-03-23 00:33:21 +0200
commitf6e1f554ccf79754c5e305083f34cc0afd06be08 (patch)
tree8eb09a661e4bd72b5e0a4045dc26ebaee73a2f99 /obnam
parentbf615d5dc6fa5984ce3bc55639da7e8517f61b63 (diff)
downloadobnam-f6e1f554ccf79754c5e305083f34cc0afd06be08.tar.gz
Add mapping updating into Application.
Diffstat (limited to 'obnam')
-rw-r--r--obnam/app.py20
-rw-r--r--obnam/appTests.py18
2 files changed, 38 insertions, 0 deletions
diff --git a/obnam/app.py b/obnam/app.py
index 658956c1..677380b5 100644
--- a/obnam/app.py
+++ b/obnam/app.py
@@ -287,3 +287,23 @@ class Application:
dirrefs=dirrefs)
self.enqueue([gen])
return gen
+
+ def _update_map_helper(self, map):
+ """Create new mapping blocks of a given kind, and upload them."""
+ if obnam.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)
+ self._context.be.upload_block(id, block, True)
+ else:
+ logging.debug("No new mappings, no new mapping block")
+
+ def update_maps(self):
+ """Create new object mapping blocks and upload them."""
+ logging.debug("Creating new mapping block for normal mappings")
+ self._update_map_helper(self._context.map)
+
+ def update_content_maps(self):
+ """Create new content object mapping blocks and upload them."""
+ logging.debug("Creating new mapping block for content mappings")
+ self._update_map_helper(self._context.contmap)
diff --git a/obnam/appTests.py b/obnam/appTests.py
index d2ec391e..bf9853cb 100644
--- a/obnam/appTests.py
+++ b/obnam/appTests.py
@@ -392,3 +392,21 @@ class ApplicationMapTests(unittest.TestCase):
def testLoadsContentMapsWhenRequested(self):
self.app.load_content_maps()
self.failUnlessEqual(obnam.map.count(self.context.contmap), 1)
+
+ def testAddsNoNewMapsWhenNothingHasChanged(self):
+ self.app.update_maps()
+ self.failUnlessEqual(obnam.map.count(self.context.map), 0)
+
+ def testAddsANewMapsWhenSomethingHasChanged(self):
+ obnam.map.add(self.context.map, "pink", "pretty")
+ self.app.update_maps()
+ self.failUnlessEqual(obnam.map.count(self.context.map), 1)
+
+ def testAddsNoNewContentMapsWhenNothingHasChanged(self):
+ self.app.update_content_maps()
+ self.failUnlessEqual(obnam.map.count(self.context.contmap), 0)
+
+ def testAddsANewContentMapsWhenSomethingHasChanged(self):
+ obnam.map.add(self.context.contmap, "pink", "pretty")
+ self.app.update_content_maps()
+ self.failUnlessEqual(obnam.map.count(self.context.contmap), 1)