diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-09-19 10:27:36 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-09-24 10:26:03 +0000 |
commit | 924e2192ae3de5974ee058c0ea9c180f2e46d78e (patch) | |
tree | 895c52ab9f1d1401f58eb971609a6faebdf04d77 /morphlib | |
parent | f58e5f85d135d00f92116a97bb8bce82d46f0d36 (diff) | |
download | definitions-924e2192ae3de5974ee058c0ea9c180f2e46d78e.tar.gz |
MorphSet: add a list_refs() method
This will be used to factor the morphology traversal code out of petrify,
since it is cleaner to find out which refs are present, resolve them,
then update them, instead of the previous approach which updated as part
of the traversal.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/morphset.py | 20 | ||||
-rw-r--r-- | morphlib/morphset_tests.py | 6 |
2 files changed, 26 insertions, 0 deletions
diff --git a/morphlib/morphset.py b/morphlib/morphset.py index 468bcbe9..10583326 100644 --- a/morphlib/morphset.py +++ b/morphlib/morphset.py @@ -202,3 +202,23 @@ class MorphologySet(object): self._traverse_specs(process_spec, wanted_spec) + def list_refs(self): + '''Return a set of all the (repo, ref) pairs in the MorphologySet. + + This does not dirty the morphologies so they do not need to be + written back to the disk. + + ''' + known = set() + + def wanted_spec(m, kind, spec): + return (spec['repo'], spec['ref']) not in known + + def process_spec(spec): + known.add((spec['repo'], spec['ref'])) + return False + + self._traverse_specs(process_spec, wanted_spec) + + return known + diff --git a/morphlib/morphset_tests.py b/morphlib/morphset_tests.py index 69a7057f..24f3d91a 100644 --- a/morphlib/morphset_tests.py +++ b/morphlib/morphset_tests.py @@ -185,3 +185,9 @@ class MorphologySetTests(unittest.TestCase): } ]) + def test_list_refs(self): + self.morphs.add_morphology(self.system) + self.morphs.add_morphology(self.stratum) + self.assertEqual(sorted(self.morphs.list_refs()), + [('test:foo-chunk', 'master'), + ('test:morphs', 'master')]) |