diff options
author | Lars Wirzenius <liw@gytha> | 2008-03-23 00:33:21 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@gytha> | 2008-03-23 00:33:21 +0200 |
commit | f6e1f554ccf79754c5e305083f34cc0afd06be08 (patch) | |
tree | 8eb09a661e4bd72b5e0a4045dc26ebaee73a2f99 /obnam | |
parent | bf615d5dc6fa5984ce3bc55639da7e8517f61b63 (diff) | |
download | obnam-f6e1f554ccf79754c5e305083f34cc0afd06be08.tar.gz |
Add mapping updating into Application.
Diffstat (limited to 'obnam')
-rw-r--r-- | obnam/app.py | 20 | ||||
-rw-r--r-- | obnam/appTests.py | 18 |
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) |