Пример #1
0
async def delete_immediately_batch(
    namespace: Namespace,
    paths: Iterable[StrOrPath],
) -> list[FileTaskResult]:
    """
    Permanently delete a file or a folder with all of its contents.

    Args:
        namespace (Namespace): Namespace where file/folder should be deleted.
        paths (Iterable[StrOrPath]): Iterable of pathnames to delete.

    Returns:
        list[FileTaskResult]: List, where each item contains either a moved file
            or an error code.
    """
    results = []
    async with db.create_client() as conn:
        for path in paths:
            file, err_code = None, None

            try:
                file = await actions.delete_immediately(conn, namespace, path)
            except errors.FileNotFound:
                err_code = errors.ErrorCode.file_not_found
            except Exception:
                err_code = errors.ErrorCode.internal
                logger.exception("Unexpectedly failed to delete a file")

            results.append(FileTaskResult(file=file, err_code=err_code))
    return results
Пример #2
0
async def move_batch(
    namespace: Namespace,
    relocations: Iterable[RelocationPath],
) -> list[FileTaskResult]:
    """
    Move several files/folders to a different locations

    Args:
        namespace (Namespace): Namespace, where files should be moved.
        relocations (Iterable[RelocationPath]): Iterable, where each item contains
            current file path and path to move file to.

    Returns:
        list[FileTaskResult]: List, where each item contains either a moved file
            or an error code.
    """
    results = []
    async with db.create_client() as conn:
        for relocation in relocations:
            path, next_path = relocation.from_path, relocation.to_path
            file, err_code = None, None

            try:
                file = await actions.move(conn, namespace, path, next_path)
            except errors.Error as exc:
                err_code = exc.code
            except Exception:
                err_code = errors.ErrorCode.internal
                logger.exception("Unexpectedly failed to move file")

            results.append(FileTaskResult(file=file, err_code=err_code))
    return results
Пример #3
0
async def move_to_trash_batch(
    namespace: Namespace,
    paths: Iterable[StrOrPath],
) -> list[FileTaskResult]:
    """
    Move several files to trash asynchronously.

    Args:
        namespace (Namespace): Namespace, where files should be moved to trash
        paths (Iterable[StrOrPath]): Iterable of pathnames to move to trash.

    Returns:
        list[FileTaskResult]: List, where each item contains either a moved file
            or an error code.
    """
    results = []
    async with db.create_client() as conn:
        for path in paths:
            file, err_code = None, None

            try:
                file = await actions.move_to_trash(conn, namespace, path)
            except errors.Error as exc:
                err_code = exc.code
            except Exception:
                err_code = errors.ErrorCode.internal
                logger.exception("Unexpectedly failed to move file to trash")

            results.append(FileTaskResult(file=file, err_code=err_code))
    return results
Пример #4
0
async def empty_trash(namespace: Namespace) -> None:
    """
    Delete all files and folders in the Trash folder within a target Namespace.

    Args:
        namespace (Namespace): Namespace where Trash should be emptied.
    """
    async with db.create_client() as conn:
        await actions.empty_trash(conn, namespace)
Пример #5
0
 async def run_migration(schema: str) -> None:
     async with db.create_client() as conn:
         await db.migrate(conn, schema)
Пример #6
0
 async def _reconcile():
     async with db.create_client(max_concurrency=None) as db_client:
         ns = await crud.namespace.get(db_client, namespace)
         await actions.reconcile(db_client, ns)
Пример #7
0
 async def _createuser(username: str, password: str):
     async with db.create_client() as conn:
         await actions.create_account(conn,
                                      username,
                                      password,
                                      superuser=True)