From b315d122591acb03370c3cac50c81773ea6a532a Mon Sep 17 00:00:00 2001 From: Ulrich Date: Fri, 7 Aug 2026 21:48:46 +0200 Subject: [PATCH] extractor works --- .gitignore | 3 +++ data/8.0.8/party.json | 37 +++++++---------------------- extract.py | 54 ++++++++++++++++++++++++++++--------------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 36b13f1..86bf85b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ __pycache__/ # C extensions *.so +# temporary patchfiles +*.diff + # Distribution / packaging .Python build/ diff --git a/data/8.0.8/party.json b/data/8.0.8/party.json index c25e487..94ca27b 100644 --- a/data/8.0.8/party.json +++ b/data/8.0.8/party.json @@ -49,7 +49,8 @@ ], "kwargs": {}, "code": "cursor.execute(*table.update([table.identifier_types], [cls.identifier_types.sql_format(identifier_types)]))", - "phase": "after_super" + "phase": "after_super", + "condition": "configuration.identifier_types != identifier_types" }, { "object": "table", @@ -61,7 +62,8 @@ ], "kwargs": {}, "code": "table.update([table.identifier_types], [cls.identifier_types.sql_format(identifier_types)])", - "phase": "after_super" + "phase": "after_super", + "condition": "configuration.identifier_types != identifier_types" } ] }, @@ -71,31 +73,6 @@ "method": "__register__", "line": 859, "operations": [ - { - "object": "cursor", - "operation": "execute", - "line": 873, - "args": [ - "*table.update([table.type], [new], where=table.type == old)" - ], - "kwargs": {}, - "code": "cursor.execute(*table.update([table.type], [new], where=table.type == old))", - "phase": "after_super" - }, - { - "object": "table", - "operation": "update", - "line": 873, - "args": [ - "[table.type]", - "[new]" - ], - "kwargs": { - "where": "table.type == old" - }, - "code": "table.update([table.type], [new], where=table.type == old)", - "phase": "after_super" - }, { "object": "cursor", "operation": "execute", @@ -155,7 +132,8 @@ ], "kwargs": {}, "code": "cursor.execute(*table.update([table.code_compact], [table.code]))", - "phase": "after_super" + "phase": "after_super", + "condition": "fill_code_compact" }, { "object": "table", @@ -167,7 +145,8 @@ ], "kwargs": {}, "code": "table.update([table.code_compact], [table.code])", - "phase": "after_super" + "phase": "after_super", + "condition": "fill_code_compact" }, { "object": "cursor", diff --git a/extract.py b/extract.py index d07b08d..6152761 100644 --- a/extract.py +++ b/extract.py @@ -3,7 +3,6 @@ import ast import argparse import json -import re from pathlib import Path DEFAULT_REPO = "/home/uha4/tmp/tryton" @@ -29,25 +28,9 @@ class RegisterExtractor(ast.NodeVisitor): def extract_register(self, cls, func): - phase = "before_super" - operations = [] - for stmt in func.body: - - # Wurde super().__register__() aufgerufen? - if self.is_super_register(stmt): - phase = "after_super" - continue - - for call in ast.walk(stmt): - if isinstance(call, ast.Call): - - op = self.extract_call(call) - - if op: - op["phase"] = phase - operations.append(op) + self.walk_statements(func.body, operations, "before_super", None) self.results.append({ "file": self.filename, @@ -57,6 +40,41 @@ class RegisterExtractor(ast.NodeVisitor): "operations": operations, }) + + def walk_statements(self, statements, operations, phase, condition): + + for stmt in statements: + + if self.is_super_register(stmt): + phase = "after_super" + continue + + if isinstance(stmt, ast.If): + cond = ast.unparse(stmt.test) + self.walk_statements(stmt.body, operations, phase, cond) + self.walk_statements(stmt.orelse, operations, phase, condition) + continue + + value = getattr(stmt, "value", None) + if value is not None: + self.walk_expression(value, operations, phase, condition) + + def walk_expression(self, node, operations, phase, condition): + + if node is None: + return + + if isinstance(node, ast.Call): + op = self.extract_call(node) + if op: + op["phase"] = phase + if condition: + op["condition"] = condition + operations.append(op) + + for child in ast.iter_child_nodes(node): + self.walk_expression(child, operations, phase, condition) + def is_super_register(self, stmt): if not isinstance(stmt, ast.Expr):