Skip to content

Instantly share code, notes, and snippets.

@keitheis
Last active August 29, 2015 14:01
Show Gist options
  • Save keitheis/c5395e048279168a7a13 to your computer and use it in GitHub Desktop.
Save keitheis/c5395e048279168a7a13 to your computer and use it in GitHub Desktop.
"""
Output all plim to the folder
e.g.
python plimcd.py ./templates ../mako
"""
import sys
import os.path
import subprocess
class Chdir:
def __init__(self, newPath):
self.newPath = newPath
self.savedPath = os.getcwd()
def __enter__(self):
os.chdir(self.newPath)
def __exit__(self, *args):
os.chdir(self.savedPath)
current = {'no': 0}
def plimcit(output, dirpath, filenames):
output = os.path.abspath(output)
if not os.path.exists(output):
os.mkdir(output)
with Chdir(dirpath):
for filename in filenames:
basename = os.path.basename(filename)
if not filename.endswith('.plim'):
continue
current['no'] += 1
print(dirpath, filename)
cmd = 'plimc {filename} -o {output}/{fileno}{basename}.mako' \
.format(
fileno=current['no'], filename=filename,
output=output, basename=basename,
)
subprocess.call(cmd, shell=True)
def main(source, output):
os.path.walk(source, plimcit, output)
if __name__ == '__main__':
main(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment