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
*.so
# temporary patchfiles
*.diff
# Distribution / packaging
.Python
build/
+8 -29
View File
@@ -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",
+36 -18
View File
@@ -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):