diff --git a/OATFWGUI/gui_logic.py b/OATFWGUI/gui_logic.py index 820951c..d91dba0 100644 --- a/OATFWGUI/gui_logic.py +++ b/OATFWGUI/gui_logic.py @@ -1,3 +1,4 @@ +import os import re import logging import sys @@ -18,13 +19,13 @@ from external_processes import external_processes, get_install_dir from gui_state import LogicState, PioEnv, FWVersion from anon_usage_data import AnonStatsDialog, create_anon_stats, upload_anon_stats -from misc_utils import delete_directory +from misc_utils import delete_directory, get_env_var log = logging.getLogger('') def read_platformio_ini_file(logic_state: LogicState) -> List[str]: - ini_path = Path(logic_state.fw_dir, 'platformio.ini') + ini_path = Path(os.path.expandvars(logic_state.fw_dir), 'platformio.ini') with open(ini_path.resolve(), 'r') as fp: ini_lines = fp.readlines() return ini_lines @@ -48,6 +49,7 @@ def get_pio_environments(ini_lines: List[str]) -> List[PioEnv]: 'mksgenlv21': 'MKS Gen L v2.1', 'mksgenlv2': 'MKS Gen L v2', 'mksgenlv1': 'MKS Gen L v1', + 'oaeboardv1': 'OAE Board v1', } pio_environments = [] for raw_env in raw_pio_envs: @@ -69,8 +71,10 @@ def download_fw(zip_url: str) -> Path: def extract_fw(zipfile_name: Path) -> Path: # For Windows path length reasons, keep the firmware folder name short - fw_dir = Path(get_install_dir(), 'OATFW') - if fw_dir.exists(): + fw_dir_env = Path(get_env_var('INSTALL_DIR'), 'OATFW') + fw_dir = os.path.expandvars(fw_dir_env) + + if Path(fw_dir).exists(): log.info(f'Removing previously downloaded FW from {fw_dir}') delete_directory(fw_dir) @@ -87,7 +91,7 @@ def extract_fw(zipfile_name: Path) -> Path: log.info(f'Rename {extracted_dir} to {fw_dir}') shutil.move(extracted_dir, fw_dir) log.info(f'Extracted FW to {fw_dir}') - return fw_dir + return fw_dir_env class BusinessLogic: @@ -169,6 +173,8 @@ def get_fw_versions(self) -> str: releases_list = [ FWVersion('develop', 'https://github.com/OpenAstroTech/OpenAstroTracker-Firmware/archive/refs/heads/develop.zip'), + FWVersion('oae-fw', + 'https://github.com/OpenAstroTech/OpenAstroTracker-Firmware/archive/refs/heads/oae-fw.zip'), ] if r.status_code != requests.codes.ok: log.error(f'Failed to grab latest FW versions: {r.status_code} {r.reason} {r.text}') @@ -307,7 +313,7 @@ def build_fw(self): # Hot patches, since we can't re-release an old firmware tag self.do_hot_patches() - config_dest_path = str(Path(self.logic_state.fw_dir, 'Configuration_local.hpp').resolve()) + config_dest_path = str(Path(os.path.expandvars(self.logic_state.fw_dir), 'Configuration_local.hpp').resolve()) if Path(config_dest_path) != Path(self.logic_state.config_file_path): if QFile.exists(config_dest_path): log.warning(f'Deleting existing configuration file {config_dest_path}') diff --git a/OATFWGUI/main.py b/OATFWGUI/main.py index 790585f..8c86dc4 100755 --- a/OATFWGUI/main.py +++ b/OATFWGUI/main.py @@ -48,6 +48,7 @@ def check_and_warn_directory_path_length(dir_to_check: Path, max_path_len: int, def setup_environment(): install_dir = get_install_dir() log.debug(f'Install dir is {install_dir}') + os.environ['INSTALL_DIR'] = str(install_dir) if get_platform() == PlatformEnum.WINDOWS: # With 54fa285a dependencies the maximum path length is 180. # 260-152=108, but derate to 100 (for possible future increases) diff --git a/OATFWGUI/misc_utils.py b/OATFWGUI/misc_utils.py index 843174b..dab5a60 100644 --- a/OATFWGUI/misc_utils.py +++ b/OATFWGUI/misc_utils.py @@ -4,6 +4,7 @@ import logging from pathlib import Path from typing import Callable +from platform_check import get_platform, PlatformEnum log = logging.getLogger('') @@ -21,3 +22,11 @@ def remove_readonly(func: Callable, path, excinfo): def decode_bytes(byte_string: bytes) -> str: # Just to consolidate all text decoding and make sure they're all the same return byte_string.decode('utf-8', errors='backslashreplace') + +def get_env_var(env_var) -> str: + if get_platform() == PlatformEnum.WINDOWS: + # Use %MY_PATH% syntax + return f'%{env_var}%' + else: + # Use $MY_PATH syntax + return os.path.expandvars(f'${env_var}') \ No newline at end of file