#! /usr/bin/env python import os import sys def main (): products = os.environ.get ("PRODUCTS") if not products: print "ERROR: Your PRODUCTS environment variable is not set!" print "ERROR: I have no ups databases to work with!" sys.exit (127) dist = os.environ.get ("SRT_DIST") if not dist: print "ERROR: Your SRT_DIST environment variable is not set!" print "ERROR: I do not know where the distribution root is!" sys.exit (127) pri = os.environ.get ("SRT_PRIVATE_CONTEXT") if not pri: print "ERROR: Your SRT_PRIVATE_CONTEXT environment variable is not set!" print "ERROR: I do not know where the release is!" sys.exit (127) baserelfil = os.path.join (pri, ".base_release") if not os.path.isfile (baserelfil): print "ERROR: Your .base_release file is not readable!" print "ERROR: I can't figure out what your base release is!" sys.exit (127) expfil = os.path.join (pri, ".experiment") if not os.path.isfile (expfil): print "ERROR: Your .experiment file is not readable!" print "ERROR: I can't figure out what your experiment is!" sys.exit (127) glpkgsfil = os.path.join (os.path.join (pri, "D0reldb"), "D0-glpkgs") if not os.path.isfile (glpkgsfil): print "ERROR: I cannot find %s!" % (glpkgsfil) print "ERROR: I don't know what your global packages are!" sys.exit (127) f = open (baserelfil, "r") base_release = f.read () f.close () if base_release[-1] == "\n": base_release = base_release[:-1] f = open (expfil, "r") experiment = f.read () f.close () if experiment[-1] == "\n": experiment = experiment[:-1] if experiment == "D0": prod = "D0RunII" else: print "ERROR: Experiment %s not yet supported!" (experiment,) print "ERROR: I don't know what to call your release ups product!" sys.exit (127) tblfile = os.path.join (os.path.join (pri, "ups"), prod + ".table") print "Building %s's %s" % (experiment, tblfile) if os.path.islink (tblfile) or os.path.exists (tblfile): os.unlink (tblfile) f = open (tblfile, "w") print >> f, 'File=Table' print >> f, 'Product=D0RunII' print >> f, '#*************************************************' print >> f, '# Starting Group definition, one used for "setup"' print >> f, '#*************************************************' print >> f, 'Group:' print >> f, 'Flavor=ANY' print >> f, 'Qualifiers=""' print >> f, '' print >> f, 'Flavor=ANY' print >> f, 'Qualifiers="build"' print >> f, '' print >> f, 'Common:' print >> f, ' Action=setup' print >> f, ' prodDir()' print >> f, ' setupEnv()' print >> f, ' envSet(BIN_SH,xpg4)' print >> f, '' print >> f, '#set the DEFAULT_SRT variables' print >> f, ' envSet(_SRT_INT_TMP, `dirname ${UPS_PROD_DIR}`)' print >> f, ' envSet(_SRT_INT_TMP, `dirname ${_SRT_INT_TMP}`)' print >> f, ' envSet(DEFAULT_SRT_DIST,`cd ${_SRT_INT_TMP} ; /bin/pwd`)' print >> f, ' envSet(DEFAULT_SRT_PROJECT,"D0")' print >> f, ' envSet(DEFAULT_SRT_BASE_RELEASE, `basename ${UPS_PROD_DIR}`)' print >> f, '#override this in setupII* if necessary (NT for example)' #print >> f, ' envSet(DEFAULT_SRT_CXX,"KCC_4_0")' print >> f, ' envSet(DEFAULT_SRT_CXX,"GCC_3_4")' print >> f, '# Others that might be set are ..._LOCAL and ..._QUAL' print >> f, '# We (D0) do *not* want to set DEFAULT_CVSROOT' print >> f, '' print >> f, '#need to set SRT_PUBLIC_CONTEXT to get the override features to work' print >> f, '# even though they are set again later' print >> f, ' envSet(SRT_PUBLIC_CONTEXT,`cd ${UPS_PROD_DIR}; /bin/pwd`)' print >> f, '' print >> f, ' pathPrepend(PATH, ${UPS_PROD_DIR}/SoftRelTools/scripts)' print >> f, ' pathPrepend(PATH,"${UPS_PROD_DIR}/D0reltools")' print >> f, '' print >> f, ' addAlias(srt_setup,"${UPS_SOURCE} `env SRT_PROJECT=D0 srt_environment -X --${UPS_SHELL} %s`")' print >> f, '' print >> f, ' sourceRequired(${UPS_UPS_DIR}/setupII.${UPS_SHELL},UPS_ENV)' print >> f, '' print >> f, ' envSet(SRT_TOP,${SRT_PRIVATE_CONTEXT})' print >> f, '' print >> f, ' addAlias(d0setwa,"${UPS_SOURCE} ${SRT_PUBLIC_CONTEXT}/D0reltools/d0setwa.${UPS_SHELL}")' print >> f, ' addAlias(fczar, grep %s ${SRT_PUBLIC_CONTEXT}/D0reldb/loginfo)' print >> f, '' # Now add Global packages g = open (glpkgsfil, "r") line = g.readline () while line: if line[-1] == "\n": line = line[:-1] if line: pos = line.find ("#") if pos != -1: line = line[:pos] if line: print >> f, ' setupOptional( "%s" )' % (line,) line = g.readline () g.close () # # Now add the local packages for each product, find # the version used in this release. # pkglist = os.listdir (pri) pkglist.sort () for pkg in pkglist: if (pkg != "SoftRelTools") and (pkg != "rcpdb"): pkglink = os.path.join (pri, pkg) pkgtbl = os.path.join (os.path.join (pkglink, "ups"), pkg + ".table") if os.path.islink (pkglink) and os.path.isfile (pkgtbl): vers = os.path.basename (os.readlink (pkglink)) print >> f, ' setupRequired( "%s %s -j" )' % (pkg, vers) # Now add the "trailer", the constant part. print >> f, ' Action=Configure' print >> f, '' print >> f, ' Action=Compile' print >> f, ' writeCompileScript("${UPS_UPS_DIR}/setup_comp","SETUP")' print >> f, ' writeCompileScript("${UPS_UPS_DIR}/unsetup_comp","UNSETUP")' print >> f, 'End:' print >> f, '#*************************************************' print >> f, '# End Group definition' print >> f, '#*************************************************' print >> f, '' ################################################################### # This adds the section for distribution ################################################################### print >> f, '#*************************************************' print >> f, '# Starting Group definition, one used for distribution' print >> f, '#*************************************************' print >> f, 'Group:' print >> f, 'Flavor=ANY' print >> f, 'Qualifiers="dist"' print >> f, '' print >> f, 'Common:' print >> f, ' Action=setup' print >> f, ' prodDir()' print >> f, ' setupEnv()' print >> f, ' envSet(BIN_SH,xpg4)' print >> f, ' envSet(_SRT_INT_TMP, `dirname ${UPS_PROD_DIR}`)' print >> f, ' envSet(_SRT_INT_TMP, `dirname ${_SRT_INT_TMP}`)' print >> f, ' envSet(SRT_DIST,`cd ${_SRT_INT_TMP} ; /bin/pwd`)' print >> f, ' envSet(SRT_PUBLIC_CONTEXT,`cd ${UPS_PROD_DIR}; /bin/pwd`)' print >> f, ' pathPrepend(PATH, ${UPS_PROD_DIR}/SoftRelTools/scripts)' print >> f, ' pathPrepend(PATH,"${UPS_PROD_DIR}/D0reltools")' print >> f, ' addAlias(fczar, grep %s ${SRT_PUBLIC_CONTEXT}/D0reldb/loginfo)' print >> f, ' execute(echo "**** setting up this section should ONLY done during the installation process!",NO_UPS_ENV)' print >> f, ' execute(echo "****",NO_UPS_ENV)' print >> f, '' # No real setups are done in this section. # It's only use is for distribution. # No Global packages distributed. # Now add the configurations part print >> f, ' Action=declare' print >> f, ' execute(echo " ",NO_UPS_ENV)' print >> f, ' execute(echo "****",NO_UPS_ENV)' print >> f, ' execute(echo "**** To configure ${UPS_PROD_NAME} ${UPS_PROD_VERSION} the following commands",UPS_ENV)' print >> f, ' execute(echo "ups declare ${UPS_PROD_NAME} ${UPS_PROD_VERSION} -z ${UPS_THIS_DB} -m ${UPS_PROD_NAME}.table -f ${UPS_PROD_FLAVOR} -r ${UPS_PROD_DIR}",UPS_ENV)' print >> f, ' execute(echo "**** To fetch the source code packages from www-d0.fnal.gov:",UPS_ENV)' print >> f, ' execute(echo "setup D0RunII ${UPS_PROD_VERSION} -q +dist",UPS_ENV)' print >> f, ' execute(echo "\${SRT_PUBLIC_CONTEXT}/D0reltools/fetchpkgs.sh",UPS_ENV)' print >> f, ' execute(echo "**** To fetch the external products from www-d0.fnal.gov or fnkits.fnal.gov:",UPS_ENV)' print >> f, ' execute(echo "\${SRT_PUBLIC_CONTEXT}/D0reltools/fetchprod.sh",UPS_ENV)' print >> f, ' execute(echo "**** See ${UPS_PROD_DIR}/ups/INSTALL.txt for details.",UPS_ENV)' print >> f, ' execute(echo "****",NO_UPS_ENV)' print >> f, ' execute(echo " ",NO_UPS_ENV)' # Now add the "trailer", the constant part. print >> f, '' print >> f, 'End:' print >> f, '# End Group definition' print >> f, '#*************************************************' f.close () ################################################################### # Now do the ups declare, or re-configure ################################################################### g = os.popen ("ups list -K+ D0RunII %s" % (base_release,), "r") lines = g.read () err = g.close () if err: print "ERROR: could not ups list -K+ D0RunII %s!" % (base_release,) sys.exit (127) if lines: print "Re-configuring D0RunII %s" % (base_release,) err = os.system ("ups configure D0RunII %s" % (base_release,)) if err: print "ERROR: configure failed." sys.exit (127) else: print "Declaring D0RunII %s to ups" % (base_release,) err = os.system ("ups declare D0RunII %s -z %s/upsdb:%s -r %s -m D0RunII.table -f NULL" % \ (base_release, dist, products, os.path.join ("releases", base_release),)) if err: print "ERROR: ups declare D0RunII %s failed!" % (base_release,) sys.exit (127) if __name__ == "__main__": # We are being called as a script. main () sys.exit (0) else: # We are being loaded as a module. pass