Skip to content

Commit

Permalink
Improve handling of invalid workdir creation
Browse files Browse the repository at this point in the history
  • Loading branch information
LegenJCdary committed Mar 24, 2022
1 parent 204a98a commit fba33aa
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions ansible_deployer/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fba33aa

Please sign in to comment.