From 8f47d014bd8946acc67e6fd291a91028ba6c6a08 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Thu, 6 Nov 2014 16:41:23 +0000 Subject: Remove one place where we pass the Application instance around The MorphologyFactory class only uses the status() function of the morphlib.Application instance that it gets passed. So make it require only a status callback. --- morphlib/app.py | 4 ++-- morphlib/morphologyfactory.py | 9 ++++----- morphlib/morphologyfactory_tests.py | 8 +------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/morphlib/app.py b/morphlib/app.py index c3c9c970..c4d45aae 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -350,8 +350,8 @@ class Morph(cliapp.Application): system_filenames, lrc, rrc, update=True, visit=lambda rn, rf, fn, arf, m: None, definitions_original_ref=None): - morph_factory = morphlib.morphologyfactory.MorphologyFactory(lrc, rrc, - self) + morph_factory = morphlib.morphologyfactory.MorphologyFactory( + lrc, rrc, self.status) definitions_queue = collections.deque(system_filenames) chunk_in_definitions_repo_queue = [] chunk_in_source_repo_queue = [] diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index b0a0528d..dad7238e 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -41,14 +41,13 @@ class MorphologyFactory(object): '''A way of creating morphologies which will provide a default''' - def __init__(self, local_repo_cache, remote_repo_cache=None, app=None): + def __init__(self, local_repo_cache, remote_repo_cache=None, + status_cb=None): self._lrc = local_repo_cache self._rrc = remote_repo_cache - self._app = app - def status(self, *args, **kwargs): # pragma: no cover - if self._app is not None: - self._app.status(*args, **kwargs) + null_status_function = lambda **kwargs: None + self.status = status_cb or null_status_function def get_morphology(self, reponame, sha1, filename): morph_name = os.path.splitext(os.path.basename(filename))[0] diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index 52d5f598..41d06480 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -144,19 +144,13 @@ class FakeLocalRepoCache(object): return self.lr -class FakeApp(object): - - def status(self, **kwargs): - pass - - class MorphologyFactoryTests(unittest.TestCase): def setUp(self): self.lr = FakeLocalRepo() self.lrc = FakeLocalRepoCache(self.lr) self.rrc = FakeRemoteRepoCache() - self.mf = MorphologyFactory(self.lrc, self.rrc, app=FakeApp()) + self.mf = MorphologyFactory(self.lrc, self.rrc) self.lmf = MorphologyFactory(self.lrc, None) def nolocalfile(self, *args): -- cgit v1.2.1