Ensure that --output-env-file handles path expansion

Currently using the option '--output-env-file=~/path/to/env-file.yaml'
will result in a '[Errno 2] No such file or directory' failure because
the path is not expanded.

This patch ensures that the path is expanded before working with it.

Change-Id: Ibd087976eea6f16f3b659dbda5d37fbed1767dc2
This commit is contained in:
Jesse Pretorius (odyssey4me) 2019-10-09 18:04:12 +01:00
parent 8b9bb10455
commit 0ebccf267f
1 changed files with 6 additions and 4 deletions

View File

@ -459,12 +459,14 @@ class PrepareImageFiles(command.Command):
)
if parsed_args.output_env_file:
params = prepare_data[parsed_args.output_env_file]
if os.path.exists(parsed_args.output_env_file):
output_env_file_expanded = os.path.expanduser(
parsed_args.output_env_file)
if os.path.exists(output_env_file_expanded):
self.log.warning("Output env file exists, "
"moving it to backup.")
shutil.move(parsed_args.output_env_file,
parsed_args.output_env_file + ".backup")
utils.safe_write(parsed_args.output_env_file,
shutil.move(output_env_file_expanded,
output_env_file_expanded + ".backup")
utils.safe_write(output_env_file_expanded,
build_env_file(params, self.app.command_options))
result = prepare_data[output_images_file]