aides-spec/aides_spec/replacers/simple_replacer.py

34 lines
1,003 B
Python
Raw Normal View History

2025-01-02 21:26:20 +00:00
from aides_spec.replacers.base import BaseReplacer
2024-12-01 18:49:14 +00:00
class SimpleReplacer(BaseReplacer):
SIMPLE_REPLACEMENTS = {
"pkgname": "name",
"pkgver": "version",
"pkgrel": "release",
2025-01-05 08:37:11 +00:00
"pkgdesc": "desc",
2024-12-01 18:49:14 +00:00
"url": "homepage",
"arch": "architectures",
2025-01-05 08:37:11 +00:00
"depends": "deps",
2024-12-01 18:49:14 +00:00
"optdepends": "opt_deps",
}
def process(self):
root_node = self.tree.root_node
def find_replacements(node):
if node.type == "variable_name":
var_name = self._node_text(node)
if var_name in self.SIMPLE_REPLACEMENTS:
self.replaces.append(
{
"node": node,
"content": self.SIMPLE_REPLACEMENTS[var_name],
}
)
for child in node.children:
find_replacements(child)
find_replacements(root_node)
return self._apply_replacements()