#!/usr/bin/env python2 """Utility program to install CMT""" import os import os.path import sys import re import shutil # Figure where we are. curdir = os.getcwd() # CMT version name cmtver = "v1r20p20081118" if (len(sys.argv) > 1): if (sys.argv[1] == 'v1r20' ): print "Using CMT version v1r20p20081118" if (sys.argv[1] == 'v1r24' ): print "Using CMT version v1r24" cmtver = "v1r24" if (sys.argv[1] == 'v1r25' ): print "Using CMT version v1r25" cmtver = "v1r25" else: print "Unknown CMT version requested, using default v1r20p20081118" print "Options are v1r20 and v1r24" # Name of the CMT tarball. cmttar = "CMT"+cmtver+".tar.gz" # Figure out which make command. makecmd = "gmake" match = re.compile(r'Command not found') screen = os.popen("which "+makecmd) screenchar = screen.read() if match.match(screenchar) or len(screenchar)==0: print "Could not find gmake on this system, using make instead.\n" makecmd = "make" # Does the tar ball exist? if not os.path.exists(cmttar): print "Cannot find CMT tarball "+cmttar+".\nWas it checked out from the repository?\n" sys.exit(-1) # Has install CMT already been run on this version? if os.path.exists(cmtver): # Yes it has, remove the old version. if os.path.isdir(cmtver): # It's a directory, clean it up. shutil.rmtree(cmtver) else: # For some reason it's a file, so deal with that. os.unlink(cmtver) # Untar CMT os.system("tar -zxf "+cmttar) # Tidy up the directory structure a bit. The CMT tarball untars into a CMT # directory, but we're already in one. os.system("mv CMT/"+cmtver+" ./") os.rmdir("CMT") # CMTROOT now exists. cmtroot = curdir+"/"+cmtver # Move to the mgr directory os.chdir(cmtroot+"/mgr") # Make, this need a script for the environment unfortunately. install_script = "setup_cmt_t2k.sh" try: batchFile = open(install_script,"w") batchFile.write("#! /bin/sh\n") batchFile.write("./INSTALL\n") batchFile.write(". ./setup.sh\n") batchFile.write(makecmd+"\n") batchFile.close() except: print "Cannot write compilation batch file.\n" sys.exit(-1) os.chmod(install_script,0744) try: os.system("sh -x ./"+install_script) except: print "Failed to build cmt, please investigate....\nExiting....\n" sys.exit(-1) os.unlink(install_script) # Install try: os.system("sh -e ./INSTALL") except: print "Failed to create CMT scripts, please investigate....\nExiting....\n" sys.exit(-1) # Move back os.chdir(curdir) # Make setup scripts for bash and c shells. # Bash first try: batchFile = open("setup.sh","w") batchFile.write("#!/bin/sh\n") batchFile.write("echo Setup CMT Version "+cmtver+"\n") batchFile.write(". "+cmtroot+"/mgr/setup.sh\n") batchFile.close() except: print "Cannot write batch file setup.sh\n" sys.exit(-1) os.chmod("setup.sh",0744) # Now C Shell first try: batchFile = open("setup.csh","w") batchFile.write("#!/bin/csh\n") batchFile.write("echo Setup CMT Version "+cmtver+"\n") batchFile.write("source "+cmtroot+"/mgr/setup.csh\n") batchFile.close() except: print "Cannot write batch file setup.sh\n" sys.exit(-1) os.chmod("setup.csh",0744) # Report success print "\nCMT successfully installed on your system." print "Please add setup.(c)sh to your login script.\n"