Last active
August 29, 2015 14:01
-
-
Save keitheis/c5395e048279168a7a13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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