extractor works

This commit is contained in:
2026-08-07 21:48:46 +02:00
parent 7bf43718e0
commit b315d12259
3 changed files with 47 additions and 47 deletions
+3
View File
@@ -7,6 +7,9 @@ __pycache__/
# C extensions # C extensions
*.so *.so
# temporary patchfiles
*.diff
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
+8 -29
View File
@@ -49,7 +49,8 @@
], ],
"kwargs": {}, "kwargs": {},
"code": "cursor.execute(*table.update([table.identifier_types], [cls.identifier_types.sql_format(identifier_types)]))", "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", "object": "table",
@@ -61,7 +62,8 @@
], ],
"kwargs": {}, "kwargs": {},
"code": "table.update([table.identifier_types], [cls.identifier_types.sql_format(identifier_types)])", "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__", "method": "__register__",
"line": 859, "line": 859,
"operations": [ "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", "object": "cursor",
"operation": "execute", "operation": "execute",
@@ -155,7 +132,8 @@
], ],
"kwargs": {}, "kwargs": {},
"code": "cursor.execute(*table.update([table.code_compact], [table.code]))", "code": "cursor.execute(*table.update([table.code_compact], [table.code]))",
"phase": "after_super" "phase": "after_super",
"condition": "fill_code_compact"
}, },
{ {
"object": "table", "object": "table",
@@ -167,7 +145,8 @@
], ],
"kwargs": {}, "kwargs": {},
"code": "table.update([table.code_compact], [table.code])", "code": "table.update([table.code_compact], [table.code])",
"phase": "after_super" "phase": "after_super",
"condition": "fill_code_compact"
}, },
{ {
"object": "cursor", "object": "cursor",
+36 -18
View File
@@ -3,7 +3,6 @@
import ast import ast
import argparse import argparse
import json import json
import re
from pathlib import Path from pathlib import Path
DEFAULT_REPO = "/home/uha4/tmp/tryton" DEFAULT_REPO = "/home/uha4/tmp/tryton"
@@ -29,25 +28,9 @@ class RegisterExtractor(ast.NodeVisitor):
def extract_register(self, cls, func): def extract_register(self, cls, func):
phase = "before_super"
operations = [] operations = []
for stmt in func.body: self.walk_statements(func.body, operations, "before_super", None)
# 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.results.append({ self.results.append({
"file": self.filename, "file": self.filename,
@@ -57,6 +40,41 @@ class RegisterExtractor(ast.NodeVisitor):
"operations": operations, "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): def is_super_register(self, stmt):
if not isinstance(stmt, ast.Expr): if not isinstance(stmt, ast.Expr):