import os from cElementTree import ElementTree as ET jsb = ET(file="ext.jsb") root = jsb.getroot() output_dir = '..' for package in root.findall("target"): output = package.attrib['file'].replace('$output', output_dir).replace('\\', '/') print "Creating", output dirname = os.path.dirname(output) if not os.path.exists(dirname): os.makedirs(dirname) files = [file.attrib['name'] for file in package.findall("include")] filecontents = [open(file.replace('\\', '/')).read() for file in files] all = '\n'.join(filecontents) open(output, 'w').write(all)