def initialize_datatable_scripts_for_html_table_rendering(): logger.log_task_init("initializing datatable scripts") with open(constants.temporary_template_filepath, "r") as f: html_template = Template(f.read()) datatable_init_js_scripts_str = "" with open(constants.temporary_template_filepath, 'r') as f: for line in f.readlines(): result = constants.table_div_matcher_re.match(line) if result: div_id = html_utils.extract_id_from_html_elem(result.string) datatable_init_js_scripts_str += \ constants.datatable_declaration_js_script_tpl.format(div_id) html_template_str = html_template.safe_substitute( datatable_init_js_scripts=datatable_init_js_scripts_str) with open(constants.temporary_template_filepath, 'w') as f: logger.log_task_init( "overwriting {} with datatable init js scripts".format( constants.temporary_template_filepath)) f.write(html_template_str) logger.log_task_end( "overwriting {} with datatable init js scripts".format( constants.temporary_template_filepath)) logger.log_task_end("initializing datatable scripts")
def add_network_to_template(div_id, nodes_str, edges_str): logger.log_task_init("adding network id={} to template".format(div_id)) nodes_var_template_placeholder = \ constants.network_js_nodes_var_template_placeholder.format(div_id) edges_var_template_placeholder = \ constants.network_js_edges_var_template_placeholder.format(div_id) with open(constants.temporary_template_filepath, 'r') as f: html_template = Template(f.read()) html_template_str = html_template.safe_substitute( { nodes_var_template_placeholder: nodes_str, edges_var_template_placeholder: edges_str, div_id: "" } ) logger.log_task_end("adding network id={} to template".format(div_id)) with open(constants.temporary_template_filepath, 'w') as f: f.write(html_template_str)
def initialize_network_scripts(): logger.log_task_init("initializing network js scripts") network_js_scripts_str = "" with open(constants.temporary_template_filepath, 'r') as f: html_template = Template(f.read()) with open(constants.temporary_template_filepath, 'r') as f: for line in f.readlines(): result = constants.network_div_matcher_re.match(line) if result: div_id = html_utils.extract_id_from_html_elem(result.string) network_js_scripts_str += constants.network_js_script_tpl.format( div_id) html_template_str = html_template.safe_substitute( network_js_scripts=network_js_scripts_str) with open(constants.temporary_template_filepath, 'w') as f: logger.log_task_init( "overwriting {} with network init js scripts".format( constants.temporary_template_filepath)) f.write(html_template_str) logger.log_task_end( "overwriting {} with network init js scripts".format( constants.temporary_template_filepath)) logger.log_task_end("initializing network js scripts")
def generate_network_html(div_id, nodes, edges): logger.log_task_init('generating html for network id={}'.format(div_id)) nodes_str = json.dumps(nodes) edges_str = json.dumps(edges) logger.log_task_end('generating html for network id={}'.format(div_id)) return nodes_str, edges_str
def initialize_temporary_template_file(): logger.log_task_init("creating file '{}'".format( constants.temporary_template_filepath)) with open(constants.temporary_template_filepath, 'w+') as f: with open(constants.template_filename, 'r') as ifile: f.write(ifile.read()) logger.log_task_end("creating file '{}'".format( constants.temporary_template_filepath))
def generate_table_html(div_id, cols, rows, table_id=None, css_classes=None): logger.log_task_init('generating html for table id={}'.format(div_id)) df = pd.DataFrame(rows, columns=cols) table_html_str = df.to_html(table_id=table_id, classes=css_classes, index=False, justify='left') logger.log_task_end('generating html for table id={}'.format(div_id)) return table_html_str
def create_final_html_file(): logger.log_task_init("storing finalized html in file={}".format( constants.output_filename)) with open(constants.temporary_template_filepath) as f: html_str = f.read() with open(constants.output_filename, 'w+') as ofile: ofile.write(html_str) logger.log_task_end("storing finalized html in file={}".format( constants.output_filename))
def add_table_to_template(div_id, table_html_str): logger.log_task_init("adding table id={} to template".format(div_id)) with open(constants.temporary_template_filepath, 'r') as f: html_template = Template(f.read()) html_template_str = html_template.safe_substitute({div_id: table_html_str}) with open(constants.temporary_template_filepath, 'w') as f: f.write(html_template_str) logger.log_task_end("adding table id={} to template".format(div_id))
def initialize_workdir(): if not os.path.exists(constants.workdir_dirname): logger.log_task_init("creating directory '{}'".format( constants.workdir_dirname)) os.makedirs(constants.workdir_dirname) logger.log_task_end("creating directory '{}'".format( constants.workdir_dirname)) else: logger.log_message("directory '{}' already exists, removing it".format( constants.workdir_dirname)) shutil.rmtree(constants.workdir_dirname) initialize_workdir()
def remove_workdir(): logger.log_task_init("removing directory '{}'".format( constants.workdir_dirname)) shutil.rmtree(constants.workdir_dirname) logger.log_task_end("removing directory '{}'".format( constants.workdir_dirname))