This commit is contained in:
yumoqing 2025-04-19 13:21:18 +08:00
parent eb6f94529d
commit 05e2a58fff
4 changed files with 21 additions and 1 deletions

View File

@ -82,3 +82,17 @@ def tmpTml(f, ns):
wf.write(b) wf.write(b)
return p return p
if __name__ == '__main__':
import sys
import json
if len(sys.argv) < 3:
print(f'{sys.argv[0]} tmplfile jsonfile')
sys.exit(1)
te = MyTemplateEngine('.')
with codecs.open(sys.argv[1], 'r', 'utf-8') as f:
tmpl = f.read()
with codecs.open(sys.argv[2], 'r', 'utf-8') as f1:
ns = json.loads(f1.read())
print(te.renders(tmpl, ns))

View File

@ -113,7 +113,7 @@ class SSHNode:
self.conn = await self._connect(**j) self.conn = await self._connect(**j)
@asynccontextmanager @asynccontextmanager
async def getconnector(self): async def get_connector(self):
refconn = None refconn = None
for jj in self.jumpers: for jj in self.jumpers:
j = jj.copy() j = jj.copy()

4
test/test.json Normal file
View File

@ -0,0 +1,4 @@
{
"user":"John",
"who":"Thomas"
}

2
test/test.tmpl Normal file
View File

@ -0,0 +1,2 @@
this is a {{user}}'s documents
{{who}} want it