Skip to content
Snippets Groups Projects
build_docs.py 2.52 KiB
Newer Older
  • Learn to ignore specific revisions
  • tuhe's avatar
    tuhe committed
    import slider.convert
    from slider.beamer_nup import beamer_nup
    import jinja2
    from slider import convert
    import os
    
    tuhe's avatar
    tuhe committed
    import glob
    
    tuhe's avatar
    tuhe committed
    import shutil
    from slider.slider_cli import slider_cli
    
    tuhe's avatar
    tuhe committed
    import glob
    
    # def my_nup(path):
    #     dir = os.path.dirname(path)
    #     base = os.path.basename(dir)
    #
    #     out = beamer_nup(path, output="./" + base + "_nup.pdf", nup=2)
    #     out_png = convert.pdf2png(out, scale_to=600)
    #     print(out_png)
    
    
    tuhe's avatar
    tuhe committed
    # from example.load_references import reference_example
    # reference_example()
    
    def my_nup(path):
        dir = os.path.dirname(path)
        base = os.path.basename(dir)
    
    
    tuhe's avatar
    tuhe committed
        out = beamer_nup(path, output="./" + base + "_nup.pdf", nup=1)
        convert.pdfcrop(out, out)
        out_png = convert.pdf2png(out, scale_to=1600)
    
    tuhe's avatar
    tuhe committed
        print(out_png)
    
    if __name__ == "__main__":
    
    tuhe's avatar
    tuhe committed
    
        from jinjafy.bibliography_maker import make_bibliography
    
    tuhe's avatar
    tuhe committed
        bib = make_bibliography("../setup.py", "./")
    
    tuhe's avatar
    tuhe committed
    
    
    tuhe's avatar
    tuhe committed
        from snipper.fix_s import save_s
        from snipper.snipper_main import censor_file
    
    tuhe's avatar
    tuhe committed
        data = {'bitex': bib}
    
    tuhe's avatar
    tuhe committed
        EX_BASE = "../examples"
        np = EX_BASE + "/latex"
    
    tuhe's avatar
    tuhe committed
    
    
    
        dirs = ['cs101_output', 'cs101_instructor', 'cs101_students']
        def dir_import(dir):
            dat = {}
            for f in glob.glob(dir+"/*.*"):
    
                ex = f.split(".")[-1]
                if ex not in ['py', 'txt', 'shell', 'tex', 'txt']:
                    continue
    
    
                name = os.path.basename(f).replace(".", '_')
                with open(f, 'r') as f:
                    s = [s for s in f.read().rstrip().splitlines() if s.strip() != '']
                    dat[name] = '\n'.join(s)
            return dat
    
        for d in dirs:
            data[d] = dir_import("../examples/"+d)
    
    
        data = {**data, **dir_import('../examples')}
    
        data = {**data, **dir_import('../examples/latex')}
    
    
        data['resources'] = 'https://gitlab.compute.dtu.dk/tuhe/snipper/-/raw/main'
    
    tuhe's avatar
    tuhe committed
        from slider.beamer_nup import beamer_nup
    
        my_nup(np+"/index_samples.pdf")
    
        convert.pdf2png(np + "/index.pdf", "./index.png", scale_to=800)
    
    tuhe's avatar
    tuhe committed
        convert.pdf2png(np + "/index_samples.pdf", "./index_samples.png", scale_to=800)
    
    
    tuhe's avatar
    tuhe committed
    
        # Build the docs.
    
        # with open("../examples/citations.py", 'r') as f:
        #     data['citations_orig_py'] = f.read()
    
        # for file in glob.glob("../examples/output/*.*"):
        #     with open(file, 'r') as f:
        #         data[os.path.basename(file).replace(".", "_")] = f.read()
    
    tuhe's avatar
    tuhe committed
    
        with open("README.jinja.md", 'r') as f:
            s = jinja2.Environment(loader=jinja2.FileSystemLoader([".", "../example"])).from_string(f.read()).render(data)
    
        with open("../README.md", 'w') as f:
    
    tuhe's avatar
    tuhe committed
            f.write(s)