From aed1c567f2704ac15acf97a16f7fef1e7824e40b Mon Sep 17 00:00:00 2001 From: Jonas Linter Date: Tue, 23 Sep 2025 09:40:11 +0200 Subject: [PATCH] trying to find out why there are so many different numbered versions --- CustomerType.txt | 14 ++++++++ CustomerType125.txt | 13 +++++++ src/CustomerType.txt | 0 src/CustomerType125.txt | 0 src/main.py | 12 +++++++ src/postprocessing.py | 77 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 CustomerType.txt create mode 100644 CustomerType125.txt create mode 100644 src/CustomerType.txt create mode 100644 src/CustomerType125.txt create mode 100644 src/postprocessing.py diff --git a/CustomerType.txt b/CustomerType.txt new file mode 100644 index 0000000..7647527 --- /dev/null +++ b/CustomerType.txt @@ -0,0 +1,14 @@ + def validate_StatusType1(self, value): + # Validate type StatusType1, a restriction on xs:string. + if value is not None and Validate_simpletypes_ and self.gds_collector_ is not None: + if not isinstance(value, str): + lineno = self.gds_get_node_lineno_() + self.gds_collector_.add_message('Value "%(value)s"%(lineno)s is not of the correct base simple type (str)' % {"value": value, "lineno": lineno, }) + return False + value = value + enumerations = ['ALPINEBITS_HANDSHAKE'] + if value not in enumerations: + lineno = self.gds_get_node_lineno_() + self.gds_collector_.add_message('Value "%(value)s"%(lineno)s does not match xsd enumeration restriction on StatusType1' % {"value" : encode_str_2_3(value), "lineno": lineno} ) + result = False + diff --git a/CustomerType125.txt b/CustomerType125.txt new file mode 100644 index 0000000..333e629 --- /dev/null +++ b/CustomerType125.txt @@ -0,0 +1,13 @@ + def validate_StatusType(self, value): + # Validate type StatusType, a restriction on xs:string. + if value is not None and Validate_simpletypes_ and self.gds_collector_ is not None: + if not isinstance(value, str): + lineno = self.gds_get_node_lineno_() + self.gds_collector_.add_message('Value "%(value)s"%(lineno)s is not of the correct base simple type (str)' % {"value": value, "lineno": lineno, }) + return False + value = value + enumerations = ['ALPINEBITS_HANDSHAKE'] + if value not in enumerations: + lineno = self.gds_get_node_lineno_() + self.gds_collector_.add_message('Value "%(value)s"%(lineno)s does not match xsd enumeration restriction on StatusType' % {"value" : encode_str_2_3(value), "lineno": lineno} ) + result = False \ No newline at end of file diff --git a/src/CustomerType.txt b/src/CustomerType.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/CustomerType125.txt b/src/CustomerType125.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/main.py b/src/main.py index bafdec2..7dce7ea 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ from alpinebits_guestrequests import ResGuest, RoomStay +from alpine_bits_classes import ResGuestType, ProfilesType, ProfileType, ProfileInfoType @@ -7,6 +8,17 @@ def main(): print(guest1) + profileInfo = ProfileInfoType() + + profile = ProfileType() + + + + profiles = ProfilesType() + + resGuest = ResGuestType() + + if __name__ == "__main__": main() \ No newline at end of file diff --git a/src/postprocessing.py b/src/postprocessing.py new file mode 100644 index 0000000..94314c0 --- /dev/null +++ b/src/postprocessing.py @@ -0,0 +1,77 @@ +""" +Script to verify if all classes in alpine_bits_classes.py with the same base name (e.g., CustomerType, CustomerType125, CustomerType576) +are structurally identical. This helps to identify duplicate dataclasses generated by generateDS. + +Usage: + python src/postprocessing.py + +Requirements: + - Only uses the standard library. +""" + +import ast +import re +from collections import defaultdict +from pathlib import Path + +def get_class_basenames(classname): + """Returns the base name of a class (e.g., CustomerType125 -> CustomerType)""" + return re.sub(r'\d+$', '', classname) + +def extract_classes(filepath): + """Parse the file and extract all class definitions as AST nodes.""" + with open(filepath, "r", encoding="utf-8") as f: + source = f.read() + tree = ast.parse(source) + classes = {} + for node in tree.body: + if isinstance(node, ast.ClassDef): + classes[node.name] = node + return classes + +def class_struct_signature(class_node): + """Return a tuple representing the structure of the class: base classes, method names, attribute names.""" + bases = tuple(base.id if isinstance(base, ast.Name) else ast.dump(base) for base in class_node.bases) + methods = [] + attrs = [] + for item in class_node.body: + if isinstance(item, ast.FunctionDef): + methods.append(item.name) + elif isinstance(item, ast.Assign): + for target in item.targets: + if isinstance(target, ast.Name): + attrs.append(target.id) + return (bases, tuple(sorted(methods)), tuple(sorted(attrs))) + +def main(): + file_path = Path(__file__).parent / "alpine_bits_classes.py" + classes = extract_classes(file_path) + grouped = defaultdict(list) + for cname in classes: + base = get_class_basenames(cname) + grouped[base].append(cname) + + identical = [] + different = [] + + for base, classnames in grouped.items(): + if len(classnames) > 1: + sigs = [class_struct_signature(classes[c]) for c in classnames] + if all(s == sigs[0] for s in sigs): + identical.append((base, classnames)) + else: + different.append((base, classnames)) + + print("=== Structurally Identical Groups ===") + for base, classnames in identical: + print(f"{base}: {', '.join(classnames)}") + + print("\n=== Structurally Different Groups ===") + for base, classnames in different: + print(f"{base}: {', '.join(classnames)}") + + + + +if __name__ == "__main__": + main() \ No newline at end of file