s365b.modules.onedrive.restore ============================== .. py:module:: s365b.modules.onedrive.restore .. autoapi-nested-parse:: Restore files into a OneDrive. Files go back into their folders (created where missing), in the drive they came from or another user's, or under a new folder at the top of the drive. A name already taken is not overwritten: OneDrive gives the restored file a new name ("report 1.pdf"). Restoring into the original folders of the same drive skips files that are still there unchanged. Content is uploaded in pieces through an upload session, so a file is never held in memory whole; its modification time is restored too. A file counts as restored only when OneDrive confirms it complete at its size. A stop request is honoured between files and between pieces of one; what was restored by then is reported. Attributes ---------- .. autoapisummary:: s365b.modules.onedrive.restore.PIECE s365b.modules.onedrive.restore.RENAME s365b.modules.onedrive.restore.PERMISSION_HINT Exceptions ---------- .. autoapisummary:: s365b.modules.onedrive.restore.Stopped Classes ------- .. autoapisummary:: s365b.modules.onedrive.restore.Folders Functions --------- .. autoapisummary:: s365b.modules.onedrive.restore.pieces s365b.modules.onedrive.restore.onedrive_names s365b.modules.onedrive.restore.still_in_place s365b.modules.onedrive.restore.upload s365b.modules.onedrive.restore.restore_files Module Contents --------------- .. py:data:: PIECE :value: 10485760 .. py:data:: RENAME .. py:data:: PERMISSION_HINT :value: 'The Restore app may not write to OneDrive. In Microsoft 365 tenant, choose Update permissions.' .. py:function:: pieces(source: collections.abc.AsyncIterator[bytes], size: int = PIECE) -> collections.abc.AsyncIterator[bytes] :async: Regroup a stream into pieces of exactly ``size`` bytes (the last shorter). :param source: The content, in pieces of any size. :param size: Piece size. :Yields: The pieces. .. py:exception:: Stopped Bases: :py:obj:`Exception` The run was asked to stop during an upload. .. py:function:: onedrive_names(path: str) -> tuple[str, ...] A stored folder path as OneDrive folder names. OneDrive names cannot hold ``/``, so a ``/`` after decoding stood for a real division slash (U+2215) in the name, which goes back as it was. :param path: The stored path. :returns: The folder names. .. py:class:: Folders(graph: s365b.graph.GraphClient, drive: str, created: list[str]) Folders of a drive by path, created when missing. .. py:attribute:: ids :type: dict[tuple[str, ...], str] .. py:method:: ensure(path: tuple[str, ...]) -> str :async: Return the ID of the folder at ``path``, creating what is missing. :param path: Folder names from the drive's root; empty for the root. :returns: The folder's item ID. .. py:function:: still_in_place(reader: s365b.graph.GraphClient, drive: str, item: s365b.modules.sdk.StoredItem) -> bool :async: Whether a file is still where it was backed up, with the same content. Looked up by its backed-up path, so a file whose folder (or a folder above it) was renamed or moved since is not there, and is restored. The file found there counts if it is the same item with the same content tag, or (restored before, so with a new ID) has the same size and content hash. :param reader: Client with read access (the Backup app). :param drive: The drive's ID. :param item: The backed-up file. :returns: True if restoring it would only double it. .. py:function:: upload(graph: s365b.graph.GraphClient, drive: str, folder: str, item: s365b.modules.sdk.StoredItem, cancel: asyncio.Event | None = None) -> None :async: Upload one file into a folder, renamed if the name is taken. :param graph: Client that may write to the drive. :param drive: Drive ID. :param folder: The folder's item ID. :param item: The backed-up file. :param cancel: Set when the run is asked to stop. :raises Stopped: If the run was asked to stop; the upload is abandoned. :raises ModuleError: If OneDrive did not confirm the file complete. .. py:function:: restore_files(ctx: s365b.modules.sdk.ModuleContext, request: s365b.modules.sdk.RestoreRequest) -> s365b.modules.sdk.RestoreResult :async: Upload backed-up files into a drive. Options: ``destination`` is ``"original"`` (the folders they were in) or ``"folder"`` (under a new folder named ``folder_name`` at the top of the drive, keeping the folder structure). :param ctx: Module context with the Restore app's client (and ``reader``). :param request: Files and where to put them. :returns: The outcome. :raises ModuleError: If the options are wrong, the target has no OneDrive or the Restore app may not write to it.