diff options
author | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2014-04-04 15:39:34 +0000 |
---|---|---|
committer | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2014-04-15 09:20:26 +0000 |
commit | a4bf96b0bf29928e4e4aa3690261236fa31e80a0 (patch) | |
tree | 9c19750112b190eb4243ea1db0685833d5ceef4c | |
parent | af91d93e113618709eb25b137b69339012a0a452 (diff) | |
download | morph-a4bf96b0bf29928e4e4aa3690261236fa31e80a0.tar.gz |
Make morph edit use a path to a morphology as its only argument
To edit a chunk, do `morph edit path/to/chunk.morph` where the path is
relative to the root of the definitions repository checkout.
-rw-r--r-- | morphlib/plugins/branch_and_merge_new_plugin.py | 77 |
1 files changed, 23 insertions, 54 deletions
diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py index 51cba401..5ff9e34d 100644 --- a/morphlib/plugins/branch_and_merge_new_plugin.py +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -419,59 +419,33 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): ''' - if len(args) not in (2, 3): - raise cliapp.AppException('morph edit needs the names of a system,' - ' a stratum and optionally a chunk' - ' as parameters') + if len(args) != 1: + raise cliapp.AppException('morph edit needs the path to a ' + 'morphology as a parameter') - system_name = morphlib.util.strip_morph_extension(args[0]) - stratum_name = morphlib.util.strip_morph_extension(args[1]) - chunk_name = None - if len(args) == 3: - chunk_name = morphlib.util.strip_morph_extension(args[2]) + morphology_path = args[0] ws = morphlib.workspace.open('.') sb = morphlib.sysbranchdir.open_from_within('.') loader = morphlib.morphloader.MorphologyLoader() - # Load the system morphology, and all stratum morphologies, including - # all the strata that are being build-depended on. - - logging.debug('Loading system morphology') - system_morph = loader.load_from_file( - sb.get_filename(sb.root_repository_url, system_name + '.morph')) - if system_morph['kind'] != 'system': - raise cliapp.AppException("%s is not a system" % system_name) - system_morph.repo_url = sb.root_repository_url - system_morph.ref = sb.system_branch_name - system_morph.filename = system_name + '.morph' - - logging.debug('Loading stratum morphologies') - morphs = self._load_stratum_morphologies(loader, sb, system_morph) - morphs.add_morphology(system_morph) - logging.debug('morphs: %s' % repr(morphs.morphologies)) - - # Change refs to the stratum to be to the system branch. - # Note: this currently only supports strata in root repository. - - logging.debug('Changing refs to stratum %s' % stratum_name) - stratum_morph = morphs.get_stratum_in_system( - system_morph, stratum_name) - morphs.change_ref( - stratum_morph.repo_url, stratum_morph.ref, stratum_morph.filename, - sb.system_branch_name) - logging.debug('morphs: %s' % repr(morphs.morphologies)) - - # If we're editing a chunk, make it available locally, with the - # relevant git branch checked out. This also invents the new branch - # name. - - if chunk_name: - logging.debug('Editing chunk %s' % chunk_name) + # Load the morphology, including all the stratum morphologies that + # are being build-depended on. - chunk_url, chunk_ref, chunk_morph = morphs.get_chunk_triplet( - stratum_morph, chunk_name) + logging.debug('Loading morphology') + morphology = loader.load_from_file( + sb.get_filename(sb.root_repository_url, morphology_path)) + if morphology['kind'] == 'chunk': + # Checkout the chunk repo, and update other morphologies to use + # the edited chunk. + try: + chunk_url = morphology['repo'] + chunk_ref = morphology['ref'] + except KeyError: + raise cliapp.AppException('Chunk definition %s does not ' + 'contain repo and ref' % + morphology_path) chunk_dirname = sb.get_git_directory_name(chunk_url) if not os.path.exists(chunk_dirname): lrc, rrc = morphlib.util.new_repo_caches(self.app) @@ -491,15 +465,10 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): gd.fat_init() gd.fat_pull() - # Change the refs to the chunk. - if chunk_ref != sb.system_branch_name: - morphs.change_ref( - chunk_url, chunk_ref, chunk_morph + '.morph', - sb.system_branch_name) - - # Save any modified strata. - - self._save_dirty_morphologies(loader, sb, morphs.morphologies) + # TODO: Save changed repo/ref in both the stratum and the chunk + else: + raise cliapp.AppException( + 'morph edit takes a path to a chunk morphology.') def show_system_branch(self, args): '''Show the name of the current system branch.''' |