#!/usr/bin/python """Add a new module to IMP. """ import os import sys import getopt import shutil import re def fix_string(input, modname): return input.replace("example", modname)\ .replace("EXAMPLE", modname.upper()) def copy_dir(source, dest, modname): for x in os.listdir(source): if x == ".svn": continue if x.endswith(".pyc"): continue if x.endswith(".old"): continue fx= x xspath= os.path.join(source, x) xdpath= os.path.join(dest, fx) print "handling "+ xspath +"->"+xdpath if os.path.isdir(xspath): os.mkdir(xdpath) copy_dir(xspath, xdpath, modname) else: input= file(xspath, 'r').read() if xspath.endswith(".cpp") or xspath.endswith(".h") \ or xspath.endswith(".i-in") or xspath.endswith(".py"): output= fix_string(input, modname) else: output=input file(xdpath, 'w').write(output) def main(): if len(sys.argv) != 2: print("Usage: %s module_name" % sys.argv[0]) return modname= sys.argv[1] modpath=os.path.join("modules", modname) if os.path.isdir(modpath): print "Module already exists" return print "Creating a new module " + modname os.mkdir(modpath) copy_dir("modules/example", modpath, modname) if __name__ == '__main__': main()