summaryrefslogtreecommitdiff
path: root/morphlib/morphset.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-06-17 16:36:07 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-07-10 13:50:00 +0000
commit3dc83847b8f17793bdab5e978d13d394b48987b0 (patch)
treea67c54b99b7e822ab7f49df3c9df2199435f21ff /morphlib/morphset.py
parentae007688d8f1f57b138dafffdfc3683aa7c7730f (diff)
downloadmorph-3dc83847b8f17793bdab5e978d13d394b48987b0.tar.gz
Use exact filenames to refer to morphology files
Rather than repeatedly stripping and appending an optional .morph extension morphology names, instead always use the file path of the morphology relative to the definitions repository. This is an inversion of the previous logic, which would strip the .morph extension and use the "name" internally. The exception to this rule of always using the filename, is that `morph edit CHUNK` uses the name of the morphology as-defined in the stratum. This is based off Adam Coldrick's inital patch, but this version will allow the old style of providing the "name" by converting it into a path if it does not have either a / or a . in it. An unfortunate consequence of this change is that the show-dependencies command's output changed, so the test needed updating.
Diffstat (limited to 'morphlib/morphset.py')
-rw-r--r--morphlib/morphset.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/morphlib/morphset.py b/morphlib/morphset.py
index 9f349db7..590ac51e 100644
--- a/morphlib/morphset.py
+++ b/morphlib/morphset.py
@@ -66,7 +66,7 @@ class MorphologySet(object):
def _find_spec(self, specs, wanted_name):
for spec in specs:
- name = spec.get('morph', spec.get('name'))
+ name = spec.get('name', spec.get('morph'))
if name == wanted_name:
return spec.get('repo'), spec.get('ref'), name
return None, None, None
@@ -127,8 +127,8 @@ class MorphologySet(object):
specs = m[kind]
for spec in specs:
if cb_filter(m, kind, spec):
- orig_spec = (spec.get('repo'), spec.get('ref'),
- spec['morph'])
+ fn = morphlib.util.sanitise_morphology_path(spec['morph'])
+ orig_spec = (spec.get('repo'), spec.get('ref'), fn)
dirtied = cb_process(m, kind, spec)
if dirtied:
m.dirty = True
@@ -142,17 +142,18 @@ class MorphologySet(object):
process_spec_list(m, 'chunks')
for m in self.morphologies:
- tup = (m.repo_url, m.ref, m.filename[:-len('.morph')])
+ tup = (m.repo_url, m.ref, m.filename)
if tup in altered_references:
spec = altered_references[tup]
if m.ref != spec.get('ref'):
m.ref = spec.get('ref')
m.dirty = True
- assert (m.filename == spec['morph'] + '.morph'
+ file = morphlib.util.sanitise_morphology_path(spec['morph'])
+ assert (m.filename == file
or m.repo_url == spec.get('repo')), \
'Moving morphologies is not supported.'
- def change_ref(self, repo_url, orig_ref, morph_filename, new_ref):
+ def change_ref(self, repo_url, orig_ref, morph_name, new_ref):
'''Change a triplet's ref to a new one in all morphologies in a ref.
Change orig_ref to new_ref in any morphology that references the
@@ -161,9 +162,10 @@ class MorphologySet(object):
'''
def wanted_spec(m, kind, spec):
+ spec_name = spec.get('name', spec['morph'])
return (spec.get('repo') == repo_url and
spec.get('ref') == orig_ref and
- spec['morph'] + '.morph' == morph_filename)
+ spec_name == morph_name)
def process_spec(m, kind, spec):
spec['unpetrify-ref'] = spec.get('ref')