Moved deployment logic to python scripts.

This commit is contained in:
James Goppert 2017-01-12 19:21:41 -05:00 committed by Lorenz Meier
parent 50159cabbe
commit a0fff97fd2
5 changed files with 86 additions and 6 deletions

5
.gitignore vendored
View File

@ -20,8 +20,9 @@
Archives/*
Build/*
Testing/
Binaries/*
Meta/*
Packages/*
s3deploy-branch/
s3deploy-archive/
build/*
build_*/
core

View File

@ -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;

View File

@ -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_*/

37
Tools/package_firmware.py Executable file
View File

@ -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))

44
Tools/s3_deploy.py Executable file
View File

@ -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)