diff --git a/.gitignore b/.gitignore index 7f6a4445f3..ebfcf22cce 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,9 @@ Archives/* Build/* Testing/ -Binaries/* -Meta/* +Packages/* +s3deploy-branch/ +s3deploy-archive/ build/* build_*/ core diff --git a/.travis.yml b/.travis.yml index a2cb7e9d83..c75ae3dee0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,9 +78,7 @@ script: after_success: - if [[ "${TRAVIS_OS_NAME}" = "linux" && "${TRAVIS_BRANCH}" != "coverity" ]]; then make package_firmware && mkdir s3deploy-archive && cp Firmware.zip s3deploy-archive/ - && cp Binaries/* . - && find . -maxdepth 1 -mindepth 1 -type f -name 'nuttx-*-default.px4' | sed 's/.\/nuttx-//' | sed 's/-default.px4//' | xargs -I{} mv nuttx-{}-default.px4 {}_default.px4 - && mkdir s3deploy-branch && mv *_default.px4 Meta/px4fmu-v4_default/parameters.xml Meta/px4fmu-v4_default/airframes.xml s3deploy-branch/; + && Tools/s3_deploy.py; fi - if [[ "${TRAVIS_OS_NAME}" = "linux" && "$GCC_VER" == "5.4" && "${TRAVIS_BRANCH}" != "coverity" ]]; then export PX4_S3_DEPLOY=1; diff --git a/Makefile b/Makefile index f766e79cd5..02e08069c4 100644 --- a/Makefile +++ b/Makefile @@ -300,7 +300,7 @@ clang-tidy: @$(SRC_DIR)/Tools/clang-tool.sh -b build_posix_sitl_default -t clang-tidy package_firmware: - @zip --junk-paths Firmware.zip `find Binaries/. -name \*.px4` + @./Tools/package_firmware.py clean: @rm -rf build_*/ diff --git a/Tools/package_firmware.py b/Tools/package_firmware.py new file mode 100755 index 0000000000..338d41ded3 --- /dev/null +++ b/Tools/package_firmware.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import glob +import zipfile +import os + +FIRMWARE_FILE = 'Firmware.zip' + + +def extract_file_only(filename, dest): + """ + Extract a file without keeping directories. + """ + # extract firmware files without paths + f_src = archive.open(filename, 'r') + data = f_src.read() + dst_name = os.path.join(dest, os.path.basename(filename)) + with open(dst_name, 'w') as f_dst: + f_dst.write(data) + f_src.close() + +# open destination archive +with zipfile.ZipFile(FIRMWARE_FILE, 'w') as dest_archive: + + # get all zip files in Packages directory + for zip_filename in glob.glob("Packages/*.zip"): + + # open zipfile + with zipfile.ZipFile(zip_filename, 'r') as archive: + + # look for interesting names + for src_filename in archive.namelist(): + + # extract firmware files + if os.path.splitext(src_filename)[1] == '.px4': + base_name = os.path.basename(src_filename) + dest_archive.writestr(base_name, archive.read(src_filename)) diff --git a/Tools/s3_deploy.py b/Tools/s3_deploy.py new file mode 100755 index 0000000000..3013a0952d --- /dev/null +++ b/Tools/s3_deploy.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +import glob +import zipfile +import os +import re +import shutil + +S3_DIR = 's3deploy-branch' +S3_ARCHIVE_DIR = 's3deploy-branch' + +if not os.path.isdir(S3_DIR): + os.mkdir(S3_DIR) + +if not os.path.isdir(S3_ARCHIVE_DIR): + os.mkdir(S3_ARCHIVE_DIR) + +shutil.copyfile(Firmware.zip, S3_ARCHIVE_DIR) + +def extract_file_only(filename, dest): + # extract firmware files without paths + f_src = archive.open(filename, 'r') + data = f_src.read() + with open(os.path.join(dest, + os.path.basename(filename)), 'w') as f_dst: + f_dst.write(data) + f_src.close() + +# get all zip files in Packages directory +for zip_filename in glob.glob("Packages/*.zip"): + + # open zipfile + with zipfile.ZipFile(zip_filename, 'r') as archive: + + # look for interesting names + for filename in archive.namelist(): + + # extract firmware files + if os.path.splitext(filename)[1] == '.px4': + extract_file_only(filename, S3_DIR) + + # copy px4fmu-v4_default xml files for qgroundcontrol + if re.match(filename, r'.*px4fmu-v4_default.*\.xml') is not None: + extract_file_only(filename, S3_DIR)