Commit 993c3c8a authored by Javier Vegas-Regidor's avatar Javier Vegas-Regidor
Browse files

Add nested alias support

parent c57c2ea2
......@@ -213,9 +213,11 @@ class Config(object):
)
Log.debug("Preparing command list")
commands = self._diags.split()
self._real_commands = list()
self._apply_aliases(commands)
Log.debug("Command list ready ")
while self._apply_aliases(commands):
pass
Log.debug("Command list ready: ")
for command in self._real_commands:
Log.debug(command)
self.scratch_dir = os.path.join(
self.scratch_dir, "diags", self.experiment.expid
......@@ -226,22 +228,29 @@ class Config(object):
self.report = ReportConfig(parser)
def _apply_aliases(self, commands):
for command in commands:
command = command.strip()
if command.startswith("#"):
break
if command.lower() in self._aliases:
added_commands = self._aliases[command.lower()]
Log.info(
"Changing alias {0} for {1}",
command,
" ".join(added_commands),
)
for add_command in added_commands:
if add_command:
self._real_commands.append(add_command)
else:
self._real_commands.append(command)
applied_alias = True
while applied_alias:
real_commands = []
applied_alias = False
for command in commands:
command = command.strip()
if command.startswith("#"):
break
if command.lower() in self._aliases:
added_commands = self._aliases[command.lower()]
Log.info(
"Changing alias {0} for {1}",
command,
" ".join(added_commands),
)
for add_command in added_commands:
if add_command:
real_commands.append(add_command)
applied_alias = True
else:
real_commands.append(command)
commands = real_commands
self._real_commands = commands
def _parse_dataconvention(self, parser):
data_convention = parser.get_choice_option(
......
......@@ -752,6 +752,14 @@ class TestConfig(TestCase):
self._parse(config)
self.assertEqual(config.get_commands(), ["diag2"])
def test_nested_alias(self):
"""Test alias parsing"""
config = Config()
self.mock_parser.add_value("ALIAS", "nested", "diag3")
self.mock_parser.add_value("ALIAS", "diag2", "nested diag4")
self._parse(config)
self.assertEqual(config.get_commands(), ["diag1", "diag3", "diag4"])
def test_auto_clean_ram_disk(self):
"""Test that USE_RAMDISK forces AUTO_CLEAN to true"""
config = Config()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment