From 78e894201c63f1d8bbb7a7459e9bb73216315922 Mon Sep 17 00:00:00 2001 From: mandresm Date: Wed, 11 Dec 2024 17:52:39 +0100 Subject: [PATCH] add emulate pushd and popd behavior for esm_master --- src/esm_master/task.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/esm_master/task.py b/src/esm_master/task.py index 1c2173b90..86f5b9ddc 100644 --- a/src/esm_master/task.py +++ b/src/esm_master/task.py @@ -435,6 +435,8 @@ def generate_task_script(self): def execute(self, ignore_errors=False): # Calculate the number of get commands for this esm_master operation self.num_of_get_commands() + # Initialize the dirstack for imitating pushd popd + dirstack = [] # Loop through the commands for command in self.command_list: repo = self.get_repo_properties_from_command(command) @@ -481,6 +483,16 @@ def execute(self, ignore_errors=False): command_spl = shlex.split(command) if "cd" == command_spl[0]: os.chdir(command_spl[1]) + elif "pushd" == command_spl[0]: + # Emulates pushd (MA): yes it is horrible, but I don't + # have time to rewrite esm_master right now + dirstack.append(os.getcwd()) + os.chdir(command_spl[1]) + elif "popd" == command_spl[0]: + # Emulates popd (MA): yes it is horrible, but I don't + # have time to rewrite esm_master right now + target_dir = target_dir = dirstack.pop(-1) + os.chdir(target_dir) else: subprocess.run( command_spl,