diff --git a/ansible_deployer/command_line.py b/ansible_deployer/command_line.py index e67dca0d..0da81268 100644 --- a/ansible_deployer/command_line.py +++ b/ansible_deployer/command_line.py @@ -107,20 +107,25 @@ def create_workdir(timestamp: str): # #TODO: Add locking of the directory - if short_ts not in os.listdir(conf["global_paths"]["work_dir"]): - seq_path = os.path.join(date_dir, f"{conf['file_naming']['sequence_prefix']}0000") - else: - sequence_list = os.listdir(date_dir) - sequence_list.sort() - new_sequence = int(sequence_list[-1].split(conf['file_naming']['sequence_prefix'])[1]) + 1 - seq_path = os.path.join(date_dir, f"{conf['file_naming']['sequence_prefix']}" - f"{new_sequence:04d}") + try: + if short_ts not in os.listdir(conf["global_paths"]["work_dir"]): + seq_path = os.path.join(date_dir, f"{conf['file_naming']['sequence_prefix']}0000") + else: + sequence_list = os.listdir(date_dir) + sequence_list.sort() + new_sequence = int(sequence_list[-1].split(conf['file_naming']['sequence_prefix'])[1])\ + + 1 + seq_path = os.path.join(date_dir, f"{conf['file_naming']['sequence_prefix']}" + f"{new_sequence:04d}") + except Exception as exc: + logger.critical("Failed to list work dir due to: %s", exc) + sys.exit(91) try: os.makedirs(seq_path) os.chdir(seq_path) - except Exception as e: - logger.critical("Failed to create work dir:%s error was:%s", seq_path, e, file=sys.stderr) + except Exception as exc: + logger.critical("Failed to create work dir: %s due to: %s", seq_path, exc) sys.exit(90) logger.debug("Successfully created workdir: %s", seq_path) return seq_path