Skip to content

Commit

Permalink
Define for folder name within zip file (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian M <[email protected]>
  • Loading branch information
elral and DocMoebiuz authored Sep 16, 2024
1 parent 9d98024 commit a6abb27
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
22 changes: 13 additions & 9 deletions Template/MyCustomDevice_platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ build_src_filter =
+<../Template> ; build files for your custom device, replace "Template" by your folder name
lib_deps = ; You can add additional libraries if required
custom_core_firmware_version = 2.5.1 ; define the version from the core firmware files your build should base on
custom_device_folder = Template ; path to your Custom Device Sources, replace "Template" by your folder name
custom_community_project = Your_Project ; Should match "Project" from section "Community" within the board.json file, it's the name of the ZIP file

custom_source_folder = Template ; path to your Custom Device Sources, replace "Template" by your folder name
custom_community_project = YourProject ; Folder name inside zip file, also ZIP file name if "custom_zip_filename" is not changed
custom_zip_filename = ${env_template.custom_community_project} ; Name of the zip-file, overwrite it to define an different zip-file name

; Build settings for the Arduino Mega with Custom Firmware Template
[env:mobiflight_template_mega]
Expand All @@ -41,8 +41,8 @@ extra_scripts =
${env.extra_scripts} ; don't change this one!
custom_core_firmware_version = ${env_template.custom_core_firmware_version} ; don't change this one!
custom_community_project = ${env_template.custom_community_project} ; don't change this one!
custom_device_folder = ${env_template.custom_device_folder} ; don't change this one!

custom_source_folder = ${env_template.custom_source_folder} ; don't change this one!
custom_zip_filename = ${env_template.custom_zip_filename} ; don't change this one!

; Build settings for the Arduino ProMicro with Custom Firmware Template
[env:mobiflight_template_micro]
Expand All @@ -66,7 +66,8 @@ extra_scripts =
${env.extra_scripts} ; don't change this one!
custom_core_firmware_version = ${env_template.custom_core_firmware_version} ; don't change this one!
custom_community_project = ${env_template.custom_community_project} ; don't change this one!
custom_device_folder = ${env_template.custom_device_folder} ; don't change this one!
custom_source_folder = ${env_template.custom_source_folder} ; don't change this one!
custom_zip_filename = ${env_template.custom_zip_filename} ; don't change this one!


; Build settings for the Arduino Uno with Custom Firmware Template
Expand All @@ -91,7 +92,8 @@ extra_scripts =
${env.extra_scripts} ; don't change this one!
custom_core_firmware_version = ${env_template.custom_core_firmware_version} ; don't change this one!
custom_community_project = ${env_template.custom_community_project} ; don't change this one!
custom_device_folder = ${env_template.custom_device_folder} ; don't change this one!
custom_source_folder = ${env_template.custom_source_folder} ; don't change this one!
custom_zip_filename = ${env_template.custom_zip_filename} ; don't change this one!


; Build settings for the Arduino Nano with Custom Firmware Template
Expand All @@ -116,7 +118,8 @@ extra_scripts =
${env.extra_scripts} ; don't change this one!
custom_core_firmware_version = ${env_template.custom_core_firmware_version} ; don't change this one!
custom_community_project = ${env_template.custom_community_project} ; don't change this one!
custom_device_folder = ${env_template.custom_device_folder} ; don't change this one!
custom_source_folder = ${env_template.custom_source_folder} ; don't change this one!
custom_zip_filename = ${env_template.custom_zip_filename} ; don't change this one!


; Build settings for the Raspberry Pico with Custom Firmware Template
Expand Down Expand Up @@ -145,4 +148,5 @@ extra_scripts =
${env.extra_scripts} ; don't change this one!
custom_core_firmware_version = ${env_template.custom_core_firmware_version} ; don't change this one!
custom_community_project = ${env_template.custom_community_project} ; don't change this one!
custom_device_folder = ${env_template.custom_device_folder} ; don't change this one!
custom_source_folder = ${env_template.custom_source_folder} ; don't change this one!
custom_zip_filename = ${env_template.custom_zip_filename} ; don't change this one!
32 changes: 16 additions & 16 deletions copy_fw_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,30 @@
community_project = env.GetProjectOption('custom_community_project', "")

# Get the custom folder from the build environment.
custom_device_folder = env.GetProjectOption('custom_device_folder', "")
custom_source_folder = env.GetProjectOption('custom_source_folder', "")

# Get the foldername inside the zip file from the build environment.
zip_filename = env.GetProjectOption('custom_zip_filename', "")

platform = env.BoardConfig().get("platform", {})

def copy_fw_files (source, target, env):
fw_file_name=str(target[0])

if os.path.exists("./_build/" + custom_device_folder) == False:
os.makedirs("./_build/" + custom_device_folder + "/Community/firmware")
shutil.copytree(custom_device_folder + "/Community", "./_build/" + custom_device_folder + "/Community", dirs_exist_ok=True)
print("Creating Folder and copying community folder")
if os.path.exists("./_build/" + custom_source_folder) == False:
os.makedirs("./_build/" + custom_source_folder + "/Community/firmware")
shutil.copytree(custom_source_folder + "/Community", "./_build/" + custom_source_folder + "/Community", dirs_exist_ok=True)
print("Creating /_build folder")

if fw_file_name[-3:] == "bin":
if platform == "raspberrypi":
fw_file_name=fw_file_name[0:-3] + "uf2"

shutil.copy(fw_file_name, "./_build/" + custom_device_folder + "/Community/firmware")
createCommunityZipFile(source, target, env)

def createCommunityZipFile(source, target, env):
original_folder_path = "./_build/" + custom_device_folder + "/Community"
zip_file_path = './_dist/' + community_project + '_' + firmware_version + '.zip'
new_folder_in_zip = community_project
createZIP(original_folder_path, zip_file_path, new_folder_in_zip)
print("Copying community folder")
shutil.copy(fw_file_name, "./_build/" + custom_source_folder + "/Community/firmware")
original_folder_path = "./_build/" + custom_source_folder + "/Community"
zip_file_path = './_dist/' + zip_filename + '_' + firmware_version + '.zip'
print("Creating zip file")
createZIP(original_folder_path, zip_file_path, community_project)

def createZIP(original_folder_path, zip_file_path, new_folder_name):
if os.path.exists("./_dist") == False:
Expand All @@ -50,5 +52,3 @@ def createZIP(original_folder_path, zip_file_path, new_folder_name):

env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", copy_fw_files)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", copy_fw_files)
#env.AddPostAction("checkprogsize", createCommunityZipFile)
#env.AddCustomTarget("create_community_zip", None, createCommunityZipFile)

0 comments on commit a6abb27

Please sign in to comment.