"""AutoMoc.py by J at dynamica.org, options:
-e extension look for files with this extension
-d directory start searching in this driectory
-a filename read the arguments to moc.exe in this file
-r search subfolders
-h print this help"""
import os,sys, getopt
directory = ""
files = []
recursive = 0
extension = ".h"
arguments = ""
try:
opts, args = getopt.getopt( sys.argv[1:], "rha:e:d:" )
except getopt.GetoptError:
print __doc__
sys.exit()
for opt, arg in opts:
if opt == '-e':
extension = arg
elif opt == '-d':
directory = arg
elif opt == "-a":
fp = open( arg, 'r' )
arguments = fp.read()
fp.close()
elif opt == '-r':
recursive = 1
else :
print __doc__
sys.exit()
def walk( directory, call ):
directory = os.path.abspath( directory )
for file in [ file for file in os.listdir( directory ) if not file in [".",".."] ]:
nfile = os.path.join( directory, file )
if os.path.isdir( nfile ) and recursive:
walk( nfile, call )
elif nfile[-len(extension):] == extension:
fp = open( nfile, 'r' )
text = fp.read()
fp.close()
if text.find( "Q_OBJECT" ) != -1:
call( directory, file )
def doMoc( directory, filename ):
print "parsing " + directory + "\\" + filename
cmd = "moc.exe " + arguments + " \"" + directory + "\\" + filename + "\" -o \"" + directory + "\\moc_" + filename + "\""
# print cmd
os.system( cmd )
if __name__ == "__main__":
walk( directory, doMoc )
and here is a sample arguments file: