5 Copyright © 2022 Samsung Electronics Co., Ltd.. All rights reserved.
7 Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute
8 this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear
9 in all copies of this software.
11 IN NO EVENT SHALL SAMSUNG ELECTRONICS CO., LTD. BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
12 DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF SAMSUNG ELECTRONICS CO., LTD. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 SAMSUNG ELECTRONICS CO., LTD. SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND SAMSUNG ELECTRONICS CO., LTD. HAS NO OBLIGATION TO PROVIDE
16 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
21 This script is used to generate an info file, which is to be attached to a delta of any type.
22 The file contains specific details about an image that a particular delta will upgrade.
23 Sample file (with currently supported image details)
27 device_type=IoT_Headless
28 tz_build_release_name=Tizen7/Unified
30 tz_build_date=20220922_060719
35 import xml.etree.ElementTree as ET
41 TIZEN_PREFIX = "tizen.org"
42 SYSTEM_PREFIX = os.path.join(TIZEN_PREFIX, "system")
43 BUILD_PREFIX = "TZ_BUILD_"
46 # following three could be simpler, but this way its easier in case we add more variables to check
47 def generate_hal_model_config_set():
51 return set(os.path.join(SYSTEM_PREFIX, elem) for elem in hal_list)
54 def generate_rootfs_model_config_set():
59 return set(os.path.join(SYSTEM_PREFIX, elem) for elem in rootfs_list)
62 def generate_tizen_build_set():
68 return set(BUILD_PREFIX + elem for elem in tizen_list)
71 def get_dict_from_text_file(path, set_info):
73 with open(path, 'r') as reader:
74 lines = (line.rstrip() for line in reader.readlines())
75 lines = (line for line in lines if line)
77 var_name, var_value = line.split('=')
80 if var_name in set_info:
81 set_info.remove(var_name)
82 # for consistent formatting
83 tmp_dict[var_name.lower()] = var_value
84 if len(set_info) == 0:
90 def get_dict_from_xml_file(path, set_info):
93 xml_tree = ET.parse(path)
94 xml_root = xml_tree.getroot()
96 for elem in xml_root.findall('./platform/key'):
97 name = elem.get('name')
100 tmp_dict[name] = elem.text
101 if len(set_info) == 0:
107 def generate_main_dict(args):
110 hal_set = generate_hal_model_config_set()
111 rootfs_set = generate_rootfs_model_config_set()
112 tizen_set = generate_tizen_build_set()
114 hal_dict = get_dict_from_xml_file(args.hal_model_config_path, hal_set)
116 print(f'{args.hal_model_config_path}: error parsing file', file=sys.stderr)
119 rootfs_dict = get_dict_from_xml_file(args.rootfs_model_config_path, rootfs_set)
121 print(f'{args.rootfs_model_config_path}: error parsing file', file=sys.stderr)
124 tizen_dict = get_dict_from_text_file(args.tizen_build_config_path, tizen_set)
126 print(f'{args.tizen_build_config_path}: error parsing file', file=sys.stderr)
129 main_dict.update(hal_dict)
130 main_dict.update(rootfs_dict)
131 main_dict.update(tizen_dict)
137 parser = argparse.ArgumentParser(description='Generate a formated update-info.ini file used to verify whether \
138 delta archive used during update is compatible with our device. This file will be created using three files.')
140 parser.add_argument('hal_model_config_path', type=str, help='path to a file originally at path_to_hal/etc/config/model-config.xml')
141 parser.add_argument('rootfs_model_config_path', type=str, help='path to a file originally at path_to_rootfs/etc/config/model-config.xml')
142 parser.add_argument('tizen_build_config_path', type=str, help='path to a file originally at path_to_rootfs/etc/tizen-build.conf')
143 parser.add_argument('output_file', type=str, help='path to an output file')
149 parser = create_parser()
150 args = parser.parse_args()
152 for index, (arg_name, arg_value) in enumerate(vars(args).items(), start=1):
153 # we do not want output file to exist
154 if index == len(vars(args)):
155 if os.path.exists(arg_value):
156 parser.error(f'{arg_name} = {arg_value} is a file that already exists!')
158 if not (os.path.exists(arg_value) and os.path.isfile(arg_value)):
159 parser.error(f'{arg_name} = {arg_value} is not a valid path!')
161 print('--- Generate update info file ---')
162 update_data = generate_main_dict(args)
164 # TODO make this exception more verbose
167 with open(args.output_file, 'w') as writer:
168 for key, value in update_data.items():
169 _, key = os.path.split(key)
170 key = key.split()[-1]
171 value = value.replace('\"', '')
172 writer.write(f'{key}={value}\n')
174 print('--- Generating update info file successful ---')
178 if __name__ == '__main__':