#!/usr/bin/env python #-*- coding:utf-8 -*- import os, subprocess def recurse(dir): """Recurse in a directory and compile all LilyPond files""" os.chdir(dir) for item in os.listdir(dir): print "Enter directory", dir abs_item = os.path.join(dir, item) if os.path.isdir(abs_item): recurse(abs_item) else: file_name, ext = os.path.splitext(item) if ext == '.ly': print "Compile file", item pr = subprocess.Popen('lilypond ' + abs_item, cwd = dir, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE) (out, error) = pr.communicate() print out print error def main(): current_dir = os.getcwd() recurse(os.getcwd()) if __name__ == "__main__": main()