|
19 | 19 | from subprocess import STDOUT, CalledProcessError, call, check_output |
20 | 20 | from time import sleep |
21 | 21 | from typing import Callable, Optional |
| 22 | +from loguru import logger |
22 | 23 |
|
23 | 24 | import flet |
24 | 25 | from flet import ( |
|
47 | 48 | colors, |
48 | 49 | icons, |
49 | 50 | ) |
50 | | -from installer_config import InstallerConfig, Step |
51 | | -from loguru import logger |
| 51 | +from installer_config import Step, _load_config |
52 | 52 | from tool_utils import call_tool_with_command, search_device |
53 | 53 | from widgets import call_button, confirm_button, get_title |
54 | 54 |
|
55 | 55 | # Toggle to True for development purposes |
56 | | -DEVELOPMENT = False |
| 56 | +DEVELOPMENT = False |
57 | 57 | DEVELOPMENT_CONFIG = "sargo" # "a3y17lte" # "sargo" |
58 | 58 |
|
59 | 59 |
|
@@ -199,8 +199,7 @@ def search_devices(self, e): |
199 | 199 | if device_code: |
200 | 200 | self.device_name.value = device_code |
201 | 201 | # load config from file |
202 | | - path = CONFIG_PATH.joinpath(Path(f"{device_code}.yaml")) |
203 | | - device_name = self.load_config(path) |
| 202 | + device_name = self.load_config(device_code) |
204 | 203 |
|
205 | 204 | # display success in the application |
206 | 205 | if device_name: |
@@ -394,17 +393,12 @@ def confirm(self, e): |
394 | 393 | self.view.controls.append(self.final_view) |
395 | 394 | self.view.update() |
396 | 395 |
|
397 | | - def load_config(self, path: str) -> Optional[str]: |
398 | | - """Function to load a config file from path.""" |
399 | | - try: |
400 | | - self.config = InstallerConfig.from_file(path) |
| 396 | + def load_config(self, device_code: str) -> Optional[str]: |
| 397 | + """Function to load a config file from device code.""" |
| 398 | + self.config = _load_config(device_code, CONFIG_PATH) |
| 399 | + if self.config: |
401 | 400 | self.num_total_steps = len(self.config.steps) |
402 | | - logger.info(f"Loaded device config from {path}.") |
403 | | - logger.info(f"Config metadata: {self.config.metadata}.") |
404 | 401 | return self.config.metadata.get("devicename", "No device name in config.") |
405 | | - except FileNotFoundError: |
406 | | - logger.info(f"No device config found for {path}.") |
407 | | - return None |
408 | 402 |
|
409 | 403 | def pick_image_result(self, e: FilePickerResultEvent): |
410 | 404 | self.selected_image.value = ( |
@@ -496,10 +490,12 @@ def call_to_phone(self, e, command: str): |
496 | 490 |
|
497 | 491 | Some parts of the command are changed by placeholders. |
498 | 492 | """ |
| 493 | + # replace placeholders by the required values |
499 | 494 | command = command.replace("<recovery>", self.recovery_path) |
500 | 495 | command = command.replace("<image>", self.image_path) |
501 | 496 | command = command.replace("<inputtext>", self.inputtext.value) |
502 | 497 |
|
| 498 | + # display a progress ring to show something is happening |
503 | 499 | self.right_view.controls.append( |
504 | 500 | Row( |
505 | 501 | [ProgressRing(color="#00d886")], |
|
0 commit comments