コード例 #1
0
ファイル: proxy.py プロジェクト: yota-code/marccup
    def _prep_section(self, book_key, ident):

        base_dir = self.repo_dir / book_key

        b = marccup.parser.generic.GenericParser()
        u = marccup.composer.html5.Html5Composer()

        t = (base_dir / 'part' / f'{ident:04d}').read_text()

        o = b.parse(t)

        g = oaktree.proxy.braket.BraketProxy()
        k = oaktree.proxy.braket.BraketProxy(indent='')

        g.save(o, Path(base_dir / ".tmp" / f'{ident:04d}.parsed.bkt'))
        #k.save(o, Path( base_dir / ".tmp" / f'{ident:04d}.parsednoindent.bkt'))

        h = oaktree.Leaf('tmp')
        u.compose(o, h)

        #g.save(h.sub[0], Path( base_dir / ".tmp" / f'{ident:04d}.composed.bkt'))
        #k.save(h.sub[0], Path( base_dir / ".tmp" / f'{ident:04d}.composednoindent.bkt'))

        f = oaktree.proxy.html5.Html5Proxy(indent='', fragment=True)
        #f.save(h.sub[0], Path( base_dir / ".tmp" / f'{ident:04d}.result.html'))
        f.save(h.sub[0], Path(base_dir / ".cache" / "part" / f'{ident:04d}'))

        return f.save(h.sub[0])
コード例 #2
0
    def __init__(self, shelf=None, proxy=None):

        self.static_dir = Path(os.environ['SPEXT_static_DIR'])
        self.repo_dir = Path(os.environ['SPEXT_repo_DIR'])

        self.shelf = shelf
        self.proxy = proxy

        self.book_lst = (self.repo_dir / "index.json").load()
コード例 #3
0
ファイル: disabled.py プロジェクト: yota-code/goto.trajbang
    def plot(self, save_dir=None):
        v, f, n, d, t, z = self.prep()

        t_xx, j_xx, a_xx, s_xx = self.t_xx, self.j_xx, self.a_xx, self.s_xx

        T, J, A, S = self.symbolic_equation(n)

        plt.figure(figsize=(8.27, 11.69))
        title = f"{self.bch} :: {self.param} :: {f(self.pg):0.5e}"

        ###  jerk  ###
        plt.subplot(3, 1, 1)
        for i in range(n):
            plt.plot([
                t_xx[i][0],
            ] + list(t_xx[i]) + [
                t_xx[i][-1],
            ], [
                0.0,
            ] + list(j_xx[i]) + [
                0.0,
            ])
        plt.grid()
        plt.title(title)
        plt.ylabel("jerk")

        ###  acceleration  ###
        plt.subplot(3, 1, 2)
        for i in range(n):
            plt.plot(t_xx[i], a_xx[i])
        print([i.subs(v) for i in A])
        a_lst = [f(i) for i in A]
        plt.plot(t, a_lst, 'o', color="grey")
        plt.grid()
        plt.ylabel("acceleration")

        ###  speed  ###
        plt.subplot(3, 1, 3)
        for i in range(n):
            plt.plot(t_xx[i], s_xx[i])
        s_lst = [f(i) for i in S]
        plt.plot(t, s_lst, 'o', color="grey")
        plt.grid()
        plt.ylabel("speed")

        # check_sg, check_ag = check_target(s_lst[-1], val['S_g']), check_target(a_lst[-1], 0.0)

        if save_dir:
            save_pth = Path(save_dir) / f"trajbang3({self.param}).png"
            Path(save_dir).make_dirs()
            plt.savefig(str(save_pth))
            print(save_pth)
            plt.close()
        else:
            save_pth = None
            plt.show()
コード例 #4
0
    def save(self, pth):

        pth = Path(pth).with_suffix('.tsv')

        stack = [
            self.rec_lst,
        ]
        for i in range(len(self.rec['t'])):
            stack.append([self.rec[k][i] for k in self.rec_lst])

        pth.save(stack)
コード例 #5
0
    def __init__(self):
        self.static_dir = Path(os.environ['MARCCUP_static_DIR'])

        self.shelf = marccup.server.shelf.MarccupShelf()
        self.proxy = marccup.server.proxy.MarccupProxy()

        self.to_html5 = marccup.composer.html5.Html5Composer()
コード例 #6
0
ファイル: shelf.py プロジェクト: yota-code/spext
class SpextShelf() :

	""" un objet générique, à instancier une seule fois, qui maintient la liste de tous les livres disponibles,
	permet la mise à jour des caches et la generation à la volée """
	def __init__(self, repo_dir, debug=True) :
		self.repo_dir = Path(repo_dir).resolve()
		self.debug = debug

		self.book_map = dict()

	def scan(self, check=False) :
		print(f">>> SpextShelf.scan({self.repo_dir})")

		for pth in self.repo_dir.rglob('__doc__') :
			key = str(pth.parent.relative_to(self.repo_dir))
			print(f"SpextShelf.scan({key})")
			
			value = spext.book.BookHandler(pth.parent)

			if check :
				value.check()

			self.book_map[key] = value

		(self.repo_dir / "index.json").save(sorted(self.book_map))
		print(f">>> SpextShelf.scan() DONE")
コード例 #7
0
ファイル: buildsystem.py プロジェクト: yota-code/spext
	def __init__(self, base_dir, local_pth='.build_cache.shelve'): 
		self.base_dir = Path(base_dir)
		self.local_pth = str(local_pth)q

		pth = self.cache_pth
		pth.make_parents()

		self.file_map = dict()
		self.in_progress = dict()
コード例 #8
0
	def __init__(self, node_name, replay_no) :
		self.node_name = node_name
		self.replay_no = replay_no
		
		self.node_dir = Path(os.environ["UNITEST_build_DIR"]).resolve() / node_name
		self.replay_dir = self.node_dir / "replay" / replay_no
		
		
		self.data_len = None
		self.data_pth = self.replay_dir / "context.reb"
コード例 #9
0
    def __init__(self):
        self.repo_dir = Path(os.environ['MARCCUP_repo_DIR'])

        self.book_set = set()

        for book_key in self.scan(self.repo_dir):
            self.install(book_key)
            self.book_set.add(book_key)

        print(self.book_set)
コード例 #10
0
    def _get_section(self, *pos, **nam):
        if 'b' not in nam or 's' not in nam:
            raise cherrypy.HTTPError(400)

        if nam['b'] not in self.shelf.book_set:
            raise cherrypy.HTTPError(404)

        return self.proxy._get_section(nam['b'], int(nam['s']))

        s = int(nam['s'])
        b = self.shelf[nam['b']]
        t = (b.base_dir / 'part' / f'{s:04d}').read_text()
        e = b.expand_shortcut(t)

        Path(b.base_dir / ".tmp" / f'{s:04d}.expanded.bkt').write_text(e)

        o = b.parse_section(e)

        g = oaktree.proxy.braket.BraketProxy()
        k = oaktree.proxy.braket.BraketProxy(indent='')

        g.save(o, Path(b.base_dir / ".tmp" / f'{s:04d}.parsed.bkt'))
        k.save(o, Path(b.base_dir / ".tmp" / f'{s:04d}.parsednoindent.bkt'))

        h = oaktree.Leaf('tmp')
        self.to_html5.compose(o, h)

        g.save(h.sub[0], Path(b.base_dir / ".tmp" / f'{s:04d}.composed.bkt'))
        k.save(h.sub[0],
               Path(b.base_dir / ".tmp" / f'{s:04d}.composednoindent.bkt'))

        f = oaktree.proxy.html5.Html5Proxy(indent='', fragment=True)
        f.save(h.sub[0], Path(b.base_dir / ".tmp" / f'{s:04d}.result.html'))

        return f.save(h.sub[0])
コード例 #11
0
ファイル: __init__.py プロジェクト: yota-code/goto.globe
 def to_wsk_qnd_point(self, r_lst):
     w_lst = [
         "wsk_qnd_point_T wsk_qnd_line_arr[wsk_qnd_line_LEN] = {",
     ]
     for verb, lat, lon, radius, alt, spd, width in r_lst:
         print(verb, lat, lon, radius, alt, spd, width)
         verb_id = 0 if radius == 0.0 else 1
         w_lst.append('\t' +
                      str([verb_id, [lat, lon], alt, spd, radius]).replace(
                          '[', '{').replace(']', '}') + ',')
     w_lst.append("};")
     w_txt = '\n'.join(w_lst)
     Path("4_wsk_qnd.c").write_text(w_txt)
コード例 #12
0
ファイル: __init__.py プロジェクト: yota-code/spext
	def __init__(self, base_dir) :
		self.base_dir = Path(base_dir).resolve()

		self.toc = spext.book.toc.BookToc(self)
		self.ref = spext.book.ref.BookRef(self)

		self.cache_dir = self.base_dir / '.cache'
		self.cache_dir.make_dirs()

		(self.cache_dir / 'part').make_dirs()

		self.log_pth = None

		self.ident_set = None
		self._last_ident = None
コード例 #13
0
    def check(self,
              a0: float,
              s0: float,
              ag: float,
              sg: float,
              result_dir=None):
        jm, am, a0, s0, ag, sg = self.__prep__(a0, s0, ag, sg)

        val = self.val

        def f(e):
            try:
                return float(e.subs(val))
            except AttributeError:
                return float(e)

        res = self.compute(a0, s0, ag, sg)

        cmd, dur, T, J, A, S, D = self.integrate(res)

        # check all acceleration values are inside the limits (except a0 which can be out of bounds)
        ai_condition = all(self.check_is_inside(f(i), -am, am) for i in A[1:])

        ag_condition = self.check_is_close(f(A[-1]), ag)
        sg_condition = self.check_is_close(f(S[-1]), sg)

        total_condition = ag_condition and ai_condition and sg_condition

        print(
            f"TrajBang3(jm={jm}, am={am}, a0={a0}, s0={s0}, ag={ag}, sg={sg}) ==>",
            k(total_condition))

        print("> cmd :", '\t'.join(f"{i:5g}" for i in cmd))
        print("> dur :", '\t'.join(f"{i:5g}" for i in dur))
        print("-" * 4)
        print(
            "  > T :", '\t'.join(f"{i:5g}" for i in ([
                0.0,
            ] + list(itertools.accumulate(T)))))
        print("  > A :", '\t'.join(f"{i:5g}" for i in A), f" \t=( {ag} )>",
              k(ag_condition), k(ai_condition))
        print("  > S :", '\t'.join(f"{i:5g}" for i in S), f" \t=( {sg} )>",
              k(sg_condition))
        print("  > D :", '\t'.join(f"{i:5g}" for i in D))

        if not total_condition:
            with Path('error_listing.log').open('at') as fid:
                fid.write(f"\n{self.title} ==>\n\t{cmd}\n\t{dur}\n")
コード例 #14
0
    def _prep_section(self, key, ident):

        base_dir = self.repo_dir / key
        cache_dir = base_dir / '.cache'

        local_pth = Path('part') / f'{ident:05d}'

        # read the source_file
        src_pth = base_dir / local_pth
        src_byt = src_pth.read_bytes()
        src_hsh = '<!-- {0} -->'.format(hashlib.blake2s(src_byt).hexdigest())

        # check the hash of the cached version
        dst_pth = cache_dir / local_pth
        try:
            with dst_pth.open('rt') as fid:
                dst_hsh = fid.readline().strip()
        except FileNotFoundError:
            dst_hsh = ''

        if dst_hsh != src_hsh or key == '_test':
            print(
                f">>> SpextProxy._prep_section({key}, {ident}) \x1b[33mPROCESSED\x1b[0m"
            )

            src_txt = src_byt.decode('utf8')

            if key == '_test':
                debug_dir = base_dir / '.debug' / f'{ident:05d}'
                debug_dir.make_dirs()
            else:
                debug_dir = None

            dst_txt = self.mcp_to_html(src_txt, debug_dir)

            with dst_pth.open('wt') as fid:
                fid.write(src_hsh + '\n')
                fid.write(dst_txt)

        else:
            print(
                f">>> SpextProxy._prep_section({key}, {ident}) \x1b[36mCACHED\x1b[0m"
            )
コード例 #15
0
ファイル: _unitest_prepare.py プロジェクト: yota-code/unitest
def unroll_tempate(node_name, template_name, context_info):

    node_dir = Path(os.environ['UNITEST_build_DIR']) / node_name
    if not node_dir.is_dir():
        raise ValueError("Not a valid model directory:{0}".format(node_dir))

    template_dir = Path(os.environ['UNITEST_template_DIR']) / template_name
    if not template_dir.is_dir():
        raise ValueError(
            "Not a valid template directory:{0}".format(template_dir))

    unitest.unroll_template_folder(template_dir, node_dir, {
        'scade_map': context_info,
        'node_name': node_name
    })
コード例 #16
0
    def _prep_refer(self, book_key):

        # un fichier appelé référence, qui contient, pour chaque section, la liste des
        # alinea, paragraphes, figures, equations (ou l'inverse)
        # ce fichier est créé s'il n'existe pas, mais il n'est mis à jour que lorsqu'un fichier est modifié
        # ou lors d'une requête explicite

        refer_map = dict()

        section_set = set(
            int(pth.name)
            for pth in (self.repo_dir / book_key / 'part').glob('*'))

        other_set = set()
        for s_ident in sorted(section_set):

            pth = self.repo_dir / book_key / 'part' / f'{s_ident:04d}'

            txt = pth.read_text()

            u = marccup.parser.book.BookParser()
            o_section = u.parse(txt)

            b = oaktree.proxy.braket.BraketProxy()
            b.save(o_section, Path('debug.bkt'))

            for o in o_section.walk():
                if o.ident != None:
                    other_set.add(o.ident)
                    if o.tag not in refer_map:
                        refer_map[o.tag] = collections.defaultdict(set)
                    refer_map[o.tag][s_ident].add(o.ident)

        refer_map['__next__'] = max(section_set | other_set) + 1

        dst_pth = self.repo_dir / book_key / '.cache' / 'refer.json'
        dst_pth.save(refer_map)

        print(refer_map)

        return refer_map
コード例 #17
0
ファイル: _unitest_prepare.py プロジェクト: yota-code/unitest
def map_interface(node_name, include_lst):
    cwd = Path(os.environ['UNITEST_build_DIR']) / node_name / "mapping"
    cwd.make_dirs()

    (cwd / 'structarray_interface.c').write_text(scade_interface_template)

    cmd = (["gcc", "-save-temps", "-std=c99", "-g"] +
           [f"-I{str(include_dir)}" for include_dir in include_lst] +
           ["structarray_interface.c", "-o", "structarray_interface.exe"])
    ret = cwd.run(*cmd)
    if ret.returncode != 0:
        raise ValueError("gcc couldn't compile properly")

    ret = cwd.run("./structarray_interface.exe")

    for k in ["input", "output"]:
        u = structarray.StructInfo(cwd / 'structarray_interface.exe')
        u.parse(k)
        u.save(cwd, k)
コード例 #18
0
ファイル: array.py プロジェクト: yota-code/structarray
    def __init__(self, meta=None, data=None):

        self.meta = None
        self.data = None

        self.length = 0

        if meta is not None:
            m = Path(meta)
            if m.is_file():
                self.meta = m
                self.load_meta(m)

        if data is not None:
            d = Path(data)
            if d.is_file():
                self.data = d
                self.load_data(d)

        self.extract_map = dict()
        self.extract_lst = list()
コード例 #19
0
ファイル: _unitest_prepare.py プロジェクト: yota-code/unitest
def map_context(node_name, include_lst):

    cwd = Path(os.environ['UNITEST_build_DIR']) / node_name / "mapping"
    cwd.make_dirs()

    (cwd / 'structarray_context.c').write_text(
        scade_context_template.format(node_name=node_name))

    cmd = (["gcc", "-save-temps", "-std=c99", "-g"] +
           [f"-I{str(include_dir)}" for include_dir in include_lst] +
           ["structarray_context.c", "-o", "structarray_context.exe"])
    ret = cwd.run(*cmd)
    if ret.returncode != 0:
        raise ValueError("gcc couldn't compile properly")

    ret = cwd.run("./structarray_context.exe")
    txt = ret.stdout.decode(sys.stdout.encoding)
    (cwd / "structarray_ctype.json").write_text(txt.replace(',\n}', '\n}'))

    u = structarray.StructInfo(cwd / 'structarray_context.exe')
    u.parse('context')
    u.save(cwd, 'context')

    return u
コード例 #20
0
ファイル: plot.py プロジェクト: yota-code/trajbang
def plot_3(c, d, val, prefix="check/"):

    # on recopie val
    val = {k: v for k, v in val.items()}

    n = len(c)

    T, J, A, S = symbolic_equation_3(n)

    print("d = ", d)
    t = np.cumsum([
        0.0,
    ] + d)
    print("t = ", t)
    z = [float(i * val['J_m']) for i in c]
    print("z = ", z)

    for i in range(n):
        val[f"T_{i}"] = d[i]
        val[f"J_{i}"] = z[i]

    t_xx = [np.linspace(t[i], t[i + 1], 50) for i in range(n)]

    plt.figure(figsize=(8.27, 11.69))

    title = f"jm={val['J_m']}, am={val['A_m']}, a0={val['A_0']}, s0={val['S_0']}, sg={val['S_g']}"

    ###  jerk  ###
    plt.subplot(3, 1, 1)
    j_xx = [(np.ones_like(t_xx[0]) * z[i]) for i in range(n)]
    for i in range(n):
        plt.plot([
            t_xx[i][0],
        ] + list(t_xx[i]) + [
            t_xx[i][-1],
        ], [
            0.0,
        ] + list(j_xx[i]) + [
            0.0,
        ])
    plt.grid()
    plt.title(title)
    plt.ylabel("jerk")

    ###  acceleration  ###
    plt.subplot(3, 1, 2)
    a_xx = list()
    for i in range(n):
        a_xx.append((a_xx[-1][-1] if a_xx else val['A_0']) +
                    (t_xx[i] - t[i]) * j_xx[i][0])

    for i in range(n):
        plt.plot(t_xx[i], a_xx[i])
    a_lst = [i.subs(val) for i in A]
    plt.plot(t, a_lst, 'o', color="grey")
    plt.grid()
    plt.ylabel("acceleration")
    print("acc:", ', '.join(f'{round(float(i), 5):8.5f}' for i in a_lst))

    ###  speed  ###
    plt.subplot(3, 1, 3)
    s_xx = list()
    for i in range(n):
        s_xx.append((s_xx[-1][-1] if s_xx else val['S_0']) +
                    (a_xx[i][0] * (t_xx[i] - t[i])) +
                    (j_xx[i][0] * (t_xx[i] - t[i])**2 / 2.0))

    for i in range(n):
        plt.plot(t_xx[i], s_xx[i])
    s_lst = [i.subs(val) for i in S]
    plt.plot(t, s_lst, 'o', color="grey")
    plt.grid()
    plt.ylabel("speed")
    print("spd:", ', '.join(f'{round(float(i), 5):8.5f}' for i in s_lst))

    if prefix:
        check_sg, check_ag = check_target(s_lst[-1], val['S_g']), check_target(
            a_lst[-1], 0.0)
        #if check_sg != "OK" or check_ag != "OK" :
        Path("check").make_dirs()
        plt.savefig(
            f"check/{prefix}.compute_3({title}).{check_sg}.{check_ag}.png")
    else:
        plt.show()

    return a_lst, s_lst
コード例 #21
0
ファイル: go_east.py プロジェクト: yota-code/goto.globe
#!/usr/bin/env python3

import math

from cc_pathlib import Path

import goto.globe.aircraft
import goto.globe.common

goto.globe.common.earth_radius = 1000.0 / math.pi

u = goto.globe.aircraft.Aircraft(0.0, 0.0, 0.0, math.radians(90.0), 1.0, 0.0)

for i in range(100):
    u.step()
    u.dump(Path("go_east.tsv"))
コード例 #22
0
#!/usr/bin/env python3

import random
import sys

random.seed(0)

from cc_pathlib import Path

tmp_dir = Path('./tmp')
tmp_dir.make_dirs()
tmp_dir.delete(content_only=True)

letter = 'abcdefghijklmnopqrstuvwxyz0123456789'

content_map = dict()

for i in range(256):
    l = random.randrange(8, 16)
    c = random.randrange(len(letter))
    m = letter[c] * l

    (tmp_dir / f"{i:04d}.txt").write_text(m)
    content_map[i] = m

tmp_dir.dedup('*.txt')

exit_value = 0
for i in content_map:
    m_ref = content_map[i]
    m_tst = (tmp_dir / f"{i:04d}.txt").read_text()
コード例 #23
0
ファイル: array.py プロジェクト: yota-code/structarray
        self.extract()
        stack = self.get_stack()
        header = stack[0]
        has_error = False
        print("\x1b[31mNan\x1b[0m")
        print("\x1b[32mInf\x1b[0m")
        for n, line in enumerate(stack[1:]):
            print(f"---  {n}")
            for i, item in enumerate(line):
                if math.isnan(item):
                    print(f"\x1b[31m{header[i]}\x1b[0m")
                    has_error = True
                if math.isinf(item):
                    print(f"\x1b[32m{header[i]}\x1b[0m")
                    has_error = True
            if has_error:
                break


if __name__ == '__main__':

    u = StructArray(
        Path(
            "/C/autools/source/a876969/vertex/unitest/build/EagleStateEstimator/mapping/context.tsv"
        ),
        Path(
            "/C/autools/source/a876969/vertex/unitest/build/EagleStateEstimator/replay/test01/context.reb"
        ))
    u.to_tsv(Path("debug.tsv"))
    u.debug_nan(4)
コード例 #24
0
ファイル: go_north.py プロジェクト: yota-code/goto.globe
#!/usr/bin/env python3

import math

from cc_pathlib import Path

import goto.globe.aircraft
import goto.globe.common

goto.globe.common.earth_radius = 1000.0 / math.pi

u = goto.globe.aircraft.Aircraft(0.0, 0.0, 0.0, math.radians(0.0), 1.0, 0.0)

for i in range(100):
    u.step()
    u.dump(Path("go_north.tsv"))
コード例 #25
0
ファイル: __init__.py プロジェクト: yota-code/goto.globe
    def __init__(self):
        # load

        centerline_pth = Path("1_centerline.json")
        effective_pth = Path("2_effective.json")

        if Path("0_skeleton.json").is_file():
            self.r_skeleton = Path("0_skeleton.json").load()
            self.plot_segment(self.r_skeleton, Path("0_skeleton.plot.json"))

            # apply first pass
            self.r_centerline = self.pass_1(self.r_skeleton)
            Path("1_centerline.json").save(self.r_centerline)
            self.plot_segment(self.r_centerline,
                              Path("1_centerline.plot.json"))

            self.plot_corridor(Path("3_corridor.plot.json"))

        if centerline_pth.is_file():
            self.r_effective = self.pass_2(self.r_centerline)
            Path("2_effective.json").save(self.r_centerline)
        else:
            self.r_effective = effective_pth.load()
        self.plot_segment(self.r_effective, Path("2_effective.plot.json"))

        self.to_wsk_qnd_point(self.r_effective)
コード例 #26
0
#!/usr/bin/env python3

import collections

from cc_pathlib import Path

from goto.globe.blip import Blip

WskPt = collections.namedtuple('WskPt', ['verb', 'pos', 'radius', 'alt', 'spd', 'width'])

w_lst = list()
for p in Path("source.json").load() :
	w = WskPt(("GOTO" if len(w_lst) else "START"), Blip(p['lat'], p['lon']), p['leg_radius'], p['alt'], p['speed'], p['corridor_radius'])
	w_lst.append([w.verb, w.pos.lat, w.pos.lon, -w.radius, w.alt, w.spd, w.width])

Path("2_effective.json").save(w_lst, filter_opt={'verbose':True})
コード例 #27
0
ファイル: common.py プロジェクト: yota-code/oaktree
        if self.output is None:
            self.output = self.fid.getvalue()
        elif isinstance(self.output, list):
            self.output = '\n'.join(self.output)
        else:
            self.fid.close()

    def __enter__(self):
        return self, self.open()

    def __exit__(self, exc_type, exc_value, traceback):
        self.close()


if __name__ == '__main__':

    # objet ouvert sur un handler de fichier ouvert en écriture
    fid = open("tutu_fid.txt", 'wt')
    with UniversalWriter(fid) as (u, w):
        w("toto\n")

    # objet ouvert sur un Path()
    pth = Path("tutu_Path.txt")
    with UniversalWriter(pth) as (u, w):
        w("toto\n")

    # objet ouvert sur None
    with UniversalWriter() as (u, w):
        w("toto\n")
    print(u.fid.getvalue())
コード例 #28
0
#!/usr/bin/env python3

import os
import traceback

from cc_pathlib import Path

import mako.template

unitest_dir = Path(os.environ['UNITEST_build_DIR'])

def unroll_template_file(src_dir, src_pth, dst_dir, arg_nam) :
	#print("unroll_template_file({0}, {1}, {2}, {3})".format(src_dir, src_pth, dst_dir, arg_nam))
	src_pth = (src_dir / src_pth)
	if src_pth.is_file() :
		if src_pth.suffix == ".mako" :
			m = mako.template.Template(filename=str(src_pth), module_directory=str(unitest_dir / '.mako_template'))
			dst_pth = (dst_dir / src_pth.relative_to(src_dir)).with_suffix('')
			# print("MAKO :: {0}\n     -> {1}".format(src_pth, dst_pth))
			dst_pth.parent.mkdir(parents=True, exist_ok=True)
			try :
				dst_pth.write_text(m.render(** arg_nam))
			except Exception as e :
				dst_pth.write_text(f'Failed rendering ! {e}\n------\n{traceback.format_exc()}')
		else :
			dst_pth = (dst_dir / src_pth.relative_to(src_dir))
			# print("COPY :: {0}\n     -> {1}".format(src_pth, dst_pth))
			dst_pth.parent.mkdir(parents=True, exist_ok=True)
			dst_pth.write_bytes(src_pth.read_bytes())
	else :
		raise ValueError("not a valid .mako file:{0}".format(src_dir / src_pth))
コード例 #29
0
ファイル: shelf.py プロジェクト: yota-code/spext
	def __init__(self, repo_dir, debug=True) :
		self.repo_dir = Path(repo_dir).resolve()
		self.debug = debug

		self.book_map = dict()
コード例 #30
0
ファイル: parse_section.py プロジェクト: yota-code/marccup
#!/usr/bin/env python3

import sys

from cc_pathlib import Path

import oaktree
import marccup

section_name = sys.argv[1]
section_pth = Path("document") / f"{section_name}.bkt"
section_txt = section_pth.read_text()

u = marccup.Parser(debug_dir=Path("tmp"))
p = oaktree.Leaf("section")
u.parse_section(p, section_txt)

v = marccup.Composer(p, Path("tmp/result.html"))