Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions OATFWGUI/gui_logic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
import logging
import sys
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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}')
Expand Down
1 change: 1 addition & 0 deletions OATFWGUI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions OATFWGUI/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
from pathlib import Path
from typing import Callable
from platform_check import get_platform, PlatformEnum

log = logging.getLogger('')

Expand All @@ -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}')