Skip to content
Permalink
Browse files
Dynamically fetch templates.
We need to fetch the updated/changed templates, rather than look
on-disk for them. Switch to using "requests.get()" to grab them from a
git server. Switch to URL, USERNAME, PASSWORD to do so.

Pass the template lines to Generator.write_file() instead of a fname.
  • Loading branch information
gstein committed Mar 25, 2021
1 parent a554f36 commit 9fde1dc954a3875d30123f17cc5c742c6d3381df
Showing 2 changed files with 14 additions and 11 deletions.
@@ -21,6 +21,7 @@
import asfpy.pubsub
import asfpy.syslog
import yaml
import requests

import gen

@@ -67,17 +68,21 @@ def __init__(self, cfg, debug=False):

self.gen = gen.Generator(url, special, cfg['explicit'])

tdir = cfg['generate']['template_dir']
self.auth = (cfg['generate']['template_username'],
cfg['generate']['template_password'],
)

turl = cfg['generate']['template_url']
odir = cfg['generate']['output_dir']
if debug:
print(f'TDIR: {tdir}\nODIR: {odir}')
print(f'TURL: {turl}\nODIR: {odir}')

self.mappings = { }
for name in cfg['generate']:
ob = cfg['generate'][name]
if isinstance(ob, dict):
# Note: NAME is unused, except as a descriptor/grouping
t = os.path.join(tdir, ob['template'])
t = turl + ob['template']
o = os.path.join(odir, ob['output'])
self.mappings[t] = o

@@ -101,9 +106,10 @@ def write_files(self):
self.write_signal = FAR_FUTURE
t0 = time.time()
if self.debug:
print('WRITE_FILES: written at', t0)
print('WRITE_FILES: beginning at', t0)
for t, o in self.mappings.items():
self.gen.write_file(t, o)
template = requests.get(t, auth=self.auth, timeout=30)
self.gen.write_file(template.text.splitlines(), o)
if self.debug:
print(f' DURATION: {time.time() - t0}')

9 gen.py
@@ -115,14 +115,11 @@ def group_members(self, group):
# Note: all member IDs are ascii, so convert to simple strings.
return [m.decode() for m in self.client.get_members(cn, dn, attr)]

def write_file(self, template, output):
print(f'WRITE_FILE: t="{template}" o="{output}"')

### we should open/read/cache the template lines. for now:
lines = open(template).read().splitlines()
def write_file(self, t_lines, output):
print(f'WRITE_FILE: writing to "{output}"')

new_z = [ ]
for line in lines:
for line in t_lines:
if line.startswith(':readonly:'):
# FORMAT:
# :readonly:/some/random/path

0 comments on commit 9fde1dc

Please sign in to comment.