diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-05-01 19:14:38 +0000 |
---|---|---|
committer | Baserock Gerrit <gerrit@baserock.org> | 2015-06-16 16:02:26 +0000 |
commit | 665ea01218dcba658d95b86014c7da5dd974a8a7 (patch) | |
tree | d9e5fa8598c5e64eaf6c609a109e3b889813dcb8 /morphlib/sysbranchdir.py | |
parent | 3f030c900570392180ce9bf813e546579e908eb3 (diff) | |
download | morph-665ea01218dcba658d95b86014c7da5dd974a8a7.tar.gz |
Add DefinitionsRepo class
The intention is for this class to take over the from the Workspace and
SystemBranch classes. It allows Morph to load and parse definitions from
a Git repo, without requiring the user to run `morph checkout` or
`morph branch`: it can operate from any normal Git repository.
The class behaves differently when the Git repository is inside a Morph
system-branch checkout made with `morph branch` or `morph checkout`, to
avoid changing things under the feet of people who are used to those
commands.
Change-Id: I52a898efb9f6fb7f7e94c65b9ed38516bd51f49d
Diffstat (limited to 'morphlib/sysbranchdir.py')
-rw-r--r-- | morphlib/sysbranchdir.py | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index 3ca5a8cb..d23d9eea 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -46,12 +46,28 @@ class SystemBranchDirectory(object): def __init__(self, root_directory, root_repository_url, system_branch_name): - self.root_directory = os.path.abspath(root_directory) - self.root_repository_url = root_repository_url self.system_branch_name = system_branch_name + # The 'root repo' is the definitions repo. This attribute is named this + # way for historical reasons. + self.root_repository_url = root_repository_url + assert root_repository_url is not None + + # The 'root directory' is the parent directory of all checked-out + # repos. For example, the root directory of branch 'sam/test' in + # workspace '/src/ws' would be '/src/ws/sam/test' (at the time it was + # created by `morph branch` or `morph checkout`, anyway). + self.root_directory = os.path.abspath(root_directory) + self.config = morphlib.gitdir.Config(config_file=self._config_path) + # In order to handle newly-created system branch directories (and for + # the unit tests) we don't raise an error here if the definitions repo + # isn't cloned yet. Some methods won't work if it doesn't exist though. + definitions_repo_dir = self.get_git_directory_name(root_repository_url) + self.definitions_repo = morphlib.definitions_repo.DefinitionsRepo( + definitions_repo_dir, system_branch=self, allow_missing=True) + @property def _magic_path(self): return os.path.join(self.root_directory, '.morph-system-branch') @@ -106,9 +122,7 @@ class SystemBranchDirectory(object): return os.path.join(self.root_directory, relative) def relative_to_root_repo(self, path): # pragma: no cover - gitdirpath = self.get_git_directory_name(self.root_repository_url) - - return os.path.relpath(os.path.abspath(path), gitdirpath) + return self.definitions_repo.relative_path(path) def get_git_directory_name(self, repo_url): '''Return directory pathname for a given git repository. @@ -193,21 +207,8 @@ 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 filename in (f for f in mf.list_morphologies() - if not gd.is_symlink(f)): - text = mf.read_morphology(filename) - m = loader.load_from_string(text, filename=filename) - m.repo_url = self.root_repository_url - m.ref = self.system_branch_name - yield m - + return self.definitions_repo.load_all_morphologies(loader) def create(root_directory, root_repository_url, system_branch_name): |