summaryrefslogtreecommitdiff
path: root/obnam
diff options
context:
space:
mode:
authorLars Wirzenius <liw@gytha>2008-04-13 20:18:34 +0300
committerLars Wirzenius <liw@gytha>2008-04-13 20:18:34 +0300
commitcfa21e4eb9d746a5e140bf0b2bfc9452abe33a15 (patch)
tree43d101155e2931b13ad585431b681ad8971ad3a2 /obnam
parent928a84061813e13440af5e5be3fec18429d0f489 (diff)
downloadobnam-cfa21e4eb9d746a5e140bf0b2bfc9452abe33a15.tar.gz
Make Application use Store for stuff that Store should do.
Diffstat (limited to 'obnam')
-rw-r--r--obnam/app.py72
-rw-r--r--obnam/appTests.py14
-rw-r--r--obnam/store.py5
-rw-r--r--obnam/storeTests.py10
4 files changed, 25 insertions, 76 deletions
diff --git a/obnam/app.py b/obnam/app.py
index f1b5a416..5f21dc81 100644
--- a/obnam/app.py
+++ b/obnam/app.py
@@ -41,7 +41,7 @@ class Application:
self._exclusion_strings = []
self._exclusion_regexps = []
self._filelist = None
- self._host = None
+ self._store = obnam.Store(self._context)
# When we traverse the file system tree while making a backup,
# we process children before the parent. This is necessary for
@@ -60,32 +60,26 @@ class Application:
"""Get the context for the backup application."""
return self._context
+ def get_store(self):
+ """Get the Store for the backup application."""
+ return self._store
+
def get_host(self):
"""Return currently active host object, or None if none is active."""
- return self._host
+ return self._store.get_host_block()
def load_host(self):
"""Load the host block into memory."""
- if not self._host:
- host_block = obnam.io.get_host_block(self._context)
- if host_block:
- self._host = obnam.obj.create_host_from_block(host_block)
- else:
- id = self._context.config.get("backup", "host-id")
- self._host = obnam.obj.HostBlockObject(host_id=id)
- return self._host
+ self.get_store().fetch_host_block()
+ return self.get_host()
def load_maps(self):
"""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)
+ self.get_store().load_maps()
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)
+ self.get_store().load_content_maps()
def get_exclusion_regexps(self):
"""Return list of regexp to exclude things from backup."""
@@ -168,9 +162,7 @@ class Application:
def enqueue(self, objs):
"""Push objects to the object queue."""
for obj in objs:
- obnam.io.enqueue_object(self._context, self._context.oq,
- self._context.map, obj.get_id(),
- obj.encode(), True)
+ self.get_store().queue_object(obj)
def compute_signature(self, filename):
"""Compute rsync signature for a filename.
@@ -303,32 +295,13 @@ class Application:
self.enqueue([gen])
return gen
- def _update_map_helper(self, map):
- """Create new mapping blocks of a given kind, and upload them.
-
- Return list of block ids for the new blocks.
-
- """
-
- 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)
- return [id]
- else:
- logging.debug("No new mappings, no new mapping block")
- return []
-
def update_maps(self):
"""Create new object mapping blocks and upload them."""
- logging.debug("Creating new mapping block for normal mappings")
- return self._update_map_helper(self._context.map)
+ self.get_store().update_maps()
def update_content_maps(self):
"""Create new content object mapping blocks and upload them."""
- logging.debug("Creating new mapping block for content mappings")
- return self._update_map_helper(self._context.contmap)
+ self.get_store().update_content_maps()
def finish(self, new_gens):
"""Finish a backup operation by updating maps and uploading host block.
@@ -338,22 +311,5 @@ class Application:
that requires the host block, you have to call load_host again.
"""
-
- obnam.io.flush_all_object_queues(self._context)
-
- logging.info("Creating new mapping blocks")
- host = self.get_host()
- map_ids = host.get_map_block_ids() + self.update_maps()
- contmap_ids = (host.get_contmap_block_ids() +
- self.update_content_maps())
-
- logging.info("Creating new host block")
- gen_ids = (host.get_generation_ids() +
- [gen.get_id() for gen in new_gens])
- host2 = obnam.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())
- self._host = None
+ self.get_store().commit_host_block(new_gens)
diff --git a/obnam/appTests.py b/obnam/appTests.py
index 24a982fb..91deb2a4 100644
--- a/obnam/appTests.py
+++ b/obnam/appTests.py
@@ -419,17 +419,3 @@ class ApplicationMapTests(unittest.TestCase):
obnam.map.add(self.context.contmap, "pink", "pretty")
self.app.update_content_maps()
self.failUnlessEqual(obnam.map.count(self.context.contmap), 1)
-
-
-class ApplicationFinishTests(unittest.TestCase):
-
- def testRemovesHostObject(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.cache)
- self.app = obnam.Application(self.context)
- self.app.load_host()
-
- self.app.finish([])
- self.failUnlessEqual(self.app.get_host(), None)
diff --git a/obnam/store.py b/obnam/store.py
index f414d1a5..fe63b031 100644
--- a/obnam/store.py
+++ b/obnam/store.py
@@ -101,7 +101,7 @@ class Store:
logging.debug("Creating new mapping block for content mappings")
return self._update_map_helper(self._context.contmap)
- def commit_host_block(self):
+ def commit_host_block(self, new_generations):
"""Commit the current host block to the store.
If no host block exists, create one. If one already exists,
@@ -121,7 +121,8 @@ class Store:
self.update_content_maps())
logging.info("Creating new host block")
- gen_ids = host.get_generation_ids()
+ gen_ids = (host.get_generation_ids() +
+ [gen.get_id() for gen in new_generations])
host2 = obnam.obj.HostBlockObject(host_id=host.get_id(),
gen_ids=gen_ids,
map_block_ids=map_ids,
diff --git a/obnam/storeTests.py b/obnam/storeTests.py
index 70d7aa6f..ccc1b25c 100644
--- a/obnam/storeTests.py
+++ b/obnam/storeTests.py
@@ -49,7 +49,7 @@ class StoreTests(unittest.TestCase):
def testReturnsActualHostBlockWhenOneExists(self):
self.store.fetch_host_block()
- self.store.commit_host_block()
+ self.store.commit_host_block([])
context = obnam.context.Context()
context.be = obnam.backend.init(context.config, context.cache)
@@ -58,6 +58,12 @@ class StoreTests(unittest.TestCase):
host = store.get_host_block()
self.failUnless(isinstance(host, obnam.obj.HostBlockObject))
+ def testReplacesHostObjectInMemory(self):
+ self.store.fetch_host_block()
+ host = self.store.get_host_block()
+ self.store.commit_host_block([])
+ self.failIfEqual(self.store.get_host_block(), host)
+
def testCreatesNewHostBlockWhenNoneExists(self):
self.store.fetch_host_block()
host = self.store.get_host_block()
@@ -87,7 +93,7 @@ class StoreTests(unittest.TestCase):
o = obnam.obj.GenerationObject(id="pink")
self.store.fetch_host_block()
self.store.queue_object(o)
- self.store.commit_host_block()
+ self.store.commit_host_block([])
context2 = obnam.context.Context()
context2.cache = obnam.cache.Cache(context2.config)