def check_directories(self, directory, rel_path, album_directories, options): """Checks an export directory for obsolete files.""" if options.ignore: exclude_pattern = re.compile(su.fsdec(options.ignore)) if exclude_pattern.match(os.path.split(directory)[1]): return True if not os.path.exists(directory): return True contains_albums = False for f in su.os_listdir_unicode(directory): if self._check_abort(): return album_file = os.path.join(directory, f) if os.path.isdir(album_file): if f == "iPod Photo Cache": su.pout("Skipping " + album_file) continue rel_path_file = os.path.join(rel_path, f) if album_file in album_directories: contains_albums = True elif not self.check_directories(album_file, rel_path_file, album_directories, options): delete_album_file(album_file, directory, "Obsolete directory", options) else: # we won't touch some files if imageutils.is_ignore(f): continue delete_album_file(album_file, directory, "Obsolete", options) return contains_albums
def check_directories(self, directory, rel_path, album_directories, options): """Checks an export directory for obsolete files.""" if options.ignore: exclude_pattern = re.compile(su.fsdec(options.ignore)) if exclude_pattern.match(os.path.split(directory)[1]): return True if not os.path.exists(directory): return True contains_albums = False for f in su.os_listdir_unicode(directory): if self._check_abort(): return album_file = os.path.join(directory, f) if os.path.isdir(album_file): if f == "iPod Photo Cache": su.pout("Skipping " + album_file) continue rel_path_file = os.path.join(rel_path, f) if album_file in album_directories: contains_albums = True elif not self.check_directories(album_file, rel_path_file, album_directories, options): delete_album_file(album_file, directory, "Obsolete directory", options) else: contains_albums = True else: # we won't touch some files if imageutils.is_ignore(f): continue delete_album_file(album_file, directory, "Obsolete", options) return contains_albums
def _search_for_file(self, folder_path, basename): """Scans recursively through a folder tree and returns the path to the first file it finds that starts with "basename". """ for file_name in su.os_listdir_unicode(folder_path): path = os.path.join(folder_path, file_name) if os.path.isdir(path): path = self._search_for_file(path, basename) if path: return path elif file_name.startswith(basename): return path return None