예제 #1
0
def process_tempita_pyx(fromfile, tofile):
    import tempita
    with file(fromfile) as f:
        tmpl = f.read()
    pyxcontent = tempita.sub(tmpl)
    assert fromfile.endswith('.pyx.in')
    pyxfile = fromfile[:-len('.pyx.in')] + '.pyx'
    with file(pyxfile, 'w') as f:
        f.write(pyxcontent)
예제 #2
0
def process_tempita_pyx(fromfile, tofile):
    import tempita
    with file(fromfile) as f:
        tmpl = f.read()
    pyxcontent = tempita.sub(tmpl)
    assert fromfile.endswith('.pyx.in')
    pyxfile = fromfile[:-len('.pyx.in')] + '.pyx'
    with file(pyxfile, 'w') as f:
        f.write(pyxcontent)
예제 #3
0
 def latex(self):
   '''Return the LaTeX code for the figure.'''
   context = { 'filename' : self._file._filename
             , 'options'  : ','.join(self._options)
             , 'caption'  : ' '.join(self._caption)
             , 'label'    : ''.join(self._label)
             , 'begb'    : '{'
             , 'endb'    : '}'
             }
   return tempita.sub( self.latex_template, **context )
예제 #4
0
  def write(self, stream):
    context = { 'preamble'    : self.preamble_latex
              , 'body'        : self.body_latex
              , 'figures'     : self.figures_latex
              , 'key'         : self.key_latex
              }
    context.update( self._config )
    text = tempita.sub( self.latex_template, **context )

    stream.write(text)
예제 #5
0
파일: core.py 프로젝트: wgsproul/wavemoth
def instantiate_template(name, **args):
    path = os.path.join(os.path.dirname(__file__), name)
    with file(path) as f:
        template = f.read()
    code = tempita.sub(template, **args)
    # Strip comments
    code, n = re.subn(r'/\*.*?\*/', '', code, flags=re.DOTALL)
    # Strip empty lines
    lines = [line for line in code.split('\n') if len(line.strip()) > 0]
    code = '\n'.join(lines)
    # Output processed file for debugging
    with file(path[:-len('.in')], 'w') as f:
        f.write(code)
    return code
예제 #6
0
파일: core.py 프로젝트: wavemoth/wavemoth
def instantiate_template(name, **args):
    path = os.path.join(os.path.dirname(__file__), name) 
    with file(path) as f:
        template = f.read()
    code = tempita.sub(template, **args)
    # Strip comments
    code, n = re.subn(r'/\*.*?\*/', '', code, flags=re.DOTALL)
    # Strip empty lines
    lines = [line for line in code.split('\n') if len(line.strip()) > 0]
    code = '\n'.join(lines)
    # Output processed file for debugging
    with file(path[:-len('.in')], 'w') as f:
        f.write(code)
    return code
예제 #7
0
파일: config.py 프로젝트: kcns008/maas
def compose_conditional_bootloader(ipv6, rack_ip=None):
    output = ""
    behaviour = chain(["if"], repeat("elsif"))
    for name, method in BootMethodRegistry:
        if method.arch_octet is not None:
            url = ('tftp://[%s]/' if ipv6 else 'tftp://%s/') % rack_ip
            if method.path_prefix:
                url += method.path_prefix
            url += '/%s' % method.bootloader_path
            output += tempita.sub(
                CONDITIONAL_BOOTLOADER,
                ipv6=ipv6, rack_ip=rack_ip, url=url,
                behaviour=next(behaviour),
                arch_octet=method.arch_octet,
                bootloader=method.bootloader_path,
                path_prefix=method.path_prefix,
                name=method.name,
                ).strip() + ' '

    # The PXEBootMethod is used in an else statement for the generated
    # dhcpd config. This ensures that a booting node that does not
    # provide an architecture octet, or architectures that emulate
    # uefi_amd64 or pxelinux can still boot.
    method = BootMethodRegistry.get_item('uefi_amd64' if ipv6 else 'pxe')
    if method is not None:
        url = ('tftp://[%s]/' if ipv6 else 'tftp://%s/') % rack_ip
        if method.path_prefix:
            url += method.path_prefix
        url += '/%s' % method.bootloader_path
        output += tempita.sub(
            DEFAULT_BOOTLOADER,
            ipv6=ipv6, rack_ip=rack_ip, url=url,
            bootloader=method.bootloader_path,
            path_prefix=method.path_prefix,
            name=method.name,
            ).strip()
    return output.strip()
예제 #8
0
    else:
        h = symbs[0]
        q = symbs[1:]
        exprs = ["{}_{}*({})".format(h, i, print_expr(q, inds + [i])) for i in range(4)]
        return str.join(" + ", exprs)


values = []
dvalues = []
for order in range(max_order + 1):
    expr = print_expr(["Phi{}".format(i) for i in range(order)])
    values.append(expr)
    dv = []
    for i in range(order):
        args = ["Phi{}".format(h) for h in range(order)]
        args[i] = "dPhi{}".format(i)
        dexpr = print_expr(args)
        dv.append(dexpr)
    dvalues.append(dv)

import tempita

with file("splines_cython.pyx.in") as f:
    txt = f.read()

s = tempita.sub(txt, values=values, dvalues=dvalues, max_order=max_order)

with file("splines_cython.pyx", "w") as f:
    f.write(s)
# print(s)
예제 #9
0
#!/usr/bin/env python
import tempita, sys
print tempita.sub(sys.stdin.read())
예제 #10
0
    #     dvalues.append(dv)


def get_values(order, multispline=False):
    values = []
    expr = print_expr(['Phi{}'.format(i) for i in range(order)],
                      multispline=multispline)
    return expr


def get_dvalues(order, i, multispline=False):
    args = ['Phi{}'.format(h) for h in range(order)]
    args[i] = 'dPhi{}'.format(i)
    dexpr = print_expr(args, multispline=multispline)
    return dexpr


import tempita

with open(ftemplate) as f:
    txt = f.read()

s = tempita.sub(txt,
                values=get_values,
                dvalues=get_dvalues,
                max_order=max_order)

with open(fout, 'w') as f:
    f.write(s)
#print(s)
예제 #11
0
#!/usr/bin/env python
import tempita, sys
print(tempita.sub(sys.stdin.read()))
예제 #12
0
 def latex(self):
   '''Return the LaTeX code for the paragraph.'''
   return tempita.sub( self.latex_template, name=self.name, opts = ','.join(self.opts) )
예제 #13
0
#!/usr/bin/env python2
import tempita, sys
print(tempita.sub(sys.stdin.read()))
예제 #14
0
    if len(ind) == d:
        return 'v_{}'.format(index(ind))
    else:
        j = len(ind)
        ind1 = ind + (0, )
        ind2 = ind + (1, )
        s = "(1-lam_{j})*({a}) + (lam_{j})*({b})".format(
            j=j, a=make_formula(d, ind1, mm), b=make_formula(d, ind2, mm))
        return s


formulas = [make_formula(i, tuple([]), None) for i in range(max_d + 1)]
from itertools import product

with open('multilinear_numba.py.in') as f:
    txt = f.read()

import tempita
# template = tempita.Template(txt,name='multilinear_numba.py.in' )
# code = template.substitute()

code = tempita.sub(txt,
                   max_d=max_d,
                   product=product,
                   index=index,
                   rindex=rindex,
                   formulas=formulas)

with open('multilinear_numba.py', 'w') as f:
    f.write(code)
예제 #15
0
    #     dv = []
    #     for i in range(order):
    #         args =  ['Phi{}'.format(h) for h in range(order)]
    #         args[i] = 'dPhi{}'.format(i)
    #         dexpr = print_expr( args )
    #         dv.append(dexpr)
    #     dvalues.append(dv)


def get_values(order, multispline=False):
        values = []
        expr = print_expr( ['Phi{}'.format(i) for i in range(order)], multispline=multispline )
        return expr

def get_dvalues(order, i, multispline=False):
    args =  ['Phi{}'.format(h) for h in range(order)]
    args[i] = 'dPhi{}'.format(i)
    dexpr = print_expr( args, multispline=multispline )
    return dexpr

import tempita

with open(ftemplate) as f:
    txt = f.read()

s = tempita.sub(txt,values=get_values,dvalues=get_dvalues,max_order=max_order)

with open(fout,'w') as f:
    f.write(s)
#print(s)
예제 #16
0
    N = ['(q_{}{})'.format(n,'+1'*i) for n,i in enumerate(binds)]
    # return str.join(' , ',  [ str.join('', e) for e in zip(M,N) ])
    return str.join(' , ',  N )

def make_formula(d,ind,mm):
    if len(ind) == d:
        return 'v_{}'.format(index(ind))
    else:
        j = len(ind)
        ind1 = ind + (0,)
        ind2 = ind + (1,)
        s = "(1-lam_{j})*({a}) + (lam_{j})*({b})".format(j=j, a=make_formula(d,ind1,mm), b=make_formula(d,ind2,mm))
        return s

formulas = [make_formula(i,tuple([]),None) for i in range(max_d+1)]
from itertools import product


with open('multilinear_numba.py.in') as f:
        txt = f.read()

import tempita
# template = tempita.Template(txt,name='multilinear_numba.py.in' )
# code = template.substitute()

code = tempita.sub(txt, max_d=max_d, product=product, index=index, rindex=rindex, formulas=formulas)

with open('multilinear_numba.py','w') as f:
        f.write(code)
예제 #17
0
        exprs = [
            '{}_{}*({})'.format(h, i, print_expr(q, inds + [i]))
            for i in range(4)
        ]
        return str.join(' + ', exprs)


values = []
dvalues = []
for order in range(max_order + 1):
    expr = print_expr(['Phi{}'.format(i) for i in range(order)])
    values.append(expr)
    dv = []
    for i in range(order):
        args = ['Phi{}'.format(h) for h in range(order)]
        args[i] = 'dPhi{}'.format(i)
        dexpr = print_expr(args)
        dv.append(dexpr)
    dvalues.append(dv)

import tempita

with file('splines_cython.pyx.in') as f:
    txt = f.read()

s = tempita.sub(txt, values=values, dvalues=dvalues, max_order=max_order)

with file('splines_cython.pyx', 'w') as f:
    f.write(s)
#print(s)