1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-20 06:28:09 +00:00

refactor(python): rename NewTrezorConnection to TrezorConnection

[no changelog]
This commit is contained in:
M1nd3r 2024-11-19 17:50:17 +01:00
parent e7c1f5b3ec
commit d219578d43
7 changed files with 22 additions and 22 deletions

View File

@ -101,7 +101,7 @@ def get_passphrase(
raise exceptions.Cancelled from None
class NewTrezorConnection:
class TrezorConnection:
def __init__(
self,
@ -297,7 +297,7 @@ def with_session(
@click.pass_obj
@functools.wraps(func)
def function_with_session(
obj: NewTrezorConnection, *args: "P.args", **kwargs: "P.kwargs"
obj: TrezorConnection, *args: "P.args", **kwargs: "P.kwargs"
) -> "R":
session = obj.get_session(derive_cardano)
try:
@ -316,7 +316,7 @@ def with_management_session(
@click.pass_obj
@functools.wraps(func)
def function_with_management_session(
obj: NewTrezorConnection, *args: "P.args", **kwargs: "P.kwargs"
obj: TrezorConnection, *args: "P.args", **kwargs: "P.kwargs"
) -> "R":
session = obj.get_management_session()
try:
@ -341,7 +341,7 @@ def with_client(
@click.pass_obj
@functools.wraps(func)
def trezorctl_command_with_client(
obj: NewTrezorConnection, *args: "P.args", **kwargs: "P.kwargs"
obj: TrezorConnection, *args: "P.args", **kwargs: "P.kwargs"
) -> "R":
with obj.client_context() as client:
# session_was_resumed = obj.session_id == client.session_id

View File

@ -26,7 +26,7 @@ from ..transport.session import Session
from . import with_management_session
if TYPE_CHECKING:
from . import NewTrezorConnection
from . import TrezorConnection
@click.group(name="debug")
@ -85,7 +85,7 @@ def cli() -> None:
@click.argument("directory", required=False)
@click.option("-s", "--stop", is_flag=True, help="Stop the recording")
@click.pass_obj
def record(obj: "NewTrezorConnection", directory: Union[str, None], stop: bool) -> None:
def record(obj: "TrezorConnection", directory: Union[str, None], stop: bool) -> None:
"""Record screen changes into a specified directory.
Recording can be stopped with `-s / --stop` option.
@ -94,7 +94,7 @@ def record(obj: "NewTrezorConnection", directory: Union[str, None], stop: bool)
def record_screen_from_connection(
obj: "NewTrezorConnection", directory: Union[str, None]
obj: "TrezorConnection", directory: Union[str, None]
) -> None:
"""Record screen helper to transform TrezorConnection into TrezorClientDebugLink."""
transport = obj.get_transport()

View File

@ -29,7 +29,7 @@ from . import ChoiceType, with_management_session
if t.TYPE_CHECKING:
from ..protobuf import MessageType
from ..transport.session import Session
from . import NewTrezorConnection
from . import TrezorConnection
RECOVERY_DEVICE_INPUT_METHOD = {
"scrambled": messages.RecoveryDeviceInputMethod.ScrambledWords,
@ -315,7 +315,7 @@ def sd_protect(session: "Session", operation: messages.SdProtectOperationType) -
@cli.command()
@click.pass_obj
def reboot_to_bootloader(obj: "NewTrezorConnection") -> str:
def reboot_to_bootloader(obj: "TrezorConnection") -> str:
"""Reboot device into bootloader mode.
Currently only supported on Trezor Model One.

View File

@ -42,7 +42,7 @@ from . import ChoiceType, with_management_session
if TYPE_CHECKING:
from ..client import TrezorClient
from ..transport.session import Session
from . import NewTrezorConnection
from . import TrezorConnection
MODEL_CHOICE = ChoiceType(
{
@ -521,7 +521,7 @@ def cli() -> None:
@click.pass_obj
# fmt: on
def verify(
obj: "NewTrezorConnection",
obj: "TrezorConnection",
filename: BinaryIO,
check_device: bool,
fingerprint: Optional[str],
@ -566,7 +566,7 @@ def verify(
@click.pass_obj
# fmt: on
def download(
obj: "NewTrezorConnection",
obj: "TrezorConnection",
output: Optional[BinaryIO],
model: Optional[TrezorModel],
version: Optional[str],
@ -632,7 +632,7 @@ def download(
# fmt: on
@click.pass_obj
def update(
obj: "NewTrezorConnection",
obj: "TrezorConnection",
filename: Optional[BinaryIO],
url: Optional[str],
version: Optional[str],

View File

@ -32,7 +32,7 @@ from ..transport.thp import channel_database
from ..transport.udp import UdpTransport
from . import (
AliasedGroup,
NewTrezorConnection,
TrezorConnection,
benchmark,
binance,
btc,
@ -218,7 +218,7 @@ def cli_main(
raise click.ClickException(f"Not a valid session id: {session_id}")
# ctx.obj = TrezorConnection(path, bytes_session_id, passphrase_on_host, script)
ctx.obj = NewTrezorConnection(path, bytes_session_id, passphrase_on_host, script)
ctx.obj = TrezorConnection(path, bytes_session_id, passphrase_on_host, script)
# Optionally record the screen into a specified directory.
if record:
@ -259,7 +259,7 @@ def print_result(res: Any, is_json: bool, script: bool, **kwargs: Any) -> None:
@cli.set_result_callback()
@click.pass_obj
def stop_recording_action(obj: NewTrezorConnection, *args: Any, **kwargs: Any) -> None:
def stop_recording_action(obj: TrezorConnection, *args: Any, **kwargs: Any) -> None:
"""Stop recording screen changes when the recording was started by `cli_main`.
(When user used the `-r / --record` option of `trezorctl` command.)
@ -346,7 +346,7 @@ def ping(session: "Session", message: str, button_protection: bool) -> str:
@cli.command()
@click.pass_obj
def get_session(
obj: NewTrezorConnection, passphrase: str = "", derive_cardano: bool = False
obj: TrezorConnection, passphrase: str = "", derive_cardano: bool = False
) -> str:
"""Get a session ID for subsequent commands.
@ -414,7 +414,7 @@ def usb_reset() -> None:
@cli.command()
@click.option("-t", "--timeout", type=float, default=10, help="Timeout in seconds")
@click.pass_obj
def wait_for_emulator(obj: NewTrezorConnection, timeout: float) -> None:
def wait_for_emulator(obj: TrezorConnection, timeout: float) -> None:
"""Wait until Trezor Emulator comes up.
Tries to connect to emulator and returns when it succeeds.

View File

@ -8,8 +8,8 @@ from .protocol_and_channel import ProtocolAndChannel
LOG = logging.getLogger(__name__)
if False:
from appdirs import user_cache_dir, user_config_dir
if True:
from platformdirs import user_cache_dir, user_config_dir
APP_NAME = "@trezor" # TODO
DATA_PATH = os.path.join(user_cache_dir(appname=APP_NAME), "channel_data.json")

View File

@ -63,7 +63,7 @@ MODULES = (
CALLS_DONE = []
DEBUGLINK = None
get_client_orig = cli.NewTrezorConnection.get_client
get_client_orig = cli.TrezorConnection.get_client
def get_client(conn):
@ -75,7 +75,7 @@ def get_client(conn):
return client
cli.NewTrezorConnection.get_client = get_client
cli.TrezorConnection.get_client = get_client
def scan_layouts(dest):