From 43a03e21c9a83b983993b933ffa904dce8efb37f Mon Sep 17 00:00:00 2001 From: C Crawford Date: Sat, 29 Nov 2025 11:15:11 -0600 Subject: [PATCH 1/2] Added helper script to copy the Community folders to the local MF install directory. Helpful during custom device development. --- deploy_community.py | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 deploy_community.py diff --git a/deploy_community.py b/deploy_community.py new file mode 100644 index 0000000..81a00af --- /dev/null +++ b/deploy_community.py @@ -0,0 +1,69 @@ +import shutil +import os +import re +from pathlib import Path + +def find_custom_source_folder(): + """Find the custom_source_folder value from platformio.ini files""" + # Script is in project root directory + project_root = Path(__file__).parent + + # Search for *_platformio.ini files in subdirectories (e.g., Template/MyCustomDevice_platformio.ini) + ini_files = list(project_root.glob("*/*_platformio.ini")) + + if not ini_files: + raise FileNotFoundError("No *_platformio.ini file found in project") + + # Parse the first one found + ini_file = ini_files[0] + print(f"Found platformio.ini: {ini_file}") + + with open(ini_file, 'r') as f: + content = f.read() + # Look for custom_source_folder = CC_G5 + match = re.search(r'custom_source_folder\s*=\s*(\S+)', content) + if match and not match.group(1).startswith('${'): + return match.group(1) + + raise ValueError("custom_source_folder not found in platformio.ini") + +try: + # Auto-discover the project folder name + project_folder = find_custom_source_folder() + print(f"Project folder: {project_folder}") + + # Get the project root directory (script is in project root) + project_root = Path(__file__).parent + source_dir = project_root / project_folder / "Community" + + print(f"Project root: {project_root}") + print(f"Source directory: {source_dir}") + print(f"Source exists: {source_dir.exists()}") + + if not source_dir.exists(): + raise FileNotFoundError(f"Community folder not found at {source_dir}") + + # Destination directory (using USERPROFILE environment variable) + dest_dir = Path.home() / "AppData" / "Local" / "MobiFlight" / "MobiFlight Connector" / "Community" / project_folder + + print(f"Destination directory: {dest_dir}") + + # Create destination directory if it doesn't exist + # Check if MobiFlight Community folder exists + community_base = dest_dir.parent + if not community_base.exists(): + raise FileNotFoundError(f"MobiFlight Community folder not found at: {community_base}\nPlease verify MobiFlight Connector is installed at the standard location or update script.") + + # Create the project-specific folder + dest_dir.mkdir(exist_ok=True) + print(f"Destination created/verified") + + # Copy all contents from source to destination, overwriting existing files + shutil.copytree(source_dir, dest_dir, dirs_exist_ok=True) + + print(f"\033[92mSuccessfully copied contents from {source_dir} to {dest_dir}\033[0m") + +except Exception as e: + print(f"\033[91m*********Error: {e}\033[0m") + import traceback + traceback.print_exc() From a03bf666a1d513d28f6667bdd6c0ae315ea86e0c Mon Sep 17 00:00:00 2001 From: Chris Crawford Date: Fri, 2 Jan 2026 10:10:25 -0600 Subject: [PATCH 2/2] Enhance platformio.ini file handling and error reporting Changed the destination directory name under the MF install directory to properly match the .zip file. Improved error handling and directory path discovery to support running from different locations. Added more descriptions and error handlings. --- deploy_community.py | 69 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/deploy_community.py b/deploy_community.py index 81a00af..cf158bc 100644 --- a/deploy_community.py +++ b/deploy_community.py @@ -5,14 +5,14 @@ def find_custom_source_folder(): """Find the custom_source_folder value from platformio.ini files""" - # Script is in project root directory - project_root = Path(__file__).parent + # Get script directory (not current working directory) + script_dir = Path(__file__).parent.resolve() - # Search for *_platformio.ini files in subdirectories (e.g., Template/MyCustomDevice_platformio.ini) - ini_files = list(project_root.glob("*/*_platformio.ini")) + # Search for *_platformio.ini files recursively + ini_files = list(script_dir.glob("**/*_platformio.ini")) if not ini_files: - raise FileNotFoundError("No *_platformio.ini file found in project") + raise FileNotFoundError(f"No *_platformio.ini file found in {script_dir} or its subdirectories") # Parse the first one found ini_file = ini_files[0] @@ -20,23 +20,51 @@ def find_custom_source_folder(): with open(ini_file, 'r') as f: content = f.read() - # Look for custom_source_folder = CC_G5 + # Look for custom_source_folder (e.g. Template) match = re.search(r'custom_source_folder\s*=\s*(\S+)', content) if match and not match.group(1).startswith('${'): return match.group(1) raise ValueError("custom_source_folder not found in platformio.ini") +def find_community_project_name(): + """Find the custom_community_project value from platformio.ini files""" + # Get script directory (not current working directory) + script_dir = Path(__file__).parent.resolve() + + # Search for *_platformio.ini files recursively + ini_files = list(script_dir.glob("**/*_platformio.ini")) + + if not ini_files: + raise FileNotFoundError(f"No *_platformio.ini file found in {script_dir} or its subdirectories") + + # Parse the first one found + ini_file = ini_files[0] + print(f"Found platformio.ini: {ini_file}") + + with open(ini_file, 'r') as f: + content = f.read() + # Look for custom_community_project e.g. "YourProject" in the template + match = re.search(r'custom_community_project\s*=\s*(\S+)', content) + if match and not match.group(1).startswith('${'): + return match.group(1) + + raise ValueError("custom_community_project not found in platformio.ini") + try: # Auto-discover the project folder name project_folder = find_custom_source_folder() print(f"Project folder: {project_folder}") - # Get the project root directory (script is in project root) - project_root = Path(__file__).parent - source_dir = project_root / project_folder / "Community" + # Auto-discover the community project name (for destination folder) + community_project_name = find_community_project_name() + print(f"Community project name: {community_project_name}") - print(f"Project root: {project_root}") + # Get the script directory (works regardless of where the script is executed from) + script_dir = Path(__file__).parent.resolve() + source_dir = script_dir / project_folder / "Community" + + print(f"Script directory: {script_dir}") print(f"Source directory: {source_dir}") print(f"Source exists: {source_dir.exists()}") @@ -44,7 +72,11 @@ def find_custom_source_folder(): raise FileNotFoundError(f"Community folder not found at {source_dir}") # Destination directory (using USERPROFILE environment variable) - dest_dir = Path.home() / "AppData" / "Local" / "MobiFlight" / "MobiFlight Connector" / "Community" / project_folder + # Assumes standard install location. We'll notify the user if not found. + ########################################## + # NON STANDARD MF INSTALL? EDIT LINE BELOW + ########################################## + dest_dir = Path.home() / "AppData" / "Local" / "MobiFlight" / "MobiFlight Connector" / "Community" / community_project_name print(f"Destination directory: {dest_dir}") @@ -63,6 +95,21 @@ def find_custom_source_folder(): print(f"\033[92mSuccessfully copied contents from {source_dir} to {dest_dir}\033[0m") + # Check if _build folder exists and copy firmware files + build_firmware_dir = script_dir / "_build" / project_folder / "Community" / "firmware" + if build_firmware_dir.exists(): + dest_firmware_dir = dest_dir / "firmware" + dest_firmware_dir.mkdir(exist_ok=True) + + # Copy firmware files from _build to MobiFlight Community + for firmware_file in build_firmware_dir.glob("*"): + if firmware_file.is_file(): + shutil.copy2(firmware_file, dest_firmware_dir) + print(f"\033[92mCopied firmware: {firmware_file.name}\033[0m") + else: + print(f"\033[93mWarning: Build firmware folder not found at {build_firmware_dir}\033[0m") + print(f"\033[93mRun a PlatformIO build first to generate firmware files\033[0m") + except Exception as e: print(f"\033[91m*********Error: {e}\033[0m") import traceback