summaryrefslogtreecommitdiff
path: root/scripts/edit-morph
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-08-14 13:45:59 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-08-14 13:45:59 +0000
commitc1c331e7c545c7a2f0545d3b1ef9751c9571d357 (patch)
treed2a4edf71f2c7204808e4543f3d743a81e95a1bd /scripts/edit-morph
parentb2786c73c0f4d4b76f824e309598ce57065e30ab (diff)
parent5f705f1e2c95b988ae39df7820f4034c49f375e4 (diff)
downloadmorph-c1c331e7c545c7a2f0545d3b1ef9751c9571d357.tar.gz
Merge branch 'baserock/adamcoldrick/remove-morph2-tweaked'
Reviewed-by: Richard Maw
Diffstat (limited to 'scripts/edit-morph')
-rwxr-xr-xscripts/edit-morph60
1 files changed, 8 insertions, 52 deletions
diff --git a/scripts/edit-morph b/scripts/edit-morph
index d0b793a4..90679b23 100755
--- a/scripts/edit-morph
+++ b/scripts/edit-morph
@@ -32,13 +32,8 @@ class EditMorph(cliapp.Application):
'automatically')
def load_morphology(self, file_name, expected_kind = None):
- with open(file_name) as f:
- text = f.read()
- try:
- morphology = morphlib.morph2.Morphology(text)
- except ValueError as e:
- raise morphlib.Error("Error parsing %s: %s" %
- (file_name, str(e)))
+ loader = morphlib.morphloader.MorphologyLoader()
+ morphology = loader.load_from_file(file_name)
if expected_kind is not None and morphology['kind'] != expected_kind:
raise morphlib.Error("Expected: a %s morphology" % expected_kind)
@@ -67,10 +62,10 @@ class EditMorph(cliapp.Application):
elif chunk_name in info['build-depends']:
info['build-depends'].remove(chunk_name)
build_depends_count += 1
- morphology._dict['chunks'] = new_chunks
+ morphology['chunks'] = new_chunks
- with morphlib.savefile.SaveFile(file_name, 'w') as f:
- morphology.update_text(text, f)
+ loader = morphlib.morphloader.MorphologyLoader()
+ loader.save_to_file(file_name, morphology)
self.output.write("Removed: %i chunk(s) and %i build depend(s).\n" %
(component_count, build_depends_count))
@@ -88,49 +83,10 @@ class EditMorph(cliapp.Application):
for chunk in morphology['chunks']:
chunk['build-depends'].sort()
- morphology._dict['chunks'] = self.sort_chunks(morphology['chunks'])
+ morphology['chunks'] = self.sort_chunks(morphology['chunks'])
- with morphlib.savefile.SaveFile(file_name, 'w') as f:
- morphology.update_text(text, f)
-
- def cmd_to_json(self, args):
- """Convert one or more FILES to JSON.
-
- Assumes a .yaml extension, which will be removed in the output file.
- """
-
- if len(args) == 0:
- raise cliapp.AppException("to-json expects one or more filenames")
-
- for file_name in args:
- try:
- morphology, text = self.load_morphology(file_name)
-
- if not file_name.endswith('.yaml'):
- raise morphlib.Error('file name does not end with .yaml')
- out_file_name = file_name[:-len('.yaml')]
-
- with morphlib.savefile.SaveFile(out_file_name, 'w') as f:
- morphology.update_text(text, f, convert_to='json')
- except Exception as e:
- self.output.write('%s: %s\n' % (file_name, e))
-
- def cmd_to_yaml(self, args):
- """Convert one or more FILES to YAML.
-
- Adds a .yaml extension for each input file."""
-
- if len(args) == 0:
- raise cliapp.AppException("to-yaml expects one or more filenames")
-
- for file_name in args:
- try:
- morphology, text = self.load_morphology(file_name)
-
- with morphlib.savefile.SaveFile(file_name + '.yaml', 'w') as f:
- morphology.update_text(text, f, convert_to='yaml')
- except Exception as e:
- self.output.write('%s: %s\n' % (file_name, e))
+ loader = morphlib.morphloader.MorphologyLoader()
+ loader.save_to_file(file_name, morphology)
def sort_chunks(self, chunks_list):
"""Sort stratum chunks