def get_mapped_file(directory, remote_path, allow_nested_files=False, local_path_module=os.path, mkdir=True): """ >>> import ntpath >>> get_mapped_file(r'C:\\pulsar\\staging\\101', 'dataset_1_files/moo/cow', allow_nested_files=True, local_path_module=ntpath, mkdir=False) 'C:\\\\pulsar\\\\staging\\\\101\\\\dataset_1_files\\\\moo\\\\cow' >>> get_mapped_file(r'C:\\pulsar\\staging\\101', 'dataset_1_files/moo/cow', allow_nested_files=False, local_path_module=ntpath) 'C:\\\\pulsar\\\\staging\\\\101\\\\cow' >>> get_mapped_file(r'C:\\pulsar\\staging\\101', '../cow', allow_nested_files=True, local_path_module=ntpath, mkdir=False) Traceback (most recent call last): Exception: Attempt to read or write file outside an authorized directory. """ if not allow_nested_files: name = local_path_module.basename(remote_path) path = local_path_module.join(directory, name) else: local_rel_path = __posix_to_local_path( remote_path, local_path_module=local_path_module) local_path = local_path_module.join(directory, local_rel_path) verify_is_in_directory(local_path, directory, local_path_module=local_path_module) local_directory = local_path_module.dirname(local_path) if mkdir and not local_path_module.exists(local_directory): os.makedirs(local_directory) path = local_path return path
def _output_path(manager, job_id, name, output_type): """ """ directory = manager.job_directory(job_id).outputs_directory() if output_type == path_type.OUTPUT_WORKDIR: # action_mapper.path_type.OUTPUT_WORKDIR directory = manager.job_directory(job_id).working_directory() path = os.path.join(directory, name) verify_is_in_directory(path, directory) return path
def _output_path(manager, job_id, name, output_type): """ """ directory = manager.job_directory(job_id).outputs_directory() if output_type == path_type.OUTPUT_WORKDIR: # action_mapper.path_type.OUTPUT_WORKDIR directory = manager.job_directory(job_id).working_directory() path = os.path.join(directory, name) verify_is_in_directory(path, directory) return path
def get_mapped_file(directory, remote_path, allow_nested_files=False, local_path_module=os.path, mkdir=True): """ >>> import ntpath >>> get_mapped_file(r'C:\\pulsar\\staging\\101', 'dataset_1_files/moo/cow', allow_nested_files=True, local_path_module=ntpath, mkdir=False) 'C:\\\\pulsar\\\\staging\\\\101\\\\dataset_1_files\\\\moo\\\\cow' >>> get_mapped_file(r'C:\\pulsar\\staging\\101', 'dataset_1_files/moo/cow', allow_nested_files=False, local_path_module=ntpath) 'C:\\\\pulsar\\\\staging\\\\101\\\\cow' >>> get_mapped_file(r'C:\\pulsar\\staging\\101', '../cow', allow_nested_files=True, local_path_module=ntpath, mkdir=False) Traceback (most recent call last): Exception: Attempt to read or write file outside an authorized directory. """ if not allow_nested_files: name = local_path_module.basename(remote_path) path = local_path_module.join(directory, name) else: local_rel_path = __posix_to_local_path(remote_path, local_path_module=local_path_module) local_path = local_path_module.join(directory, local_rel_path) verify_is_in_directory(local_path, directory, local_path_module=local_path_module) local_directory = local_path_module.dirname(local_path) if mkdir and not local_path_module.exists(local_directory): os.makedirs(local_directory) path = local_path return path