diff options
-rw-r--r-- | obnamlib/plugins/restore_plugin.py | 26 | ||||
-rw-r--r-- | obnamlib/plugins/verify_plugin.py | 27 | ||||
-rw-r--r-- | obnamlib/repo_interface.py | 24 | ||||
-rw-r--r-- | test-gpghome/random_seed | bin | 600 -> 600 bytes |
4 files changed, 26 insertions, 51 deletions
diff --git a/obnamlib/plugins/restore_plugin.py b/obnamlib/plugins/restore_plugin.py index dffa0f19..bc8b42d3 100644 --- a/obnamlib/plugins/restore_plugin.py +++ b/obnamlib/plugins/restore_plugin.py @@ -150,32 +150,8 @@ class RestorePlugin(obnamlib.ObnamPlugin): if self.errors: raise obnamlib.Error('There were errors when restoring') - def repo_walk(self, gen_id, dirname, depth_first=False): - '''Like os.walk, but for a generation. - - This is a generator. Each return value is a tuple consisting - of a pathname and its corresponding metadata. Directories are - recursed into. - - ''' - - arg = os.path.normpath(dirname) - mode = self.repo.get_file_key( - gen_id, dirname, obnamlib.REPO_FILE_MODE) - if stat.S_ISDIR(mode): - if not depth_first: - yield dirname - kidpaths = self.repo.get_file_children(gen_id, dirname) - for kp in kidpaths: - for x in self.repo_walk(gen_id, kp, depth_first=depth_first): - yield x - if depth_first: - yield arg - else: - yield arg - def restore_something(self, gen, root): - for pathname in self.repo_walk(gen, root, depth_first=True): + for pathname in self.repo.walk_generation(gen, root): self.file_count += 1 self.app.ts['current'] = pathname self.restore_safely(gen, pathname) diff --git a/obnamlib/plugins/verify_plugin.py b/obnamlib/plugins/verify_plugin.py index a07dbe3d..5a2c4295 100644 --- a/obnamlib/plugins/verify_plugin.py +++ b/obnamlib/plugins/verify_plugin.py @@ -210,30 +210,5 @@ class VerifyPlugin(obnamlib.ObnamPlugin): for arg in args: scheme, netloc, path, query, fragment = urlparse.urlsplit(arg) arg = os.path.normpath(path) - for x in self.repo_walk(gen_id, arg): + for x in self.repo.walk_generation(gen_id, arg): yield x - - def repo_walk(self, gen_id, dirname, depth_first=False): - # FIXME: this is duplicate code. - '''Like os.walk, but for a generation. - - This is a generator. Each return value is a tuple consisting - of a pathname and its corresponding metadata. Directories are - recursed into. - - ''' - - arg = os.path.normpath(dirname) - mode = self.repo.get_file_key( - gen_id, dirname, obnamlib.REPO_FILE_MODE) - if stat.S_ISDIR(mode): - if not depth_first: - yield dirname - kidpaths = self.repo.get_file_children(gen_id, dirname) - for kp in kidpaths: - for x in self.repo_walk(gen_id, kp, depth_first=depth_first): - yield x - if depth_first: - yield arg - else: - yield arg diff --git a/obnamlib/repo_interface.py b/obnamlib/repo_interface.py index e4a3fe14..bf77addd 100644 --- a/obnamlib/repo_interface.py +++ b/obnamlib/repo_interface.py @@ -18,6 +18,8 @@ # =*= License: GPL-3+ =*= +import os +import stat import unittest import obnamlib @@ -605,6 +607,28 @@ class RepositoryInterface(object): ''' raise NotImplementedError() + def walk_generation(self, gen_id, dirname): # pragma: no cover + '''Like os.walk, but for a generation. + + This is a generator. Each return value is a pathname. + Directories are recursed into. If depth_first is set to + Children of a directory are returned before the directory + itself. + + Sub-classes do not need to define this method; the base + class provides a generic implementation. + + ''' + + arg = os.path.normpath(dirname) + mode = self.get_file_key(gen_id, dirname, obnamlib.REPO_FILE_MODE) + if stat.S_ISDIR(mode): + kidpaths = self.get_file_children(gen_id, dirname) + for kp in kidpaths: + for x in self.walk_generation(gen_id, kp): + yield x + yield arg + # Chunks. def put_chunk_content(self, data): diff --git a/test-gpghome/random_seed b/test-gpghome/random_seed Binary files differindex b4fb175b..ad7044f3 100644 --- a/test-gpghome/random_seed +++ b/test-gpghome/random_seed |