Skip to content

Instantly share code, notes, and snippets.

@keitheis
Last active August 29, 2015 14:07
Show Gist options
  • Save keitheis/903efff4b582fa6b913e to your computer and use it in GitHub Desktop.
Save keitheis/903efff4b582fa6b913e to your computer and use it in GitHub Desktop.
Bulk compile plim files to mako files
"""
Usage:
1. Enter your plim templates folder
cd app/templates
2. Run this Python script
python bulk_compile_plims.py
3. Check it out
tree __plim_output
"""
from pathlib import Path
from subprocess import Popen
def run(args):
Popen(args)
CMD = 'plimc -o {out_path} {input_file}'
def extract_plims(templates_path, out_dir='__plim_output'):
plims = Path(templates_path).glob('**/*.plim')
cwd = Path.cwd()
for p in plims:
to_dir = Path("{}/{}/{}".format(cwd, out_dir, p.parent))
if not to_dir.exists():
to_dir.mkdir(parents=True)
out_path = "{}/{}.mako".format(to_dir, p.stem)
cmd = CMD.format(out_path=out_path, input_file=p)
run(cmd.split(" "))
def main():
extract_plims(".")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment