def restore(self, id, catalog=None): src_path = os.path.join(self.path(), id) dst_path = open(os.path.join(src_path, '.restore_to'), 'rb').read() for fname in os.listdir(src_path): if fname in ('.', '..', '.restore_to', '.restore'): continue src = os.path.join(src_path, fname) dst = os.path.join(dst_path, fname) shutil.move(src, dst) root = self.__parent__ restore = open(os.path.join(src_path, '.restore'), 'rb').read() if restore.startswith('photo|'): path = restore[6:] restored = find_model(root, path) if catalog is not None: catalog.index(restored) elif restore.startswith('photos|'): path = restore[7:] restored = find_model(root, path) if catalog is not None: catalog.index_album_and_photos(restored) shutil.rmtree(src_path) return restored