aides-spec/alr_spec/replacers/simple_replacer.py

33 lines
981 B
Python
Raw Normal View History

2024-12-01 18:49:14 +00:00
from alr_spec.replacers.base import BaseReplacer
class SimpleReplacer(BaseReplacer):
SIMPLE_REPLACEMENTS = {
"pkgname": "name",
"pkgver": "version",
"pkgrel": "release",
"pkgdesc": "description",
"url": "homepage",
"arch": "architectures",
"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()