bacommon.bacloud

Functionality related to the bacloud tool.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Functionality related to the bacloud tool."""
  4
  5from __future__ import annotations
  6
  7from dataclasses import dataclass
  8from typing import TYPE_CHECKING, Annotated
  9
 10from efro.dataclassio import ioprepped, IOAttrs
 11
 12if TYPE_CHECKING:
 13    pass
 14
 15# Version is sent to the master-server with all commands. Can be incremented
 16# if we need to change behavior server-side to go along with client changes.
 17BACLOUD_VERSION = 8
 18
 19
 20@ioprepped
 21@dataclass
 22class RequestData:
 23    """Request sent to bacloud server."""
 24
 25    command: Annotated[str, IOAttrs('c')]
 26    token: Annotated[str | None, IOAttrs('t')]
 27    payload: Annotated[dict, IOAttrs('p')]
 28    tzoffset: Annotated[float, IOAttrs('z')]
 29    isatty: Annotated[bool, IOAttrs('y')]
 30
 31
 32@ioprepped
 33@dataclass
 34class ResponseData:
 35    # noinspection PyUnresolvedReferences
 36    """Response sent from the bacloud server to the client.
 37
 38    Attributes:
 39      message: If present, client should print this message before any other
 40        response processing (including error handling) occurs.
 41      message_end: end arg for message print() call.
 42      error: If present, client should abort with this error message.
 43      delay_seconds: How long to wait before proceeding with remaining
 44        response (can be useful when waiting for server progress in a loop).
 45      login: If present, a token that should be stored client-side and passed
 46        with subsequent commands.
 47      logout: If True, any existing client-side token should be discarded.
 48      dir_manifest: If present, client should generate a manifest of this dir.
 49        It should be added to end_command args as 'manifest'.
 50      uploads: If present, client should upload the requested files (arg1)
 51        individually to a server command (arg2) with provided args (arg3).
 52      uploads_inline: If present, a list of pathnames that should be base64
 53        gzipped and uploaded to an 'uploads_inline' dict in end_command args.
 54        This should be limited to relatively small files.
 55      deletes: If present, file paths that should be deleted on the client.
 56      downloads_inline: If present, pathnames mapped to base64 gzipped data to
 57        be written to the client. This should only be used for relatively
 58        small files as they are all included inline as part of the response.
 59      dir_prune_empty: If present, all empty dirs under this one should be
 60        removed.
 61      open_url: If present, url to display to the user.
 62      input_prompt: If present, a line of input is read and placed into
 63        end_command args as 'input'. The first value is the prompt printed
 64        before reading and the second is whether it should be read as a
 65        password (without echoing to the terminal).
 66      end_message: If present, a message that should be printed after all other
 67        response processing is done.
 68      end_message_end: end arg for end_message print() call.
 69      end_command: If present, this command is run with these args at the end
 70        of response processing.
 71    """
 72    message: Annotated[str | None, IOAttrs('m', store_default=False)] = None
 73    message_end: Annotated[str, IOAttrs('m_end', store_default=False)] = '\n'
 74    error: Annotated[str | None, IOAttrs('e', store_default=False)] = None
 75    delay_seconds: Annotated[float, IOAttrs('d', store_default=False)] = 0.0
 76    login: Annotated[str | None, IOAttrs('l', store_default=False)] = None
 77    logout: Annotated[bool, IOAttrs('lo', store_default=False)] = False
 78    dir_manifest: Annotated[str | None, IOAttrs('man', store_default=False)] = (
 79        None
 80    )
 81    uploads: Annotated[
 82        tuple[list[str], str, dict] | None, IOAttrs('u', store_default=False)
 83    ] = None
 84    uploads_inline: Annotated[
 85        list[str] | None, IOAttrs('uinl', store_default=False)
 86    ] = None
 87    deletes: Annotated[
 88        list[str] | None, IOAttrs('dlt', store_default=False)
 89    ] = None
 90    downloads_inline: Annotated[
 91        dict[str, str] | None, IOAttrs('dinl', store_default=False)
 92    ] = None
 93    dir_prune_empty: Annotated[
 94        str | None, IOAttrs('dpe', store_default=False)
 95    ] = None
 96    open_url: Annotated[str | None, IOAttrs('url', store_default=False)] = None
 97    input_prompt: Annotated[
 98        tuple[str, bool] | None, IOAttrs('inp', store_default=False)
 99    ] = None
100    end_message: Annotated[str | None, IOAttrs('em', store_default=False)] = (
101        None
102    )
103    end_message_end: Annotated[str, IOAttrs('eme', store_default=False)] = '\n'
104    end_command: Annotated[
105        tuple[str, dict] | None, IOAttrs('ec', store_default=False)
106    ] = None
BACLOUD_VERSION = 8
@ioprepped
@dataclass
class RequestData:
21@ioprepped
22@dataclass
23class RequestData:
24    """Request sent to bacloud server."""
25
26    command: Annotated[str, IOAttrs('c')]
27    token: Annotated[str | None, IOAttrs('t')]
28    payload: Annotated[dict, IOAttrs('p')]
29    tzoffset: Annotated[float, IOAttrs('z')]
30    isatty: Annotated[bool, IOAttrs('y')]

Request sent to bacloud server.

RequestData( command: Annotated[str, <efro.dataclassio._base.IOAttrs object>], token: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>], payload: Annotated[dict, <efro.dataclassio._base.IOAttrs object>], tzoffset: Annotated[float, <efro.dataclassio._base.IOAttrs object>], isatty: Annotated[bool, <efro.dataclassio._base.IOAttrs object>])
command: Annotated[str, <efro.dataclassio._base.IOAttrs object at 0x10392ade0>]
token: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x10392b800>]
payload: Annotated[dict, <efro.dataclassio._base.IOAttrs object at 0x10392a2a0>]
tzoffset: Annotated[float, <efro.dataclassio._base.IOAttrs object at 0x10392b6e0>]
isatty: Annotated[bool, <efro.dataclassio._base.IOAttrs object at 0x10392ae70>]
@ioprepped
@dataclass
class ResponseData:
 33@ioprepped
 34@dataclass
 35class ResponseData:
 36    # noinspection PyUnresolvedReferences
 37    """Response sent from the bacloud server to the client.
 38
 39    Attributes:
 40      message: If present, client should print this message before any other
 41        response processing (including error handling) occurs.
 42      message_end: end arg for message print() call.
 43      error: If present, client should abort with this error message.
 44      delay_seconds: How long to wait before proceeding with remaining
 45        response (can be useful when waiting for server progress in a loop).
 46      login: If present, a token that should be stored client-side and passed
 47        with subsequent commands.
 48      logout: If True, any existing client-side token should be discarded.
 49      dir_manifest: If present, client should generate a manifest of this dir.
 50        It should be added to end_command args as 'manifest'.
 51      uploads: If present, client should upload the requested files (arg1)
 52        individually to a server command (arg2) with provided args (arg3).
 53      uploads_inline: If present, a list of pathnames that should be base64
 54        gzipped and uploaded to an 'uploads_inline' dict in end_command args.
 55        This should be limited to relatively small files.
 56      deletes: If present, file paths that should be deleted on the client.
 57      downloads_inline: If present, pathnames mapped to base64 gzipped data to
 58        be written to the client. This should only be used for relatively
 59        small files as they are all included inline as part of the response.
 60      dir_prune_empty: If present, all empty dirs under this one should be
 61        removed.
 62      open_url: If present, url to display to the user.
 63      input_prompt: If present, a line of input is read and placed into
 64        end_command args as 'input'. The first value is the prompt printed
 65        before reading and the second is whether it should be read as a
 66        password (without echoing to the terminal).
 67      end_message: If present, a message that should be printed after all other
 68        response processing is done.
 69      end_message_end: end arg for end_message print() call.
 70      end_command: If present, this command is run with these args at the end
 71        of response processing.
 72    """
 73    message: Annotated[str | None, IOAttrs('m', store_default=False)] = None
 74    message_end: Annotated[str, IOAttrs('m_end', store_default=False)] = '\n'
 75    error: Annotated[str | None, IOAttrs('e', store_default=False)] = None
 76    delay_seconds: Annotated[float, IOAttrs('d', store_default=False)] = 0.0
 77    login: Annotated[str | None, IOAttrs('l', store_default=False)] = None
 78    logout: Annotated[bool, IOAttrs('lo', store_default=False)] = False
 79    dir_manifest: Annotated[str | None, IOAttrs('man', store_default=False)] = (
 80        None
 81    )
 82    uploads: Annotated[
 83        tuple[list[str], str, dict] | None, IOAttrs('u', store_default=False)
 84    ] = None
 85    uploads_inline: Annotated[
 86        list[str] | None, IOAttrs('uinl', store_default=False)
 87    ] = None
 88    deletes: Annotated[
 89        list[str] | None, IOAttrs('dlt', store_default=False)
 90    ] = None
 91    downloads_inline: Annotated[
 92        dict[str, str] | None, IOAttrs('dinl', store_default=False)
 93    ] = None
 94    dir_prune_empty: Annotated[
 95        str | None, IOAttrs('dpe', store_default=False)
 96    ] = None
 97    open_url: Annotated[str | None, IOAttrs('url', store_default=False)] = None
 98    input_prompt: Annotated[
 99        tuple[str, bool] | None, IOAttrs('inp', store_default=False)
100    ] = None
101    end_message: Annotated[str | None, IOAttrs('em', store_default=False)] = (
102        None
103    )
104    end_message_end: Annotated[str, IOAttrs('eme', store_default=False)] = '\n'
105    end_command: Annotated[
106        tuple[str, dict] | None, IOAttrs('ec', store_default=False)
107    ] = None

Response sent from the bacloud server to the client.

Attributes: message: If present, client should print this message before any other response processing (including error handling) occurs. message_end: end arg for message print() call. error: If present, client should abort with this error message. delay_seconds: How long to wait before proceeding with remaining response (can be useful when waiting for server progress in a loop). login: If present, a token that should be stored client-side and passed with subsequent commands. logout: If True, any existing client-side token should be discarded. dir_manifest: If present, client should generate a manifest of this dir. It should be added to end_command args as 'manifest'. uploads: If present, client should upload the requested files (arg1) individually to a server command (arg2) with provided args (arg3). uploads_inline: If present, a list of pathnames that should be base64 gzipped and uploaded to an 'uploads_inline' dict in end_command args. This should be limited to relatively small files. deletes: If present, file paths that should be deleted on the client. downloads_inline: If present, pathnames mapped to base64 gzipped data to be written to the client. This should only be used for relatively small files as they are all included inline as part of the response. dir_prune_empty: If present, all empty dirs under this one should be removed. open_url: If present, url to display to the user. input_prompt: If present, a line of input is read and placed into end_command args as 'input'. The first value is the prompt printed before reading and the second is whether it should be read as a password (without echoing to the terminal). end_message: If present, a message that should be printed after all other response processing is done. end_message_end: end arg for end_message print() call. end_command: If present, this command is run with these args at the end of response processing.

ResponseData( message: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, message_end: Annotated[str, <efro.dataclassio._base.IOAttrs object>] = '\n', error: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, delay_seconds: Annotated[float, <efro.dataclassio._base.IOAttrs object>] = 0.0, login: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, logout: Annotated[bool, <efro.dataclassio._base.IOAttrs object>] = False, dir_manifest: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, uploads: Annotated[tuple[list[str], str, dict] | None, <efro.dataclassio._base.IOAttrs object>] = None, uploads_inline: Annotated[list[str] | None, <efro.dataclassio._base.IOAttrs object>] = None, deletes: Annotated[list[str] | None, <efro.dataclassio._base.IOAttrs object>] = None, downloads_inline: Annotated[dict[str, str] | None, <efro.dataclassio._base.IOAttrs object>] = None, dir_prune_empty: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, open_url: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, input_prompt: Annotated[tuple[str, bool] | None, <efro.dataclassio._base.IOAttrs object>] = None, end_message: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, end_message_end: Annotated[str, <efro.dataclassio._base.IOAttrs object>] = '\n', end_command: Annotated[tuple[str, dict] | None, <efro.dataclassio._base.IOAttrs object>] = None)
message: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x103de6450>] = None
message_end: Annotated[str, <efro.dataclassio._base.IOAttrs object at 0x103de6960>] = '\n'
error: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x1040138c0>] = None
delay_seconds: Annotated[float, <efro.dataclassio._base.IOAttrs object at 0x104010b30>] = 0.0
login: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x104012180>] = None
logout: Annotated[bool, <efro.dataclassio._base.IOAttrs object at 0x104012510>] = False
dir_manifest: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x1040125a0>] = None
uploads: Annotated[tuple[list[str], str, dict] | None, <efro.dataclassio._base.IOAttrs object at 0x1040127e0>] = None
uploads_inline: Annotated[list[str] | None, <efro.dataclassio._base.IOAttrs object at 0x104012cf0>] = None
deletes: Annotated[list[str] | None, <efro.dataclassio._base.IOAttrs object at 0x104012e10>] = None
downloads_inline: Annotated[dict[str, str] | None, <efro.dataclassio._base.IOAttrs object at 0x104012ff0>] = None
dir_prune_empty: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x1040131a0>] = None
open_url: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x104013320>] = None
input_prompt: Annotated[tuple[str, bool] | None, <efro.dataclassio._base.IOAttrs object at 0x104013560>] = None
end_message: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x1040136b0>] = None
end_message_end: Annotated[str, <efro.dataclassio._base.IOAttrs object at 0x104013920>] = '\n'
end_command: Annotated[tuple[str, dict] | None, <efro.dataclassio._base.IOAttrs object at 0x1040139b0>] = None