def test_delete_chowdown_migration_data(api_client, chowdown_zip): selection = chowdown_zip.name response = api_client.delete( f"{MIGRATIONS_PREFIX}/chowdown/{selection}/delete") assert response.status_code == 200 assert not MIGRATION_DIR.joinpath(chowdown_zip.name).is_file()
def test_delete__nextcloud_migration_data(api_client, nextcloud_zip): selection = nextcloud_zip.name response = api_client.delete( f"{MIGRATIONS_PREFIX}/nextcloud/{selection}/delete") assert response.status_code == 200 assert not MIGRATION_DIR.joinpath(nextcloud_zip.name).is_file()
def test_upload_nextcloud_zip(api_client, nextcloud_zip): response = api_client.post( f"{MIGRATIONS_PREFIX}/nextcloud/upload", files={"archive": nextcloud_zip.open("rb")}, ) assert response.status_code == 200 assert MIGRATION_DIR.joinpath("nextcloud", nextcloud_zip.name).is_file()
def test_upload_chowdown_zip(api_client, chowdown_zip): response = api_client.post( f"{MIGRATIONS_PREFIX}/chowdown/upload", files={"archive": chowdown_zip.open("rb")}, ) assert response.status_code == 200 assert MIGRATION_DIR.joinpath("chowdown", chowdown_zip.name).is_file()
def get_avaiable_nextcloud_imports(): """ Returns a list of avaiable directories that can be imported into Mealie """ response_data = [] migration_dirs = [ MIGRATION_DIR.joinpath("nextcloud"), MIGRATION_DIR.joinpath("chowdown"), ] for directory in migration_dirs: migration = Migrations(type=directory.stem) for zip in directory.iterdir(): if zip.suffix == ".zip": migration_zip = MigrationFile(name=zip.name, date=zip.stat().st_ctime) migration.files.append(migration_zip) response_data.append(migration) migration.files.sort(key=operator.attrgetter("date"), reverse=True) return response_data
def import_nextcloud_directory(type: str, file_name: str, session: Session = Depends(generate_session)): """ Imports all the recipes in a given directory """ file_path = MIGRATION_DIR.joinpath(type, file_name) if type == "nextcloud": return nextcloud_migrate(session, file_path) elif type == "chowdown": return chowdow_migrate(session, file_path) else: return SnackResponse.error("Incorrect Migration Type Selected")
def upload_nextcloud_zipfile(archive: UploadFile = File(...)): """ Upload a .zip File to later be imported into Mealie """ dest = MIGRATION_DIR.joinpath(archive.filename) with dest.open("wb") as buffer: shutil.copyfileobj(archive.file, buffer) if dest.is_file: return SnackResponse.success("Migration data uploaded") else: return SnackResponse.error("Failure uploading file")
def delete_migration_data(type: str, file_name: str): """ Removes migration data from the file system """ remove_path = MIGRATION_DIR.joinpath(type, file_name) if remove_path.is_file(): remove_path.unlink() elif remove_path.is_dir(): shutil.rmtree(remove_path) else: SnackResponse.error("File/Folder not found.") return SnackResponse.error( f"Migration Data Remove: {remove_path.absolute()}")
def migrate(session, selection: str): prep() MIGRATION_DIR.mkdir(exist_ok=True) selection = MIGRATION_DIR.joinpath(selection) nextcloud_dir = process_selection(selection) successful_imports = [] failed_imports = [] for dir in nextcloud_dir.iterdir(): if dir.is_dir(): try: recipe = import_recipes(dir) recipe.save_to_db(session) successful_imports.append(recipe.name) except: logging.error(f"Failed Nextcloud Import: {dir.name}") failed_imports.append(dir.name) cleanup() return {"successful": successful_imports, "failed": failed_imports}