from lib.helpers import ( get_attachments_folder_path, get_document_space, get_document_space_title, write_csv, ) import os import shutil def create_import(CONFIG): rows = [] for current_path, folders, files in os.walk(CONFIG["absolute_starting_path"]): document_space = get_document_space(CONFIG, current_path) document_space_title = get_document_space_title(CONFIG, current_path) attachements_folder_path = get_attachments_folder_path(CONFIG, current_path) line = { "documentSpace": document_space, "documentName": "WebHome", "documentTitle": document_space_title, "attachmentsFolderPath": attachements_folder_path, "documentContent": "{{children/}}", "pilot": CONFIG["pilot"], } rows.append(line) path = os.path.join(CONFIG["export_directory"], attachements_folder_path) os.mkdir(path) if files: for file in files: shutil.copy( os.path.join(current_path, file), os.path.join(CONFIG["export_directory"], attachements_folder_path), ) write_csv(f"{CONFIG['export_directory']}/export-pages.csv", CONFIG["fields"], rows)