def _process_directories(self, fs_dirnames, root_object, root_web_path): # if any of directories under root doesn't exist -> remove it from db db_dirs = root_object.subdirectories.all() for directory_object in db_dirs: if os.path.basename(directory_object.path) not in fs_dirnames: logger.info("scheduling directory removal: " + directory_object.path) self._removals.append(directory_object) # add directory objects if not found on db db_dirnames = {os.path.basename(x.path) for x in db_dirs} for directory in set(fs_dirnames) - db_dirnames: dir_web_path = os.path.join(root_web_path, directory) # don't save modification time - defer until processing that directory find_or_create_directory(dir_web_path, parent=root_object) logger.info("adding directory: " + dir_web_path)
def _create_directories_in_chain(directory): parent_paths = [directory] parent = os.path.dirname(directory) while len(parent) > 0: parent_paths.append(parent) parent = os.path.dirname(parent) previous_parent = None for path in reversed(parent_paths): previous_parent = find_or_create_directory(path, previous_parent)
def synchronize_db_with_collection(self, root_phys_path, dirs, files): # only index files that have correct name - it will be changed anyway during next Runner loop files = sorted([f for f in files if is_jpeg(f) and Renamer.CORRECT_FILENAME_RE.match(f) or is_video(f)]) # find directory object corresponding to root -> create if needed root_web_path = locations.collection_web_path(root_phys_path) root_object = find_or_create_directory(root_web_path) self._process_directories(dirs, root_object, root_web_path) self._process_files(files, root_object, root_phys_path)