def write(self): # load and modify template = get_file_text_direct(self.template) lines = template.splitlines() for i in range(len(lines)): if 'INSERT_CAMPOS_HERE' in lines[i]: lines[ i] = ' campos_x = %s, campos_y = %s, campos_z = %s; // line written by SimpleWriter' % ( str(self.campos.x), str( self.campos.y), str(self.campos.z)) box = self.box lines[ i + 1] = ' box_x1 = %s, box_x2 = %s, box_y1 = %s, box_y2 = %s, box_z1 = %s, box_z2 = %s; // line written by SimpleWriter' % ( str(box.x1), str(box.x2), str(box.y1), str( box.y2), str(box.z1), str(box.z2)) lines[ i + 2] = ' invert_canvas = %s; // line written by SimpleWriter' % 'true' if self.invcanvas else 'false' self.text = '\n'.join(lines) # write to disk try: f = open(self.html_filename, 'w') f.write(self.text) finally: f.close()
def build(self): templ = get_file_text_direct(self.templatefile) t = self.Template(templ) c = self.Context({ 'instrument': self.instrument, 'campos_x': self.campos.x, 'campos_y': self.campos.y, 'campos_z': self.campos.z, }) self.text = t.render(c)
def write_browse(instrument, raybundle, dirname): ''' writes instrument definitions to html/ js ''' if not os.path.exists(dirname): os.mkdir(dirname) # write mcdisplay.js mcd_filepath = os.path.join(os.path.dirname(__file__), 'mcdisplay.js') file_save(get_file_text_direct(mcd_filepath), os.path.join(dirname, '_mcdisplay.js')) # write other necessary .js files mcd_filepath = os.path.join(os.path.dirname(__file__), 'three.min.js') file_save(get_file_text_direct(mcd_filepath), os.path.join(dirname, 'three.min.js')) mcd_filepath = os.path.join(os.path.dirname(__file__), 'dat.gui.min.js') file_save(get_file_text_direct(mcd_filepath), os.path.join(dirname, 'dat.gui.min.js')) mcd_filepath = os.path.join(os.path.dirname(__file__), 'OrbitControls.js') file_save(get_file_text_direct(mcd_filepath), os.path.join(dirname, 'OrbitControls.js')) mcd_filepath = os.path.join(os.path.dirname(__file__), 'Lut.js') file_save(get_file_text_direct(mcd_filepath), os.path.join(dirname, 'Lut.js')) mcd_filepath = os.path.join(os.path.dirname(__file__), 'jquery.min.js') file_save(get_file_text_direct(mcd_filepath), os.path.join(dirname, 'jquery.min.js')) # write html html_filepath = os.path.join(dirname, 'index.html') _write_html(instrument, html_filepath, first=args.first, last=args.last, invcanvas=args.invcanvas) # write instrument json_instr = 'MCDATA_instrdata = %s;' % json.dumps(instrument.jsonize(), indent=0) file_save(json_instr, os.path.join(dirname, '_instr.js')) # write particles json_neutr = 'MCDATA_particledata = %s;' % json.dumps(raybundle.jsonize(), indent=0) file_save(json_neutr, os.path.join(dirname, '_particles.js')) # exit if nobrowse flag has been set if args.nobrowse: return # open a web-browser in a cross-platform way try: subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], html_filepath), shell=True) except Exception as e: raise Exception('Os-specific open browser: %s' % e.__str__())