00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 import sys
00016 import os
00017 import fcntl
00018 import popen2
00019 import time
00020 import cfDBConnection
00021
00022 from cfDBConnection import *
00023
00024
00025 def test():
00026 cmdres= os.system("make test |tee df ")
00027 print "res",cmdres
00028
00029 r, w, e = popen2.popen3('make -p centerfocus NOOPT=YES ;echo makecenterfocusreturncode $?')
00030
00031 rlines = r.readlines()
00032
00033 outputfiledetected=False
00034 returnCode=-1
00035 for line in rlines:
00036
00037 if "makecenterfocusreturncode" in line:
00038 words=line.rsplit()
00039 returncode=int(words[1])
00040 print "rline",line
00041 if "outputfilemarker" in line:
00042 print "rline",line
00043 outputfiledetected=True
00044 words=line.rsplit()
00045
00046
00047 if words[0]=="outputfilemarker":
00048 executableFileName=words[1]
00049
00050 print "res---",cmdres
00051 print "returncode",returncode
00052 print "executableFileName",executableFileName
00053
00054
00055
00056 def getProgramId(mysqlConn_m, parameterstring):
00057 cursor = mysqlConn_m.cursor()
00058 SQL= "insert into programInfo (`compileParams`) VALUES ( %s )"
00059 cursor.execute(SQL, (parameterstring) )
00060 programId = long(mysqlConn_m.insert_id() )
00061 return programId
00062
00063
00064 def updateProgramInfo(mysqlConn_m, compileInfo, relatedEnv, programID, test):
00065 cursor = mysqlConn_m.cursor()
00066 SQL= "update programInfo set `compileInfo` = %s , `relatedEnv`= %s WHERE programID="+str(programID)
00067 print "programID =",str(programID)
00068
00069 print "relatedEnv =",relatedEnv
00070 print "updateProgramInfo Statement",SQL
00071
00072 cursor.execute(SQL,(compileInfo,relatedEnv) )
00073 if not test:
00074 mysqlConn_m.commit()
00075 else:
00076 mysqlConn_m.rollback()
00077
00078 def addEnvEntry(dict,varname):
00079 if os.getenv(varname)==None:
00080 dict[varname]=""
00081 else:
00082 dict[varname]=os.getenv(varname)
00083
00084
00085 def getRelevantEnv():
00086 dict ={}
00087
00088 addEnvEntry(dict, "EPSPRECISION")
00089 addEnvEntry(dict, "FIELDCHAR")
00090 addEnvEntry(dict, "MAXMONOMDEGREE")
00091
00092 addEnvEntry(dict, "WINLINE")
00093 addEnvEntry(dict, "32BIT")
00094 addEnvEntry(dict, "64BIT")
00095 addEnvEntry(dict, "NOOPT")
00096 addEnvEntry(dict, "OPENMP")
00097
00098
00099 addEnvEntry(dict, "ICC")
00100 addEnvEntry(dict, "PGPROF")
00101 addEnvEntry(dict, "OPTERON")
00102 addEnvEntry(dict, "CORE2")
00103
00104
00105 addEnvEntry(dict, "DEBUG")
00106 addEnvEntry(dict, "TEST")
00107 addEnvEntry(dict, "VALGRIND")
00108 addEnvEntry(dict, "SAFE")
00109
00110 addEnvEntry(dict, "SVN")
00111 addEnvEntry(dict, "HOSTNAME")
00112
00113 addEnvEntry(dict, "POPT_LIB")
00114
00115 addEnvEntry(dict, "COUNT")
00116 addEnvEntry(dict, "TIMER")
00117 addEnvEntry(dict, "PROFILE")
00118 addEnvEntry(dict, "PROFILING")
00119
00120
00121 addEnvEntry(dict, "NXNXN_DIR")
00122 addEnvEntry(dict, "CENTERFOCUS_BASE_DIR")
00123 addEnvEntry(dict, "EXPALIB_BASE_DIR")
00124
00125 return dict
00126
00127
00128
00129
00130 def printDict(dict):
00131
00132 for key, value in dict.items():
00133 print key, "=", value
00134
00135 def dictToText(dict):
00136 text=""
00137 for key, value in dict.items():
00138
00139 text=text+ str(key)+"="+str(value)+"\n"
00140 return text
00141
00142 def make():
00143
00144 test=False
00145
00146 envDict=getRelevantEnv()
00147 printDict(envDict)
00148 relatedEnv=dictToText(envDict)
00149
00150
00151 parameterstring =""
00152 makelogfilename=""
00153 for i in range(1,len(sys.argv)):
00154 parameterstring= parameterstring+" "+sys.argv[i]
00155
00156
00157
00158 if not test:
00159 dbconn = getCenterfocusExperimentDatabaseConnection()
00160 programid=getProgramId(dbconn, parameterstring)
00161 parameterstring=parameterstring+" SVN=YES PRODUCTION=YES PROGRAMID="+str(programid)
00162
00163 print "program id "+ str(programid)+" received"
00164 cmd = "make -p "+parameterstring
00165 print "compiling..."
00166 print "parameterstring = "+ parameterstring
00167
00168
00169
00170
00171 os.system("echo ""> makecflog;"+ cmd+" 2>&1 |tee makecflog; echo makereturncode $? >>makecflog")
00172 rlines = []
00173 cfLogfile = open("makecflog", 'r')
00174 for row in cfLogfile.readlines():
00175 rlines.append(row)
00176
00177 print "readlines..."
00178 executableFileName=None
00179 compileInfo=""
00180 outputfiledetected=False
00181 for line in rlines:
00182 compileInfo=compileInfo+line
00183
00184 if "makereturncode" in line:
00185 words=line.rsplit()
00186 returncode=int(words[1])
00187 print "rline",line
00188 if "outputfilemarker" in line:
00189 print "rline",line
00190 outputfiledetected=True
00191 words=line.rsplit()
00192
00193
00194 if words[0]=="outputfilemarker":
00195 executableFileName=words[1]
00196
00197 print "returncode (compiling)",returncode
00198
00199
00200 if test:
00201 exit(0)
00202
00203 if (returncode==0 and outputfiledetected==True ):
00204
00205 print "updating program info ",returncode
00206 updateProgramInfo(dbconn, compileInfo,relatedEnv,programid,test)
00207
00208 print "your program was successfully registered"
00209 else:
00210 print "your program was NOT registered "
00211 print "try a regular compile with parameters 'PRODUCTION=YES SVN=YES' first!"
00212
00213 if __name__ == "__main__":
00214 make()
00215
00216
00217
00218