def _move_files_safe(self, src_web_path, dst_web_path): """ Move file in collection from path1 to path2. Also move associated thumbnail and preview file, and any files with same prefix in collection folder (mainly RAWS) """ src_file_phys_path = locations.collection_phys_path(src_web_path) dst_file_phys_path = locations.collection_phys_path(dst_web_path) # create list of modifications files will be moved in loop at the end of method renames = [(src_file_phys_path, dst_file_phys_path)] # query generators and add all generated miniatures to renames for generator in MINIATURE_GENERATORS: if generator.will_output_file(src_web_path): src_miniature_phys_path = generator.miniature_phys_path(src_file_phys_path) dst_miniature_phys_path = self._calculate_dst_path_after_move(src_web_path, dst_web_path, src_miniature_phys_path) renames.append((src_miniature_phys_path, dst_miniature_phys_path)) # add move of "other files in group" in collection folder self._add_similar_files_modifications(src_file_phys_path, dst_file_phys_path, renames) # move files in batch # TODO: rollback changes (move files back to their original positions) on error for (src, dst) in renames: move_without_overwriting(src, dst, # allow creating destination folders only in trash create_destination_dir=locations.web_path_in_trash(dst_web_path))
def _rename_group(self, image_infos, good_suffix): """ Change file names in image_infos list, by concatenating new suffix. """ for image_info in image_infos: image_info.suffix = good_suffix logger.info("renaming: {0.path} -> {0.new_path}".format(image_info)) # rename file move_without_overwriting(image_info.path, image_info.new_path) # remove old name, add now name to list of files self._files.remove(os.path.basename(image_info.path)) self._files.append(os.path.basename(image_info.new_path))