Index: tools/build_common_defs.py =================================================================== diff -u -r02eff24a2b116fe3d71d8275eeb78f419302efd6 -rf053467ac7cfb9fe349e394342d3a9253a377403 --- tools/build_common_defs.py (.../build_common_defs.py) (revision 02eff24a2b116fe3d71d8275eeb78f419302efd6) +++ tools/build_common_defs.py (.../build_common_defs.py) (revision f053467ac7cfb9fe349e394342d3a9253a377403) @@ -19,7 +19,13 @@ from datetime import datetime -def create_enum_file(in_path: str, out_path:str, author: str, code_imports: str, code_class_def: str, as_int=True): +def create_enum_file(in_path: str, + out_path:str, + author: str, + code_imports: str, + code_class_def: str, + as_int=True, + custom_defs: dict = {}): """ Generates an enum source code file @param in_path: (str) input txt file @@ -28,6 +34,7 @@ @param code_imports: (str) raw source code as string imports needed for this header file @param code_class_def: (str) raw source code class definition for this enum @param as_int: (bool) if True, output enums as int, if False output as hex + @param custom_defs: (dict) custom enums (if mapped to None they are ignored) @return: True upon success, False upon failure """ @@ -41,6 +48,13 @@ num = num.replace(",", "").strip() var = split_str[0].strip() + if var in custom_defs: + if custom_defs[var] is None: + print("Ignoring {0}.".format(var)) + continue + num = custom_defs[var] + print("Applied custom mapping {0} = {1}.".format(var, num)) + base = 10 if "x" in num.lower(): base = 16 @@ -61,8 +75,7 @@ current_time = datetime.now() code_header = \ -""" -########################################################################### +"""########################################################################### # # Copyright (c) 2019-{0} Diality Inc. - All Rights Reserved. # @@ -118,6 +131,7 @@ code_prepend: str, code_class_def: str, as_int: bool, + custom_defs: dict = {}, ): """ Driver function to build a common defs .py source file @@ -131,23 +145,24 @@ @param code_prepend: (str) raw source code as string imports needed for this header file @param code_class_def: (str) raw source code class definition for this enum @param as_int: (bool) if True, output enums as int, if False output as hex + @param custom_defs: (dict) custom enums (if mapped to None they are ignored) @return: None """ - if subprocess.call("bash gen_alarm_ids.sh {0} {1} {2} {3} {4}" + if subprocess.call("bash gen_common_defs.sh {0} {1} {2} {3} {4}" .format(dst_alarms_txt, dst_common, common_branch, prefix_match, cpp_header), shell=True) != 0: print("Failure: Could not generate alarm ids.") return - if create_enum_file(dst_alarms_txt, dst_python, author, code_prepend, code_class_def, as_int): + if create_enum_file(dst_alarms_txt, dst_python, author, code_prepend, code_class_def, as_int, custom_defs): print("Created enum file: {0}".format(dst_python)) print("Done.") else: print("Failure: Could not create enum file.") if __name__ == '__main__': - common_branch="Sprint37" + common_branch="staging" build_common_defs(dst_alarms_txt="/tmp/AlarmIds.txt", dst_common="/tmp/common", common_branch=common_branch, @@ -164,6 +179,12 @@ "class AlarmList(AlarmEnum):\n").format(common_branch), as_int=True, ) + custom_defs = { + "MSG_ID_FIRST_TESTER_MESSAGE": None, + "MSG_ID_FIRST_DG_TESTER_MESSAGE": None, + "MSG_ID_TESTER_LOGIN_REQUEST": "0x8000", + "MSG_ID_DG_TESTER_LOGIN_REQUEST": "0xA000", + } build_common_defs(dst_alarms_txt="/tmp/MsgDefs.txt", dst_common="/tmp/common", common_branch=common_branch, @@ -179,4 +200,5 @@ "@unique\n" "class MsgIds(DialinEnum):\n").format(common_branch), as_int=False, + custom_defs=custom_defs, )