summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-11-22 13:44:15 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-11-29 16:11:32 +0000
commitb38e47f413c6651c8953d2bebd99ae0bb80c07f9 (patch)
tree4cf05a84653e4f4ee1f42a983e3f92d80a086425
parent21d7299e927696c2536e2170f77eef9b25f80172 (diff)
downloadmorph-b38e47f413c6651c8953d2bebd99ae0bb80c07f9.tar.gz
sysbranchdir: Move load_all_morphologies helper here
This was previously a private method of the branch and merge plugin, but it's useful to other plugins, so has been moved to the SystemBranchDirectory class, where everything else can get to it. It has an unpleasant amount of coupling to other classes, but in a *good* object oriented design it would either be a tiny module on its own, or not exist and leave all its users to re-implement the same logic multiple ways, so we've opted for a less clean, but more useful design. It is left un-covered by the unit tests, since it requires a great deal of instrumentation to test, at which point it may be best to leave it to integration tests.
-rw-r--r--morphlib/plugins/branch_and_merge_new_plugin.py11
-rw-r--r--morphlib/sysbranchdir.py14
-rw-r--r--morphlib/util.py1
3 files changed, 16 insertions, 10 deletions
diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py
index 8ad9effd..3a3c1d1b 100644
--- a/morphlib/plugins/branch_and_merge_new_plugin.py
+++ b/morphlib/plugins/branch_and_merge_new_plugin.py
@@ -615,15 +615,8 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin):
'''Read in all the morphologies in the root repository.'''
self.app.status(msg='Loading in all morphologies')
morphs = morphlib.morphset.MorphologySet()
- mf = morphlib.morphologyfinder.MorphologyFinder(
- morphlib.gitdir.GitDirectory(
- sb.get_git_directory_name(sb.root_repository_url)))
- for morph in mf.list_morphologies():
- text, filename = mf.read_morphology(morph)
- m = loader.load_from_string(text, filename=filename)
- m.repo_url = sb.root_repository_url
- m.ref = sb.system_branch_name
- morphs.add_morphology(m)
+ for morph in sb.load_all_morphologies(loader):
+ morphs.add_morphology(morph)
return morphs
def petrify(self, args):
diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py
index 73a07d5e..1a8b898a 100644
--- a/morphlib/sysbranchdir.py
+++ b/morphlib/sysbranchdir.py
@@ -161,6 +161,20 @@ class SystemBranchDirectory(object):
for dirname in
morphlib.util.find_leaves(self.root_directory, '.git'))
+ # Not covered by unit tests, since testing the functionality spans
+ # multiple modules and only tests useful output with a full system
+ # branch, so it is instead covered by integration tests.
+ def load_all_morphologies(self, loader): # pragma: no cover
+ gd_name = self.get_git_directory_name(self.root_repository_url)
+ gd = morphlib.gitdir.GitDirectory(gd_name)
+ mf = morphlib.morphologyfinder.MorphologyFinder(gd)
+ for morph in mf.list_morphologies():
+ text, filename = mf.read_morphology(morph)
+ m = loader.load_from_string(text, filename=filename)
+ m.repo_url = self.root_repository_url
+ m.ref = self.system_branch_name
+ yield m
+
def create(root_directory, root_repository_url, system_branch_name):
'''Create a new system branch directory on disk.
diff --git a/morphlib/util.py b/morphlib/util.py
index 7382e40c..16e56366 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -18,7 +18,6 @@ import os
import re
import morphlib
-import logging
'''Utility functions for morph.'''