component_information: switch from gzip to xz

Improves compression, e.g. current params file: 62KB to 51KB

There's also a PRESET_EXTREME option, which reduces by another 2KB.
We can revisit that once needed, as it increases mem usage as well.
This commit is contained in:
Beat Küng
2021-02-09 09:44:50 +01:00
parent cedfae9e46
commit 5a1c60b5a1
8 changed files with 22 additions and 22 deletions
+3 -3
View File
@@ -40,7 +40,7 @@ if (${index} EQUAL -1)
endif()
set(component_version_json ${PX4_BINARY_DIR}/component_version.json)
add_custom_command(OUTPUT ${component_version_json} ${component_version_json}.gz
add_custom_command(OUTPUT ${component_version_json} ${component_version_json}.xz
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate_component_version.py
${component_version_json}
--compress
@@ -55,13 +55,13 @@ add_custom_target(component_version_json DEPENDS ${component_version_json})
set(component_information_header ${CMAKE_CURRENT_BINARY_DIR}/hashes.h)
add_custom_command(OUTPUT ${component_information_header}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate_hashes.py
${PX4_BINARY_DIR}/params.json.gz
${PX4_BINARY_DIR}/params.json.xz
${component_version_json}
--output ${component_information_header}
DEPENDS
generate_hashes.py
parameters_xml
${PX4_BINARY_DIR}/params.json.gz
${PX4_BINARY_DIR}/params.json.xz
${component_version_json}
COMMENT "Generating component_information/hashes.h"
)
@@ -2,7 +2,7 @@
import argparse
import json
import gzip
import lzma #to create .xz file
parser = argparse.ArgumentParser(description="""Generate the COMPONENT_VERSION json file""")
parser.add_argument('filename', metavar='component_version.json', help='JSON output file')
@@ -14,9 +14,9 @@ filename = args.filename
compress = args.compress
def save_compressed(filename):
#create gz compressed version
gz_filename=filename+'.gz'
with gzip.open(gz_filename, 'wt') as f:
#create lzma compressed version
xz_filename=filename+'.xz'
with lzma.open(xz_filename, 'wt', preset=9) as f:
with open(filename, 'r') as content_file:
f.write(content_file.read())
+1 -1
View File
@@ -89,7 +89,7 @@ add_custom_command(OUTPUT ${generated_serial_params_file}
set(parameters_xml ${PX4_BINARY_DIR}/parameters.xml)
set(parameters_json ${PX4_BINARY_DIR}/params.json) # file name needs to be kept short to fit into url (metadata_uri)
file(GLOB_RECURSE param_src_files ${PX4_SOURCE_DIR}/src/*params.c)
add_custom_command(OUTPUT ${parameters_xml} ${parameters_json} ${parameters_json}.gz
add_custom_command(OUTPUT ${parameters_xml} ${parameters_json} ${parameters_json}.xz
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/px_process_params.py
--src-path ${module_list} ${generated_params_dir}
--xml ${parameters_xml}
+6 -6
View File
@@ -49,15 +49,15 @@ import os
import argparse
from px4params import srcscanner, srcparser, injectxmlparams, xmlout, markdownout, jsonout
import gzip #to create .gz file
import lzma #to create .xz file
import re
import json
import codecs
def SaveCompressed(filename):
#create gz compressed version
gz_filename=filename+'.gz'
with gzip.open(gz_filename, 'wt') as f:
def save_compressed(filename):
#create lzma compressed version
xz_filename=filename+'.xz'
with lzma.open(xz_filename, 'wt', preset=9) as f:
with open(filename, 'r') as content_file:
f.write(content_file.read())
@@ -185,7 +185,7 @@ def main():
for f in output_files:
if args.verbose:
print("Compressing file " + f)
SaveCompressed(f)
save_compressed(f)
if __name__ == "__main__":
@@ -69,12 +69,12 @@ public:
switch (type) {
case COMP_METADATA_TYPE_VERSION:
component_info.metadata_uid = component_information::component_version_hash;
handled = get_component_information("component_version.json.gz", component_info);
handled = get_component_information("component_version.json.xz", component_info);
break;
case COMP_METADATA_TYPE_PARAMETER:
component_info.metadata_uid = component_information::params_hash;
handled = get_component_information("params.json.gz", component_info);
handled = get_component_information("params.json.xz", component_info);
break;
case COMP_METADATA_TYPE_COMMANDS: