def _init(): """ This must be called once before any work """ RadiometryContext.struct_fixup() if local.env.get("PLASTER_C_COMPILE"): with local.cwd(c_radiometry_path): fp = StringIO() with redirect_stdout(fp): print( f"// This file was code-generated by sigproc_v2.c_radiometry.c_radiometry.load_lib and should be version controlled" ) print() print("#ifndef RADIOMETRY_H") print("#define RADIOMETRY_H") print() print('#include "stdint.h"') print('#include "c_common.h"') print() RadiometryContext.struct_emit_header(fp) print("#endif") header_file_path = "./_radiometry.h" existing_h = utils.load(header_file_path, return_on_non_existing="") if existing_h != fp.getvalue(): utils.save(header_file_path, fp.getvalue()) build_dev()
def _init(): """ Must be called before anything else in this module """ SurveyV2Context.struct_fixup() if local.env.get("PLASTER_C_COMPILE"): with local.cwd(lib_folder): fp = StringIO() with redirect_stdout(fp): print( f"// This file was code-generated by survey_v2.c.survey_v2.init and should be version controlled" ) print() print("#ifndef SIM_V2_H") print("#define SIM_V2_H") print() print('#include "stdint.h"') print('#include "c_common.h"') print() SurveyV2Context.struct_emit_header(fp) print("#endif") header_file_path = "./_survey_v2.h" existing_h = utils.load(header_file_path, return_on_non_existing="") if existing_h != fp.getvalue(): utils.save(header_file_path, fp.getvalue()) build_dev()
def _init(): """ Must be called before anything else in this module """ NNV2Context.struct_fixup() if local.env.get("PLASTER_C_COMPILE"): with local.cwd(c_nn_v2_path): fp = StringIO() with redirect_stdout(fp): print( f"// This file was code-generated by nn_v2.c.nn_v2.load_lib and should be version controlled" ) print() print("#ifndef NN_V2_H") print("#define NN_V2_H") print() print('#include "pthread.h"') print('#include "stdint.h"') print('#include "c_common.h"') print() NNV2ScoringVerboseFields.emit_col_name_defines(fp) print() NNV2Context.struct_emit_header(fp) print("#endif") header_file_path = "./_nn_v2.h" existing_h = utils.load(header_file_path, return_on_non_existing="") if existing_h != fp.getvalue(): utils.save(header_file_path, fp.getvalue()) build_dev()
def cache_source(cache_folder, source, copy_to): """ If this is a URL or S3 fetch and cache at cache_folder. Local files can be loaded from //jobs_folder/... only. In all cases, the cached file is optionally copied to copy_to so that that job folders contain a copy of all gen source data. Returns: the contents of the file """ def make_cache_path(): local.path(cache_folder).mkdir() return ( local.path(cache_folder) / hashlib.md5(source.encode("utf-8")).hexdigest() ) file_contents = None if source.startswith("http://") or source.startswith("https://"): cache_path = make_cache_path() if not cache_path.exists(): important(f"Fetching {source}... (TO {cache_path})") file_contents = _url_get(source) utils.save(cache_path, file_contents) else: file_contents = utils.load(cache_path) elif source.startswith("s3://"): cache_path = make_cache_path() if not cache_path.exists(): tell(f"Syncing from {source} to {cache_path}") local["aws"]["s3", "cp", source, cache_path] & FG # s3 cp already saves it to disk, fall thru & load file_contents = utils.load(cache_path) else: file_contents = utils.load(source) assert file_contents is not None if copy_to: assert local.path(copy_to).exists() filename = local.path(source).basename utils.save(copy_to / filename, file_contents) return file_contents
def _init(): """ Must be called before anything else in this module """ SimV2Context.struct_fixup() # Dyt.struct_fixup() PCB.struct_fixup() Counts.struct_fixup() DyePepRec.struct_fixup() if local.env.get("PLASTER_C_COMPILE"): with local.cwd(lib_folder): fp = StringIO() with redirect_stdout(fp): print( f"// This file was code-generated by sim_v2.c.sim_v2.init and should be version controlled" ) print() print("#ifndef SIM_V2_H") print("#define SIM_V2_H") print() print('#include "stdint.h"') print('#include "c_common.h"') print() print( textwrap.dedent("""\ typedef struct { Size count; Index dyt_i; DyeType chcy_dye_counts[]; // Note, this is a variable sized record // See dyt_* functions for manipulating it } Dyt; // Dye-track record """)) print() SimV2Context.struct_emit_header(fp) # Dyt.struct_emit_header(fp) PCB.struct_emit_header(fp) Counts.struct_emit_header(fp) print("#endif") header_file_path = "./_sim_v2.h" existing_h = utils.load(header_file_path, return_on_non_existing="") if existing_h != fp.getvalue(): utils.save(header_file_path, fp.getvalue()) build_dev()
def html_template(title, scripts): root = os.environ.get("ERISYON_ROOT") assert root zscript = load(root + "/tools/html/zscript.js") newline = "\n" return ((f""" <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>{title}</title> <link rel="icon" href="data:;base64,iVBORw0KGgo="> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <link rel="stylesheet" href="https://cdn.datatables.net/1.10.18/css/dataTables.bootstrap4.min.css" crossorigin="anonymous"> <script src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js" crossorigin="anonymous"></script> <script src="https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap4.min.js" crossorigin="anonymous"></script> <script> {zscript} </script> { newline.join([f"<script>{newline}{script}{newline}</script>" for script in scripts]) } """) + (""" <script> $(document).ready(function() { setInterval( function interval() { $(".timesince").each((i, item) => { $(item).text( timeSince($(item).data("date")) + " ago" ); }); return interval; }(), 1000); }); </script> </head> <body id="main" class="container"> </body> </html> """))
def profile_from_file(log_file): log_str = utils.load(log_file, return_on_non_existing="") return profile_from_string(log_str)