def write_parameters(data, run_dir, is_parallel): rtfile = py.path.local(_parent_file(run_dir, RTSTRUCT_EXPORT_FILENAME)) if data['report'] == 'dvhReport' and rtfile.exists(): return if data['report'] in ('doseCalculation', 'dvhReport'): _, roi_models = _generate_rtstruct_file(_parent_dir(run_dir), _parent_dir(run_dir)) if data['report'] == 'doseCalculation': dose_calc = data.models.doseCalculation roi_data = roi_models['regionsOfInterest'] ptv_name = '' oar_names = [] for roi_number in roi_data: if roi_number == dose_calc.selectedPTV: ptv_name = roi_data[roi_number]['name'] elif roi_number in dose_calc.selectedOARs: oar_names.append(roi_data[roi_number]['name']) prescription = run_dir.join(PRESCRIPTION_FILENAME) simulation_db.write_json(prescription, { 'ptv': ptv_name, 'oar': oar_names, }) pkjinja.render_file( RESOURCE_DIR.join(DOSE_CALC_SH + '.jinja'), { 'prescription': prescription, 'beamlist': run_dir.join(_BEAMLIST_FILENAME), 'dicom_zip': _sim_file(data['simulationId'], _ZIP_FILE_NAME), }, output=run_dir.join(DOSE_CALC_SH), strict_undefined=True, ),
def write_parameters(data, run_dir, is_parallel): rtfile = py.path.local(_parent_file(run_dir, RTSTRUCT_EXPORT_FILENAME)) if data['report'] == 'dvhReport' and rtfile.exists(): return if data['report'] in ('doseCalculation', 'dvhReport'): _, roi_models = _generate_rtstruct_file(_parent_dir(run_dir), _parent_dir(run_dir)) if data['report'] == 'doseCalculation': dose_calc = data.models.doseCalculation roi_data = roi_models['regionsOfInterest'] ptv_name = '' oar_names = [] for roi_number in roi_data: if roi_number == dose_calc.selectedPTV: ptv_name = roi_data[roi_number]['name'] elif roi_number in dose_calc.selectedOARs: oar_names.append(roi_data[roi_number]['name']) prescription = run_dir.join(PRESCRIPTION_FILENAME) simulation_db.write_json( prescription, { 'ptv': ptv_name, 'oar': oar_names, }) pkjinja.render_file( RESOURCE_DIR.join(DOSE_CALC_SH + '.jinja'), { 'prescription': prescription, 'beamlist': run_dir.join(_BEAMLIST_FILENAME), 'dicom_zip': _sim_file(data['simulationId'], _ZIP_FILE_NAME), }, output=run_dir.join(DOSE_CALC_SH), strict_undefined=True, ),
def __init__(self, *args, **kwargs): super(T, self).__init__(*args, **kwargs) self.root_d = pkio.py_path(cfg.root_d) self.db_d = self.root_d.join(DB_SUBDIR) self.proprietary_source_d = self.root_d.join(PROPRIETARY_SUBDIR) self.rpm_source_d = self.root_d.join(RPM_SUBDIR) self.tmp_d = self.root_d.join(TMP_SUBDIR) self.secret_d = self.db_d.join(SECRET_SUBDIR) self.srv_d = self.root_d.join(SRV_SUBDIR) self.srv_host_d = self.srv_d.join(HOST_SUBDIR) self.base = PKDict() f = None try: for d in self.db_d, self.secret_d: for f in pkio.sorted_glob(d.join(ZERO_YML)): v = pkyaml.load_str( pkjinja.render_file( f, self.base, strict_undefined=True, ), ) merge_dict(self.base, v) except Exception: pkdlog('error rendering db={}', f) raise
def _render_file(self, path, j2_ctx): from pykern import pkjinja try: return pkjinja.render_file(path, j2_ctx, strict_undefined=True) except Exception as e: pkdlog('path={} exception={}', path, e) raise
def render_jinja(sim_type, v, name=PARAMETERS_PYTHON_FILE): """Render the values into a jinja template. Args: sim_type (str): application name v: flattened model data Returns: str: source text """ b = resource_dir(sim_type).join(name) return pkjinja.render_file(b + '.jinja', v)
def render_jinja(sim_type, v, name=PARAMETERS_PYTHON_FILE): """Render the values into a jinja template. Args: sim_type (str): application name v: flattened model data Returns: str: source text """ d = sirepo.sim_data.get_class(sim_type).resource_dir() if sim_type \ else sirepo.sim_data.resource_dir() return pkjinja.render_file( # append .jinja, because file may already have an extension d.join(name) + '.jinja', v, )
def render_static_jinja(base, ext, j2_ctx, cache_ok=False): """Render static template with jinja Args: base (str): base name of file, e.g. ``user-state`` ext (str): suffix of file, e.g. ``js`` j2_ctx (dict): jinja context cache_ok (bool): OK to cache the result? [default: False] Returns: Flask.Response: reply """ p = simulation_db.STATIC_FOLDER.join('{}/{}.{}'.format(ext, base, ext)) r = flask.Response( pkjinja.render_file(p, j2_ctx, strict_undefined=True), mimetype=MIME_TYPE[ext], ) if cache_ok: return headers_for_cache(r, path=p) return headers_for_no_cache(r)
def _render(*args, **kwargs): """Renders the template and adds to git""" pkjinja.render_file(*args, **kwargs) subprocess.check_call(['git', 'add', kwargs['output']])
def default_command(): import rsconf.component import rsconf.component.rsconf import rsconf.pkcli.tls root_d = db.cfg.root_d if root_d.check(): return '{}: already exists'.format(root_d) srv = pkio.mkdir_parent(root_d.join(db.SRV_SUBDIR)) def _sym(old, new_base=None): old = pkio.py_path(old) if not new_base: new_base = old.basename assert old.check(), \ '{}: does not exist'.format(old) srv.join(new_base).mksymlinkto(old, absolute=False) # ssh-keygen -q -N '' -C rsconf -t rsa -b 4096 -f /var/tmp/foo # -- don't need this db_d = pkio.mkdir_parent(root_d.join(db.DB_SUBDIR)) secret_d = pkio.mkdir_parent(db_d.join(db.SECRET_SUBDIR)) nginx_d = pkio.mkdir_parent(root_d.join(NGINX_SUBDIR)) boot_hdb = pkcollections.Dict(rsconf_db=pkcollections.Dict( secret_d=secret_d, channel='dev', )) j2_ctx = pkcollections.Dict( all_host='v9.radia.run', group=grp.getgrgid(os.getgid())[0], host='v4.radia.run', master='v3.radia.run', port=2916, root_d=root_d, srv_d=str(srv), uid=os.getuid(), user=pwd.getpwuid(os.getuid())[0], worker5_host='v5.radia.run', worker6_host='v6.radia.run', ) hosts = [h for h in j2_ctx.values() if str(h).endswith('.radia.run')] # bootstrap j2_ctx.update(boot_hdb) j2_ctx.rsconf_db.http_host = 'http://{}:{}'.format(j2_ctx.master, j2_ctx.port) j2_ctx.bkp = pkcollections.Dict(primary=j2_ctx.host) j2_ctx.passwd_f = rsconf.component.rsconf.passwd_secret_f(j2_ctx) for h in hosts: _add_host(j2_ctx, srv, h) _sym('~/src/radiasoft/download/bin/install.sh', 'index.html') _sym(pkresource.filename('rsconf/rsconf.sh'), 'rsconf.sh') dev_d = pkio.py_path(pkresource.filename('dev')) for f in pkio.walk_tree(dev_d): if str(f).endswith('~') or str(f).startswith('#'): continue x = str(f.relto(dev_d)) if not ('local/' in x and x.endswith('.sh.jinja')): x = re.sub('.jinja$', '', x) dst = root_d.join(x) pkio.mkdir_parent_only(dst) if f.basename == dst.basename: f.copy(dst) else: pkjinja.render_file(f, j2_ctx, output=dst, strict_undefined=True) n = [] for e in 'rpm', 'proprietary': d = pkio.py_path(root_d.dirname).join(e) pkio.mkdir_parent(d) root_d.join(e).mksymlinkto(d, absolute=False) n.append(str(d)) subprocess.check_call(['bash', str(secret_d.join('setup_dev.sh')), *n], ) # dev only, really insecure, but makes consistent builds easy _sym('~/src/radiasoft') _sym('~/src/biviosoftware') for h in hosts: # needed to be able to talk setup certs for registry so we can # pull private images from all hosts. Only used in dev, because # private registry doesn't protect against pushes from these hosts. if h != j2_ctx.master: subprocess.check_call( ['rsconf', 'host', 'init_docker_registry', h]) tls_d = secret_d.join(rsconf.component.TLS_SECRET_SUBDIR) tls_d.ensure(dir=True) for h in ( 'jupyter.' + j2_ctx.all_host, 'jupyter.' + j2_ctx.host, j2_ctx.all_host, j2_ctx.master, j2_ctx.worker5_host, j2_ctx.worker6_host, ): rsconf.pkcli.tls.gen_self_signed_crt( tls_d.join(h), h, ) rsconf.pkcli.tls.gen_self_signed_crt( tls_d.join('star.' + j2_ctx.host), '*.' + j2_ctx.host, j2_ctx.host, )