Skip to content

Commit

Permalink
AdbRemote
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-usielski committed Oct 28, 2024
1 parent f77ad6b commit 1622eb7
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 84 deletions.
180 changes: 97 additions & 83 deletions moler/device/adbremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import logging

from moler.device.textualdevice import TextualDevice
# from moler.device.proxy_pc import ProxyPc # TODO: allow jumping towards ADB_REMOTE via proxy-pc
from moler.device.unixlocal import UnixLocal
from moler.device.unixremote import UnixRemote
from moler.cmd.adb.adb_shell import AdbShell
from moler.helpers import call_base_class_method_with_same_name, mark_to_call_base_class_method_with_same_name
Expand Down Expand Up @@ -86,7 +84,7 @@ def _get_default_sm_configuration_without_proxy_pc(self):
"""
config = { # TODO: shell we use direct-string names of config dicts? change simplicity vs readability
TextualDevice.connection_hops: {
UnixRemote.unix_remote: { # from
AdbRemote.unix_remote: { # from
AdbRemote.adb_shell: { # to
"execute_command": "adb_shell",
"command_params": { # with parameters
Expand All @@ -99,7 +97,7 @@ def _get_default_sm_configuration_without_proxy_pc(self):
},
},
AdbRemote.adb_shell: { # from
UnixRemote.unix_remote: { # to
AdbRemote.unix_remote: { # to
"execute_command": "exit", # using command
"command_params": { # with parameters
"expected_prompt": r'remote_user_prompt', # overwritten in _configure_state_machine()
Expand Down Expand Up @@ -143,7 +141,7 @@ def _get_default_sm_configuration_with_proxy_pc(self):
"""
config = { # TODO: shell we use direct-string names of config dicts? change simplicity vs readability
TextualDevice.connection_hops: {
UnixRemote.unix_remote: { # from
AdbRemote.unix_remote: { # from
AdbRemote.adb_shell: { # to
"execute_command": "adb_shell",
"command_params": { # with parameters
Expand All @@ -156,7 +154,7 @@ def _get_default_sm_configuration_with_proxy_pc(self):
},
},
AdbRemote.adb_shell: { # from
UnixRemote.unix_remote: { # to
AdbRemote.unix_remote: { # to
"execute_command": "exit", # using command
"command_params": { # with parameters
"expected_prompt": r'remote_user_prompt', # overwritten in _configure_state_machine()
Expand Down Expand Up @@ -199,15 +197,15 @@ def _prepare_transitions_with_proxy_pc(self):
:return: transitions without proxy_pc state.
"""
transitions = {
UnixRemote.unix_remote: {
AdbRemote.unix_remote: {
AdbRemote.adb_shell: {
"action": [
"_execute_command_to_change_state"
],
}
},
AdbRemote.adb_shell: {
UnixRemote.unix_remote: {
AdbRemote.unix_remote: {
"action": [
"_execute_command_to_change_state"
],
Expand Down Expand Up @@ -235,15 +233,15 @@ def _prepare_transitions_without_proxy_pc(self):
:return: transitions without proxy_pc state.
"""
transitions = {
UnixRemote.unix_remote: {
AdbRemote.unix_remote: {
AdbRemote.adb_shell: {
"action": [
"_execute_command_to_change_state"
],
}
},
AdbRemote.adb_shell: {
UnixRemote.unix_remote: {
AdbRemote.unix_remote: {
"action": [
"_execute_command_to_change_state"
],
Expand Down Expand Up @@ -271,7 +269,7 @@ def _prepare_state_prompts_without_proxy_pc(self):
:return: textual prompt for each state without proxy_pc state.
"""
hops_config = self._configurations[TextualDevice.connection_hops]
cfg_ux2adb = hops_config[UnixRemote.unix_remote][AdbRemote.adb_shell]
cfg_ux2adb = hops_config[AdbRemote.unix_remote][AdbRemote.adb_shell]
cfg_adb2adbroot = hops_config[AdbRemote.adb_shell][AdbRemote.adb_shell_root]
adb_shell_cmd_params = cfg_ux2adb["command_params"]
adb_shell_prompt = self._get_adb_shell_prompt(adb_shell_cmd_params)
Expand All @@ -298,7 +296,7 @@ def _prepare_state_prompts_with_proxy_pc(self):
:return: textual prompt for each state without proxy_pc state.
"""
hops_config = self._configurations[TextualDevice.connection_hops]
cfg_ux2adb = hops_config[UnixRemote.unix_remote][AdbRemote.adb_shell]
cfg_ux2adb = hops_config[AdbRemote.unix_remote][AdbRemote.adb_shell]
cfg_adb2adbroot = hops_config[AdbRemote.adb_shell][AdbRemote.adb_shell_root]
adb_shell_cmd_params = cfg_ux2adb["command_params"]
adb_shell_prompt = self._get_adb_shell_prompt(adb_shell_cmd_params)
Expand Down Expand Up @@ -326,7 +324,7 @@ def _serial_number(self):
:return: serial_number.
"""
hops_config = self._configurations[TextualDevice.connection_hops]
cfg_ux2adb = hops_config[UnixRemote.unix_remote][AdbRemote.adb_shell]
cfg_ux2adb = hops_config[AdbRemote.unix_remote][AdbRemote.adb_shell]
serial_number = cfg_ux2adb["command_params"]["serial_number"]
return serial_number

Expand All @@ -346,7 +344,7 @@ def _prepare_newline_chars_without_proxy_pc(self):
:return: newline char for each state without proxy_pc state.
"""
hops_config = self._configurations[TextualDevice.connection_hops]
cfg_ux2adb = hops_config[UnixRemote.unix_remote][AdbRemote.adb_shell]
cfg_ux2adb = hops_config[AdbRemote.unix_remote][AdbRemote.adb_shell]
cfg_adb2adbroot = hops_config[AdbRemote.adb_shell][AdbRemote.adb_shell_root]
adb_shell_newline = cfg_ux2adb["command_params"]["target_newline"]
adb_shell_root_newline = cfg_adb2adbroot["command_params"]["target_newline"]
Expand All @@ -366,7 +364,7 @@ def _prepare_newline_chars_with_proxy_pc(self):
:return: newline char for each state without proxy_pc state.
"""
hops_config = self._configurations[TextualDevice.connection_hops]
cfg_ux2adb = hops_config[UnixRemote.unix_remote][AdbRemote.adb_shell]
cfg_ux2adb = hops_config[AdbRemote.unix_remote][AdbRemote.adb_shell]
cfg_adb2adbroot = hops_config[AdbRemote.adb_shell][AdbRemote.adb_shell_root]
adb_shell_newline = cfg_ux2adb["command_params"]["target_newline"]
adb_shell_root_newline = cfg_adb2adbroot["command_params"]["target_newline"]
Expand All @@ -387,48 +385,48 @@ def _prepare_state_hops_without_proxy_pc(self):
"""
state_hops = {
TextualDevice.not_connected: {
UnixLocal.unix_local_root: UnixLocal.unix_local,
UnixRemote.unix_remote: UnixLocal.unix_local,
UnixRemote.unix_remote_root: UnixLocal.unix_local,
AdbRemote.adb_shell: UnixLocal.unix_local,
AdbRemote.adb_shell_root: UnixLocal.unix_local,
AdbRemote.unix_local_root: AdbRemote.unix_local,
AdbRemote.unix_remote: AdbRemote.unix_local,
AdbRemote.unix_remote_root: AdbRemote.unix_local,
AdbRemote.adb_shell: AdbRemote.unix_local,
AdbRemote.adb_shell_root: AdbRemote.unix_local,
},
UnixLocal.unix_local: {
UnixRemote.unix_remote_root: UnixRemote.unix_remote,
AdbRemote.adb_shell: UnixRemote.unix_remote,
AdbRemote.adb_shell_root: UnixRemote.unix_remote,
AdbRemote.unix_local: {
AdbRemote.unix_remote_root: AdbRemote.unix_remote,
AdbRemote.adb_shell: AdbRemote.unix_remote,
AdbRemote.adb_shell_root: AdbRemote.unix_remote,
},
UnixLocal.unix_local_root: {
TextualDevice.not_connected: UnixLocal.unix_local,
UnixRemote.unix_remote: UnixLocal.unix_local,
UnixRemote.unix_remote_root: UnixLocal.unix_local,
AdbRemote.adb_shell: UnixLocal.unix_local,
AdbRemote.adb_shell_root: UnixLocal.unix_local,
AdbRemote.unix_local_root: {
TextualDevice.not_connected: AdbRemote.unix_local,
AdbRemote.unix_remote: AdbRemote.unix_local,
AdbRemote.unix_remote_root: AdbRemote.unix_local,
AdbRemote.adb_shell: AdbRemote.unix_local,
AdbRemote.adb_shell_root: AdbRemote.unix_local,
},
UnixRemote.unix_remote: {
TextualDevice.not_connected: UnixLocal.unix_local,
UnixLocal.unix_local_root: UnixLocal.unix_local,
AdbRemote.unix_remote: {
TextualDevice.not_connected: AdbRemote.unix_local,
AdbRemote.unix_local_root: AdbRemote.unix_local,
AdbRemote.adb_shell_root: AdbRemote.adb_shell,
},
UnixRemote.unix_remote_root: {
TextualDevice.not_connected: UnixRemote.unix_remote,
UnixLocal.unix_local: UnixRemote.unix_remote,
UnixLocal.unix_local_root: UnixRemote.unix_remote,
AdbRemote.adb_shell: UnixRemote.unix_remote,
AdbRemote.adb_shell_root: UnixRemote.unix_remote,
AdbRemote.unix_remote_root: {
TextualDevice.not_connected: AdbRemote.unix_remote,
AdbRemote.unix_local: AdbRemote.unix_remote,
AdbRemote.unix_local_root: AdbRemote.unix_remote,
AdbRemote.adb_shell: AdbRemote.unix_remote,
AdbRemote.adb_shell_root: AdbRemote.unix_remote,
},
AdbRemote.adb_shell: {
TextualDevice.not_connected: UnixRemote.unix_remote,
UnixLocal.unix_local: UnixRemote.unix_remote,
UnixLocal.unix_local_root: UnixRemote.unix_remote,
UnixRemote.unix_remote_root: UnixRemote.unix_remote,
TextualDevice.not_connected: AdbRemote.unix_remote,
AdbRemote.unix_local: AdbRemote.unix_remote,
AdbRemote.unix_local_root: AdbRemote.unix_remote,
AdbRemote.unix_remote_root: AdbRemote.unix_remote,
},
AdbRemote.adb_shell_root: {
TextualDevice.not_connected: AdbRemote.adb_shell,
UnixLocal.unix_local: AdbRemote.adb_shell,
UnixLocal.unix_local_root: AdbRemote.adb_shell,
UnixRemote.unix_remote: AdbRemote.adb_shell,
UnixRemote.unix_remote_root: AdbRemote.adb_shell,
AdbRemote.unix_local: AdbRemote.adb_shell,
AdbRemote.unix_local_root: AdbRemote.adb_shell,
AdbRemote.unix_remote: AdbRemote.adb_shell,
AdbRemote.unix_remote_root: AdbRemote.adb_shell,
},
}
return state_hops
Expand All @@ -441,49 +439,62 @@ def _prepare_state_hops_with_proxy_pc(self):
"""
state_hops = {
TextualDevice.not_connected: {
UnixLocal.unix_local_root: UnixLocal.unix_local,
UnixRemote.unix_remote: UnixLocal.unix_local,
UnixRemote.unix_remote_root: UnixLocal.unix_local,
AdbRemote.adb_shell: UnixLocal.unix_local,
AdbRemote.adb_shell_root: UnixLocal.unix_local,
AdbRemote.unix_local_root: AdbRemote.unix_local,
AdbRemote.proxy_pc: AdbRemote.unix_local,
AdbRemote.unix_remote: AdbRemote.unix_local,
AdbRemote.unix_remote_root: AdbRemote.unix_local,
AdbRemote.adb_shell: AdbRemote.unix_local,
AdbRemote.adb_shell_root: AdbRemote.unix_local,
},
UnixLocal.unix_local: {
UnixRemote.unix_remote_root: UnixRemote.unix_remote,
AdbRemote.adb_shell: UnixRemote.unix_remote,
AdbRemote.adb_shell_root: UnixRemote.unix_remote,
AdbRemote.unix_local: {
AdbRemote.unix_remote_root: AdbRemote.proxy_pc,
AdbRemote.adb_shell: AdbRemote.proxy_pc,
AdbRemote.adb_shell_root: AdbRemote.proxy_pc,
},
UnixLocal.unix_local_root: {
TextualDevice.not_connected: UnixLocal.unix_local,
UnixRemote.unix_remote: UnixLocal.unix_local,
UnixRemote.unix_remote_root: UnixLocal.unix_local,
AdbRemote.adb_shell: UnixLocal.unix_local,
AdbRemote.adb_shell_root: UnixLocal.unix_local,
AdbRemote.unix_local_root: {
TextualDevice.not_connected: AdbRemote.unix_local,
AdbRemote.proxy_pc: AdbRemote.unix_local,
AdbRemote.unix_remote: AdbRemote.unix_local,
AdbRemote.unix_remote_root: AdbRemote.unix_local,
AdbRemote.adb_shell: AdbRemote.unix_local,
AdbRemote.adb_shell_root: AdbRemote.unix_local,
},
UnixRemote.unix_remote: {
TextualDevice.not_connected: UnixLocal.unix_local,
UnixLocal.unix_local_root: UnixLocal.unix_local,
AdbRemote.unix_remote: {
AdbRemote.unix_local: AdbRemote.proxy_pc,
TextualDevice.not_connected: AdbRemote.proxy_pc,
AdbRemote.unix_local_root: AdbRemote.proxy_pc,
AdbRemote.adb_shell_root: AdbRemote.adb_shell,
},
UnixRemote.unix_remote_root: {
TextualDevice.not_connected: UnixRemote.unix_remote,
UnixLocal.unix_local: UnixRemote.unix_remote,
UnixLocal.unix_local_root: UnixRemote.unix_remote,
AdbRemote.adb_shell: UnixRemote.unix_remote,
AdbRemote.adb_shell_root: UnixRemote.unix_remote,
AdbRemote.unix_remote_root: {
TextualDevice.not_connected: AdbRemote.unix_remote,
AdbRemote.proxy_pc: AdbRemote.unix_remote,
AdbRemote.unix_local: AdbRemote.unix_remote,
AdbRemote.unix_local_root: AdbRemote.unix_remote,
AdbRemote.adb_shell: AdbRemote.unix_remote,
AdbRemote.adb_shell_root: AdbRemote.unix_remote,
},
AdbRemote.adb_shell: {
TextualDevice.not_connected: UnixRemote.unix_remote,
UnixLocal.unix_local: UnixRemote.unix_remote,
UnixLocal.unix_local_root: UnixRemote.unix_remote,
UnixRemote.unix_remote_root: UnixRemote.unix_remote,
TextualDevice.not_connected: AdbRemote.unix_remote,
AdbRemote.proxy_pc: AdbRemote.unix_remote,
AdbRemote.unix_local: AdbRemote.unix_remote,
AdbRemote.unix_local_root: AdbRemote.unix_remote,
AdbRemote.unix_remote_root: AdbRemote.unix_remote,
},
AdbRemote.adb_shell_root: {
TextualDevice.not_connected: AdbRemote.adb_shell,
UnixLocal.unix_local: AdbRemote.adb_shell,
UnixLocal.unix_local_root: AdbRemote.adb_shell,
UnixRemote.unix_remote: AdbRemote.adb_shell,
UnixRemote.unix_remote_root: AdbRemote.adb_shell,
AdbRemote.proxy_pc: AdbRemote.adb_shell,
AdbRemote.unix_local: AdbRemote.adb_shell,
AdbRemote.unix_local_root: AdbRemote.adb_shell,
AdbRemote.unix_remote: AdbRemote.adb_shell,
AdbRemote.unix_remote_root: AdbRemote.adb_shell,
},
AdbRemote.proxy_pc: {
AdbRemote.unix_remote_root: AdbRemote.unix_remote,
AdbRemote.adb_shell: AdbRemote.unix_remote,
AdbRemote.adb_shell_root: AdbRemote.unix_remote,
AdbRemote.not_connected: AdbRemote.unix_remote,
AdbRemote.unix_local_root: AdbRemote.unix_local,
}
}
return state_hops

Expand All @@ -498,13 +509,16 @@ def _configure_state_machine(self, sm_params):
hops_config = self._configurations[TextualDevice.connection_hops]

# copy prompt for ADB_SHELL/exit from UNIX_LOCAL/ssh
cfg_uxloc2ux = hops_config[UnixLocal.unix_local][UnixRemote.unix_remote]
cfg_adb2ux = hops_config[AdbRemote.adb_shell][UnixRemote.unix_remote]
if self._use_proxy_pc:
cfg_uxloc2ux = hops_config[AdbRemote.proxy_pc][AdbRemote.unix_remote]
else:
cfg_uxloc2ux = hops_config[AdbRemote.unix_local][AdbRemote.unix_remote]
cfg_adb2ux = hops_config[AdbRemote.adb_shell][AdbRemote.unix_remote]
remote_ux_prompt = cfg_uxloc2ux["command_params"]["expected_prompt"]
cfg_adb2ux["command_params"]["expected_prompt"] = remote_ux_prompt

# copy prompt for ADB_SHELL_ROOT/exit from UNIX_REMOTE/adb shell
cfg_ux2adb = hops_config[UnixRemote.unix_remote][AdbRemote.adb_shell]
cfg_ux2adb = hops_config[AdbRemote.unix_remote][AdbRemote.adb_shell]
cfg_adbroot2adb = hops_config[AdbRemote.adb_shell_root][AdbRemote.adb_shell]
adb_shell_prompt = self._get_adb_shell_prompt(cfg_ux2adb["command_params"])
cfg_adbroot2adb["command_params"]["expected_prompt"] = adb_shell_prompt
Expand All @@ -531,7 +545,7 @@ def _get_packages_for_state(self, state, observer):
TextualDevice.events: ['moler.events.shared']}
if available:
return available[observer]
elif state == UnixRemote.unix_remote: # this is unix extended with adb commands
elif state == AdbRemote.unix_remote: # this is unix extended with adb commands
if observer == TextualDevice.cmds:
available.append('moler.cmd.adb')

Expand Down
2 changes: 1 addition & 1 deletion moler/device/textualdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def _prepare_sm_data(self, sm_params):
self._prepare_transitions()
self._prepare_state_hops()
self._configure_state_machine(sm_params)
self._validate_device_configuration()
self._prepare_newline_chars()
self._send_transitions_to_sm(self._stored_transitions)

Expand Down Expand Up @@ -1153,7 +1154,6 @@ def _configure_state_machine(self, sm_params):
self._configurations = self._prepare_sm_configuration(
default_sm_configurations, sm_params
)
self._validate_device_configuration()
self._prepare_state_prompts()

def _prepare_sm_configuration(self, default_sm_configurations, sm_params):
Expand Down
4 changes: 4 additions & 0 deletions moler/device/unixremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ def _overwrite_prompts(self):
Overwrite prompts for some states to easily configure the SM.
"""
if self._use_proxy_pc:
self._configurations[UnixRemote.connection_hops][UnixRemote.unix_remote][UnixRemote.proxy_pc][
"command_params"]["expected_prompt"] = \
self._configurations[UnixRemote.connection_hops][UnixRemote.unix_local][UnixRemote.proxy_pc][
"command_params"]["expected_prompt"]
self._configurations[UnixRemote.connection_hops][UnixRemote.unix_remote_root][UnixRemote.unix_remote][
"command_params"]["expected_prompt"] = \
self._configurations[UnixRemote.connection_hops][UnixRemote.proxy_pc][UnixRemote.unix_remote][
Expand Down
Loading

0 comments on commit 1622eb7

Please sign in to comment.