def get_application_data(self, args, schema, ignore_array_values=False): from sirepo import simulation_db if args.method == 'rpn_value': if ignore_array_values and re.search(r'^\{.*\}$', args.value): # accept array of values enclosed in curly braces args.result = '' return True v, err = self.eval_var(args.value) if err: args.error = err else: args.result = v return True if args.method == 'recompute_rpn_cache_values': self.recompute_cache(args.cache) return True if args.method == 'validate_rpn_delete': model_data = simulation_db.read_json( simulation_db.sim_data_file( args.simulationType, args.simulationId, )) args.error = self.validate_var_delete( args.name, model_data, schema, ) return True return False
def get_application_data(data, **kwargs): if data.method == 'compute_particle_ranges': return template_common.compute_field_range( data, _compute_range_across_frames) if data.method == 'rpn_value': # accept array of values enclosed in curly braces if re.search(r'^\{.*\}$', data.value): data.result = '' return data v, err = _code_var(data.variables).eval_var(data.value) if err: data.error = err else: data.result = v return data if data.method == 'recompute_rpn_cache_values': _code_var(data.variables).recompute_cache(data.cache) return data if data.method == 'validate_rpn_delete': model_data = simulation_db.read_json( simulation_db.sim_data_file(SIM_TYPE, data.simulationId)) data.error = _code_var(data.variables).validate_var_delete( data.name, model_data, _SCHEMA) return data raise AssertionError('unknown get_application_data: {}'.format(data))
def _create_zip(sim_type, sim_id, want_python): """Zip up the json file and its dependencies Args: sim_type (str): simulation type sim_id (str): simulation id want_python (bool): include template's python source? Returns: py.path.Local: zip file name """ from pykern import pkio from sirepo import simulation_db from sirepo.template import template_common #TODO(robnagler) need a lock with pkio.save_chdir(simulation_db.tmp_dir()): res = py.path.local(sim_id + '.zip') data = simulation_db.open_json_file(sim_type, sid=sim_id) files = template_common.lib_files(data) files.insert(0, simulation_db.sim_data_file(data.simulationType, sim_id)) if want_python: files.append(_python(data)) with zipfile.ZipFile( str(res), mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=True, ) as z: for f in files: z.write(str(f), f.basename) return res, data
def get_application_data(data, **kwargs): assert 'method' in data assert data.method in _METHODS, \ 'unknown application data method: {}'.format(data.method) cv = code_variable.CodeVar( data.variables, code_variable.PurePythonEval(_MADX_CONSTANTS), case_insensitive=True, ) if data.method == 'rpn_value': # accept array of values enclosed in curly braces if re.search(r'^\{.*\}$', data.value): data.result = '' return data v, err = cv.eval_var(data.value) if err: data.error = err else: data.result = v return data if data.method == 'recompute_rpn_cache_values': cv.recompute_cache(data.cache) return data if data.method == 'validate_rpn_delete': model_data = simulation_db.read_json( simulation_db.sim_data_file(data.simulationType, data.simulationId)) data.error = cv.validate_var_delete( data.name, model_data, _SCHEMA ) return data
def _create_zip(sim, want_python, out_dir): """Zip up the json file and its dependencies Args: sim (req): simulation want_python (bool): include template's python source? out_dir (py.path): where to write to Returns: py.path.Local: zip file name """ path = out_dir.join(sim.id + '.zip') data = simulation_db.open_json_file(sim.type, sid=sim.id) data.pkdel('report') files = sim_data.get_class(data).lib_files_for_export(data) files.insert(0, simulation_db.sim_data_file(sim.type, sim.id)) if want_python: files.append(_python(data)) with zipfile.ZipFile( str(path), mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=True, ) as z: for f in files: z.write(str(f), f.basename) return path, data
def _create_zip(sim_type, sim_id, want_python): """Zip up the json file and its dependencies Args: sim_type (str): simulation type sim_id (str): simulation id want_python (bool): include template's python source? Returns: py.path.Local: zip file name """ from pykern import pkio from sirepo import simulation_db from sirepo.template import template_common #TODO(robnagler) need a lock with pkio.save_chdir(simulation_db.tmp_dir()): res = py.path.local(sim_id + '.zip') data = simulation_db.open_json_file(sim_type, sid=sim_id) if 'report' in data: del data['report'] files = template_common.lib_files(data) files.insert(0, simulation_db.sim_data_file(data.simulationType, sim_id)) if want_python: files.append(_python(data)) with zipfile.ZipFile( str(res), mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=True, ) as z: for f in files: z.write(str(f), f.basename) return res, data
def get_application_data(data, **kwargs): if data.method == 'get_beam_input_type': if data.input_file: data.input_type = _sdds_beam_type_from_file(data.input_file) return data if data.method == 'rpn_value': v, err = _code_var(data.variables).eval_var(data.value) if err: data.error = err else: data.result = v return data if data.method == 'recompute_rpn_cache_values': _code_var(data.variables).recompute_cache(data.cache) return data if data.method == 'validate_rpn_delete': model_data = simulation_db.read_json( simulation_db.sim_data_file(SIM_TYPE, data.simulationId)) data.error = _code_var(data.variables).validate_var_delete( data.name, model_data, _SCHEMA) return data raise RuntimeError('unknown application data method: {}'.format( data.method))
def get_application_data(data, **kwargs): if data.method == 'get_elegant_sim_list': tp = _SIM_DATA.jspec_elegant_twiss_path() res = [] for f in pkio.sorted_glob(_SIM_DATA.jspec_elegant_dir().join('*', tp), ): assert str(f).endswith(tp) i = simulation_db.sid_from_compute_file(f) try: name = simulation_db.read_json( simulation_db.sim_data_file('elegant', i), ).models.simulation.name res.append(PKDict(simulationId=i, name=name)) except IOError: # ignore errors reading corrupted elegant sim files pass return { 'simList': res, } elif data.method == 'compute_particle_ranges': return template_common.compute_field_range( data, _compute_range_across_files) assert False, 'unknown application data method={}'.format(data.method)