def make_py_file(f_in, f_out, g, old_files=None): t = pyratemp.Template(filename=f_in) out = open(f_out, 'w') out.write(t(g=g)) out.close() if old_files is not None and f_out in old_files: old_files.remove(f_out)
def make_file(f_in, f_out, cfg): f_tmp = '%s.swp' % f_out t = pyratemp.Template(filename=f_in) with open(f_tmp, 'w') as out: out.write(t(**cfg)) if os.path.exists(f_out) and filecmp.cmp(f_tmp, f_out): # Nothing changed, don't touch the file os.remove(f_tmp) return shutil.move(f_tmp, f_out)
def make_scm_file(f_in, f_out): t = pyratemp.Template( filename=f_in, data={ "srename": lambda gn, n: gn.replace("_", "-") + "." + n.replace("_", "-"), "srenameg": lambda gn: gn.replace("_", "-") }) with open(f_out, 'w') as out: out.write(t(groups=groups))
def make_file(f_in, f_out, old_files=None): f_tmp = '%s.swp' % f_out t = pyratemp.Template(filename=f_in) out = open(f_tmp, 'w') out.write(t(groups=groups)) out.close() if os.path.exists(f_out): if old_files is not None: old_files.remove(f_out) if filecmp.cmp(f_tmp, f_out): # Nothing changed, don't touch the file. os.remove(f_tmp) return shutil.move(f_tmp, f_out)
def gen(f_in, f_out): f_tmp = '%s.swp' % f_out t = pyratemp.Template(filename=f_in) out = open(f_tmp, 'w') out.write( t(sub=sub, objects=objects, observables=observables, dimensions=dimensions)) out.close() if os.path.exists(f_out): if filecmp.cmp(f_tmp, f_out): os.remove(f_tmp) return shutil.move(f_tmp, f_out)
def make_haskell_file(f_in, f_out): t = pyratemp.Template(filename=f_in, data={}) with open(f_out, 'w') as out: out.write(t(groups=groups))
def make_ocaml_file(f_in, f_out): t = pyratemp.Template(filename=f_in, data={"renameg": lambda g: g['groupname'].title()}) with open(f_out, 'w') as out: out.write(t(groups=groups))
# Note: this imposes the following additional "restrictions" on vars.conf: # - groups and variables names are case insensitive # - "__" (double underscore) is illegal in group or variable names # - <group name>__<variable name> cannot be the same for any two variables import sys import os from libshm.parse import parse, ParseError from lib import pyratemp as pyra GROUP_MEMBER_DELIMITER = "__" TYPES = ["int", "float", "double", "string", "bool"] TPL_DSHM_H = pyra.Template(filename="libshm/dtemplates/dshm.h") TPL_DSHM_C = pyra.Template(filename="libshm/dtemplates/dshm.c") TPL_DSHM_SCM = pyra.Template( filename="libshm/dtemplates/dshm.scm", data={"srename": lambda gn, n: gn.replace("_", "-") + "." + n.replace("_", "-")}) OUT_DSHM_H = "libshm/c/dshm.h" OUT_DSHM_C = "libshm/c/dshm.c" OUT_DSHM_SCM = "libshm/scm/dshm.scm" OUT_DSHM_IDX = "libshm/index/dshm_index" def fatal(msg): print("generate_dshm.py: " + msg, file=sys.stderr) sys.exit(1) # forward declaration for try/catch