Skip to content

Commit

Permalink
Resolve input paths for compression before passing them to the contai…
Browse files Browse the repository at this point in the history
…ner; minor logging fixes (fixes #29) (#49)
  • Loading branch information
kirkrodrigues authored Feb 12, 2022
1 parent eac3fc3 commit 12b123e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions components/package-template/src/sbin/compress
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import sys
# Setup logging
# Create logger
log = logging.getLogger('clp')
log.setLevel(logging.DEBUG)
log.setLevel(logging.INFO)
# Setup console logging
logging_console_handler = logging.StreamHandler()
logging_formatter = logging.Formatter('%(asctime)s [%(levelname)s] [%(name)s] %(message)s')
Expand Down Expand Up @@ -93,10 +93,9 @@ def main(argv):
try:
check_env(clp_cluster_name)
except EnvironmentError as ex:
logging.error(ex)
log.error(ex)
return -1

# TODO: check path and perform path conversion
docker_exec_cmd = [
'docker', 'exec',
'--workdir', f'{CONTAINER_CLP_INSTALL_PREFIX}/clp',
Expand All @@ -105,11 +104,23 @@ def main(argv):
'sbin/native/compress', '--config', f'{CONTAINER_CLP_INSTALL_PREFIX}/.{clp_package_config.cluster_name}.yaml'
]
for path in parsed_args.paths:
path = str(pathlib.Path(path).resolve())
docker_exec_cmd.append(path)
if parsed_args.input_list is not None:
# Validate all paths in input list
all_paths_valid = True
with open(parsed_args.input_list, 'r') as f:
for line in f:
path = pathlib.Path(line.rstrip())
if not path.is_absolute():
log.error(f'Invalid relative path in input list: {path}')
all_paths_valid = False
if not all_paths_valid:
raise ValueError("--input-list must only contain absolute paths")

docker_exec_cmd.append('--input-list')
docker_exec_cmd.append(parsed_args.input_list)
logging.info(docker_exec_cmd)
log.debug(docker_exec_cmd)
subprocess.run(docker_exec_cmd)

return 0
Expand Down

0 comments on commit 12b123e

Please sign in to comment.