From 53495e0a507a78e120d4589b52a59b5123c2ecfd Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 13 Dec 2013 14:05:57 +0000 Subject: Modify morph to strip .morph extensions from parameters --- morphlib/plugins/branch_and_merge_new_plugin.py | 8 +++++--- morphlib/plugins/build_plugin.py | 2 +- morphlib/plugins/deploy_plugin.py | 2 +- morphlib/util.py | 9 +++++++++ morphlib/util_tests.py | 22 ++++++++++++++++++++++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py index 3a3c1d1b..f3b47468 100644 --- a/morphlib/plugins/branch_and_merge_new_plugin.py +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -417,9 +417,11 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): ' a stratum and optionally a chunk' ' as parameters') - system_name = args[0] - stratum_name = args[1] - chunk_name = args[2] if len(args) == 3 else None + 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]) ws = morphlib.workspace.open('.') sb = morphlib.sysbranchdir.open_from_within('.') diff --git a/morphlib/plugins/build_plugin.py b/morphlib/plugins/build_plugin.py index 8e04d0b3..a58bce20 100644 --- a/morphlib/plugins/build_plugin.py +++ b/morphlib/plugins/build_plugin.py @@ -107,7 +107,7 @@ class BuildPlugin(cliapp.Plugin): self.app.settings['cachedir'], self.app.settings['cachedir-min-space']) - system_name = args[0] + system_name = morphlib.util.strip_morph_extension(args[0]) ws = morphlib.workspace.open('.') sb = morphlib.sysbranchdir.open_from_within('.') diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py index 09405aa4..1e86d44c 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -265,7 +265,7 @@ class DeployPlugin(cliapp.Plugin): self.app.settings['tempdir-min-space'], '/', 0) - cluster_name = args[0] + cluster_name = morphlib.util.strip_morph_extension(args[0]) env_vars = args[1:] ws = morphlib.workspace.open('.') diff --git a/morphlib/util.py b/morphlib/util.py index 16e56366..90ad425e 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -58,6 +58,15 @@ def indent(string, spaces=4): return '\n'.join(lines) +def strip_morph_extension(morph_name): + if morph_name.startswith('.'): + raise morphlib.Error( + 'Invalid morphology name: %s' % morph_name) + elif morph_name.endswith('.morph'): + return morph_name[:-len('.morph')] + return morph_name + + def make_concurrency(cores=None): '''Return the number of concurrent jobs for make. diff --git a/morphlib/util_tests.py b/morphlib/util_tests.py index fbf7f27b..5a8ae797 100644 --- a/morphlib/util_tests.py +++ b/morphlib/util_tests.py @@ -38,6 +38,28 @@ class IndentTests(unittest.TestCase): ' foo\n bar') +class StripMorphExtensionTests(unittest.TestCase): + + def test_raises_error_when_string_starts_with_period(self): + with self.assertRaises(morphlib.Error): + morphlib.util.strip_morph_extension('.morph') + + def test_strips_morph_extension_from_string(self): + self.assertEqual(morphlib.util.strip_morph_extension('a.morph'), 'a') + + def test_returns_morph_when_not_given_as_extension(self): + self.assertEqual(morphlib.util.strip_morph_extension('morph'), 'morph') + + def test_strips_extension_only_once_from_string(self): + self.assertEqual(morphlib.util.strip_morph_extension('a.morph.morph'), + 'a.morph') + + def test_returns_input_without_modification_if_no_extension(self): + self.assertEqual( + morphlib.util.strip_morph_extension('completely not a path'), + 'completely not a path') + + class MakeConcurrencyTests(unittest.TestCase): def test_returns_2_for_1_core(self): -- cgit v1.2.1