···77import argparse
88import json
99import copy
1010-import itertools
1111-1010+from operator import attrgetter
12111312def find_component_in_list_by_name(name, component_list, subaction_path=None, identifier_json_path=None):
1413 """Find a component with the given name in a list of components."""
···124123 Turn a Identifier's component paths into a list of Component objects.
125124 """
126125127127- monado_bindings = json_subpath["monado_bindings"]
128126 component_list = []
129127 for component_name in json_subpath["components"]: # click, touch, ...
130128 matched_dpad_emulation = None
···132130 json_subpath["dpad_emulation"]["position"] == component_name):
133131 matched_dpad_emulation = json_subpath["dpad_emulation"]
134132135135- monado_binding = None
136136- if component_name in monado_bindings:
137137- monado_binding = monado_bindings[component_name]
133133+ monado_binding = json_subpath["monado_bindings"].get(component_name, None)
138134139135 steamvr_path = steamvr_subpath_name(identifier_json_path, json_subpath["type"])
140136 if "steamvr_path" in json_subpath:
···224220225221 identifier_list = []
226222 for subaction_path in json_subaction_paths: # /user/hand/*
227227- for json_sub_path_itm in json_subpaths.items(): # /input/*, /output/*
228228- json_path = json_sub_path_itm[0] # /input/trackpad
223223+ for json_path in sorted(json_subpaths.keys()): # /input/*, /output/*
229224 # json object associated with a subpath (type, localized_name, ...)
230230- json_subpath = json_sub_path_itm[1]
225225+ json_subpath = json_subpaths[json_path]
231226232227 # Oculus Touch a,b/x,y components only exist on one controller
233228 if "side" in json_subpath and "/user/hand/" + json_subpath["side"] != subaction_path:
···370365 def __update_component_list(self):
371366 self.components = []
372367 for identifier in self.identifiers:
373373- for component in identifier.components:
374374- self.components.append(component)
368368+ self.components += identifier.components
369369+ self.components = sorted(self.components, key=attrgetter("steamvr_path"))
375370376371377372oxr_verify_extension_status_struct_name = "oxr_verify_extension_status"
···395390396391 def __init__(self, json_root):
397392 """Construct a bindings from a dictionary of profiles."""
398398- self.profiles = [Profile(profile_name, json_profile) for
399399- profile_name, json_profile in json_root["profiles"].items()]
393393+ self.profiles = [Profile(profile_name, json_root["profiles"][profile_name]) for
394394+ profile_name in sorted(json_root["profiles"].keys())]
400395 self.__set_parent_profile_refs()
401396 self.__mine_for_diamond_errors()
402397···422417 if profile.name in parent_path_set:
423418 return True
424419 parent_path_set.append(profile.name)
425425- for parent in profile.parent_profiles:
420420+ for parent in sorted(profile.parent_profiles, key=attrgetter("name")):
426421 if self.__has_diamonds(parent, parent_path_set):
427422 return True
428423 return False
···468463 Input is a file to write the code into, a dict where keys are length and
469464 the values are lists of strings of that length. And a suffix if any."""
470465 f.write(f"{tab_char}\tswitch (length) {{\n")
471471- for length in dict_of_lists:
466466+ for length in sorted(dict_of_lists.keys()):
472467 f.write(f"{tab_char}\tcase {str(length)}:\n\t\t")
473473- for path in dict_of_lists[length]:
468468+ for path in sorted(dict_of_lists[length]):
474469 f.write(if_strcmp.format(exttab=tab_char, check=path))
475470 f.write(f"{tab_char}{{\n{tab_char}\t\t\tbreak;\n{tab_char}\t\t}}\n")
476471 f.write(f"{tab_char}\tdefault: break;\n{tab_char}\t}}\n")
···514509 profile, dict_name), profile, profile.name, profile.extension_name)
515510 if profile.parent_profiles is None:
516511 return
517517- for pp in profile.parent_profiles:
512512+ for pp in sorted(profile.parent_profiles, key=attrgetter("name")):
518513 write_verify_func_body(f, pp, dict_name)
519514520515···722717 f.write('{\n')
723718 f.write('\tswitch(input)\n')
724719 f.write('\t{\n')
725725- for input in inputs:
720720+ for input in sorted(inputs):
726721 f.write(f'\tcase {input}: return "{input}";\n')
727722 f.write(f'\tdefault: return "UNKNOWN";\n')
728723 f.write('\t}\n')
···731726 f.write('enum xrt_input_name\n')
732727 f.write('xrt_input_name_enum(const char *input)\n')
733728 f.write('{\n')
734734- for input in inputs:
729729+ for input in sorted(inputs):
735730 f.write(f'\tif(strcmp("{input}", input) == 0) return {input};\n')
736731 f.write(f'\treturn XRT_INPUT_GENERIC_TRACKER_POSE;\n')
737732 f.write('}\n')
···741736 f.write('{\n')
742737 f.write('\tswitch(output)\n')
743738 f.write('\t{\n')
744744- for output in outputs:
739739+ for output in sorted(outputs):
745740 f.write(f'\tcase {output}: return "{output}";\n')
746741 f.write(f'\tdefault: return "UNKNOWN";\n')
747742 f.write('\t}\n')
···750745 f.write('enum xrt_output_name\n')
751746 f.write('xrt_output_name_enum(const char *output)\n')
752747 f.write('{\n')
753753- for output in outputs:
748748+ for output in sorted(outputs):
754749 f.write(f'\tif(strcmp("{output}", output) == 0) return {output};\n')
755750 f.write(f'\treturn XRT_OUTPUT_NAME_SIMPLE_VIBRATION;\n')
756751 f.write('}\n')