Simple/Complex templates / parsers
This commit is contained in:
parent
e3a37419e8
commit
3dc27cc868
4 changed files with 38 additions and 19 deletions
|
|
@ -6,11 +6,16 @@ from injectable import injectable, autowired, Autowired
|
|||
|
||||
from app.services import Passwords
|
||||
|
||||
class DotTemplate(Template):
|
||||
|
||||
class SimpleValueTemplate(Template):
|
||||
# Pozwala na kropki w nazwach placeholderów, np. ${user.name.first}
|
||||
idpattern = r'[_a-zA-Z][_a-zA-Z0-9.]*'
|
||||
|
||||
|
||||
class ComplexValueTemplate(SimpleValueTemplate):
|
||||
delimiter = '@'
|
||||
|
||||
|
||||
@injectable
|
||||
class Mo:
|
||||
@autowired
|
||||
|
|
@ -21,8 +26,12 @@ class Mo:
|
|||
raw = ''
|
||||
with open(mo_file, "r") as mo:
|
||||
raw = mo.read()
|
||||
tpl = DotTemplate(raw)
|
||||
rendered = tpl.substitute(self._passwords.get_values(tpl.get_identifiers()))
|
||||
cmp = ComplexValueTemplate(raw)
|
||||
rendered = cmp.substitute(self._passwords.get_values(cmp.get_identifiers()))
|
||||
smp = SimpleValueTemplate(rendered)
|
||||
ids = [_id + '.password' for _id in smp.get_identifiers()]
|
||||
mappings = {k.replace('.password', ''): v for k, v in self._passwords.get_values(ids).items()}
|
||||
rendered = smp.substitute(mappings)
|
||||
de_mo_ified = str(mo_file).replace(".mo", "")
|
||||
with open(de_mo_ified, "w") as mo:
|
||||
mo.write(rendered)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue