summaryrefslogtreecommitdiff
path: root/morphlib/definitions_repo.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-30 18:47:43 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-09-28 16:51:51 +0000
commitc521d6fa5a8a18ce3ed420d475ef0a3cc7b51ee5 (patch)
tree26a905f38d625b35f3da798fff8ee7073b3dae3e /morphlib/definitions_repo.py
parent54496d7d9b6d5e1c64c5c220ab2f280e0b9e84ec (diff)
downloadmorph-c521d6fa5a8a18ce3ed420d475ef0a3cc7b51ee5.tar.gz
Change how MorphologyLoader instances are created
Loading .morph files is becoming a bit more complicated, as we need to deal with the VERSION file, and possibly soon with a DEFAULTS file as well. The logic of loading and parsing .morph files is done either in the sourceresolver module, or the morphloader module. This change means that all users of the latter module can use the get hold of a MorphologyLoader instance with VERSION already parsed. If DEFAULTS is added then it is also simple to parse DEFAULTS. Change-Id: Ib33756e9dbd078e38f12dd7f776c89584b178959
Diffstat (limited to 'morphlib/definitions_repo.py')
-rw-r--r--morphlib/definitions_repo.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/morphlib/definitions_repo.py b/morphlib/definitions_repo.py
index c1381af6..301e5b86 100644
--- a/morphlib/definitions_repo.py
+++ b/morphlib/definitions_repo.py
@@ -124,10 +124,8 @@ class DefinitionsRepo(gitdir.GitDirectory):
bb = morphlib.buildbranch.BuildBranch(
build_ref_prefix, uuid, definitions_repo=self)
- loader = morphlib.morphloader.MorphologyLoader()
pbb = morphlib.buildbranch.pushed_build_branch(
- bb, loader=loader,
- changes_need_pushing=push, name=git_user_name,
+ bb, changes_need_pushing=push, name=git_user_name,
email=git_user_email, build_uuid=uuid,
status=status_cb)
return pbb # (repo_url, commit, original_ref)
@@ -228,11 +226,29 @@ class DefinitionsRepo(gitdir.GitDirectory):
'to "origin", or use the --local-changes=include feature '
'of Morph.' % (e.ref, e.repo_url, ref))
- def load_all_morphologies(self, loader):
+ def get_morphology_loader(self):
+ '''Return a MorphologyLoader instance.
+
+ This may read the VERSION and DEFAULTS file and pass appropriate
+ information to the MorphologyLoader constructor.
+
+ '''
+ mf = morphlib.morphologyfinder.MorphologyFinder(self)
+
+ version_text = mf.read_file('VERSION')
+ morphlib.definitions_version.check_version_file(version_text)
+
+ loader = morphlib.morphloader.MorphologyLoader()
+
+ return loader
+
+ def load_all_morphologies(self, loader=None):
+ loader = loader or self.get_morphology_loader()
+
mf = morphlib.morphologyfinder.MorphologyFinder(self)
for filename in (f for f in mf.list_morphologies()
if not self.is_symlink(f)):
- text = mf.read_morphology(filename)
+ text = mf.read_file(filename)
m = loader.load_from_string(text, filename=filename)
m.repo_url = self.remote_url
m.ref = self.HEAD