Skip to content

Commit

Permalink
Check for and remove previous OATFWGUI pio core installations
Browse files Browse the repository at this point in the history
  • Loading branch information
julianneswinoga committed Dec 19, 2023
1 parent d4ed760 commit 3dc24e5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion OATFWGUI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from platform_check import get_platform, PlatformEnum
from external_processes import external_processes, add_external_process, get_install_dir
from anon_usage_data import create_anon_stats
from misc_utils import delete_directory

parser = argparse.ArgumentParser(usage='Graphical way to build and load OAT Firmware')
parser.add_argument('--no-gui', action='store_true',
Expand Down Expand Up @@ -61,10 +62,21 @@ def setup_environment():

# Putting the platformio core directory in a temporary folder is only needed because
# Windows doesn't support long path names... :/
pio_core_dir = Path(tempfile.gettempdir(), f'.pioOATFWGUI{__version__}')
tempdir_path = Path(tempfile.gettempdir())
pio_prefix_str = '.pioOATFWGUI'
pio_core_dir = Path(tempdir_path, f'{pio_prefix_str}{__version__}')
log.info(f'Setting PLATFORMIO_CORE_DIR to {pio_core_dir}')
os.environ['PLATFORMIO_CORE_DIR'] = str(pio_core_dir)

log.debug('Checking for previous OATFWGUI pio core installs...')
for temp_path in tempdir_path.iterdir():
is_dir = temp_path.is_dir()
is_oatfwgui_core_dir = pio_prefix_str in temp_path.name
not_current_core_dir = temp_path.name != pio_core_dir
if is_dir and is_oatfwgui_core_dir and not_current_core_dir:
log.info(f'Removing other pio core directory:{temp_path.name}')
delete_directory(temp_path)

python_interpreter_path = Path(sys.executable)
log.debug(f'Python interpreter: {python_interpreter_path}')
python_interpreter_dir = python_interpreter_path.parent
Expand Down

0 comments on commit 3dc24e5

Please sign in to comment.