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[ 79 str | None, IOAttrs('man', store_default=False) 80 ] = None 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[ 101 str | None, IOAttrs('em', store_default=False) 102 ] = None 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
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.
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[ 80 str | None, IOAttrs('man', store_default=False) 81 ] = None 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[ 102 str | None, IOAttrs('em', store_default=False) 103 ] = None 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.