def copyContent (self, dar, method, baseBom = {}): """ Copies fsoList. """ if self.ignored(): warning('no contents copied for ignored variable: '+self.varName) return if not self.fsoList: warning('fsoList empty. No files to copy for variable: '+\ self.varName) return rteDirectory = dar.getRteTop()+"/"+self.varName for i in range(len(self.fsoList)): (location, locFso) = self.fsoList[i] rteDirI = "%s/path_%d" % (rteDirectory, i) # Check for relative paths to directories: in this case # no contents are distributed, and original path is preserved: if location[0] == ".": self.setups.append(location) else: self.setups.append(rteDirI) # Now copy the contents: if locFso: locFso.copyContent (dar.getSharedTop(), rteDirI, dar.getBaseTop(), baseBom, method)
def executeIgnore(self, cmd): """ Request.executeIgnore: Checks if variable is defined and calls its ignore method. """ varname = cmd.args[0] if self.rteDict.has_key(varname): self.rteDict[varname].ignore() warning ('variable: '+varname+' is ignored') else: warning ('could not ignore unknown variable: '+varname)
def getToolRteList(self, session, projectDir, toolname): """ This is a helping function to quickly get the list of runtime variables set by the tool. Since other tools may set the same variables, one should not rely on the produced list only, when specifying the list of ignored variables """ runtimeVars=[] # change to the proper directory # get tool info first: session.run('pushd '+projectDir) (toolInfoOut, stat) = session.run(self.program+' tool info '+toolname) if (stat != '0'): session.run('popd') # TODO: raise an exception, if e.g. tool does not exist... warning(string.join(toolInfoOut)) else: session.run('popd') # extract all assignment statements: allVars = [] for line in toolInfoOut: match = string.find(line, '=') if match != -1: allVars.append( line[:match]) # Get the runtime environment: session.run('pushd '+projectDir) (runtimeOut, stat) = session.run(self.program+' ru -sh') session.run('popd') # compare the list of runtime environment variables with # the tool assignments and get list of the runtime # environment variables set by the tool: runtimeVars = [] # get varname from the export statements : "export varname;" exportStatement = re.compile('export (.*);') for line in runtimeOut: res = exportStatement.match(line) if res and (res.groups()[0] in allVars): runtimeVars.append(res.groups()[0]) return runtimeVars
def getToolList(self, session, projectDir): """ Returns an array of pairs : (toolname, toolversion) for all tools in the project configuration. Works for scram V0 and V1. """ # change to the proper directory and get tool list output: session.run('pushd '+projectDir) toolsDict = {} (toolListOut, stat) = session.run(self.program+' tool list') if (stat != '0'): session.run('popd') warning(string.join(toolListOut)) else: scramHeader=1 for line in toolListOut: if line[:5] == '+++++' : # end of the scram header lines scramHeader=0 continue if not scramHeader: result=line.split() if result: toolsDict[result[0]]= result[1] return toolsDict
def executeUse(self, cmd): """ Request.executeUse Executes actions based on a user's input 'use' keyword Commands are given as: use <cmd> <argument> <input> where cmd can be: scram - get our DAR input from an existing SCRAM file - if 'rte' is the argument given, we gather the runtime environment from a given relative or absolute path - if 'arch' is given as an argument, we use the scram-defined bintype dar - set some dar information - if 'base' is the input argument, we check to see if the input is an existing darball - if 'file' is the argument given, then we use the given file to get our input - if 'tagname' is given, we set the version tag - if 'projectname' is given, we set the project name """ if cmd.args[0] == "scram": if cmd.args[1] == "rte": # Get release location, information, etc if os.path.isabs(cmd.args[2]): # One can specify top release directory with # absolute path. # Examples: # use scram rte /afs/cern.ch/cms/Releases/ORCA/ORCA_8_4_0 # use scram rte /home/user/work/ORCA_8_4_0 location = cmd.args[2] else: #Or it can be release name preceeded by a project name: # use scram rte ORCA ORCA_8_4_0 #In this case dar gets release top from the scram #database: location = getReleaseTop(cmd.args[2], cmd.args[3]) if not os.path.isdir(location): cmd.help() message = "could not find release, check command syntax!" raise InputError(cmd.line, message) # Choose scram executable name according to scram version used # in the project. majorVers = getScramVersion(location)[:-1] if majorVers[:2] == "V1": self.scram = SCRAM("scramv1") elif majorVers[:2] == "V0": self.scram = SCRAM("scram") else: sys.exit("""ERROR! do not know how to define scram executable for scram version """ + majorVers) # Set attributes and additional dar input that scram can get # from this location: relMeta = getReleaseMetadata (location) self.setProjectName (getProjectName (relMeta)) self.setVersionTag (getVersionTag (relMeta)) self.setBaseReleaseName (getBaseReleaseName(relMeta)) extraDarInput = self.scram.generateDarInput(location) # Process scram generated rte same way as variables # from darInput: for line in extraDarInput: # process environment variables: result = avariable.match(line) if result: vName, vValue = result.groups() # discard surrounding whitespaces: vName = string.strip(vName) vValue = string.strip(vValue) # Creates a variable object and puts into self.rteDict: self.addVariable(vName, vValue) continue # process commands ( variables ignored by # default in SCRAM2DAR): extraCmd = DARcommand(line) self.cmdList.append(extraCmd) if extraCmd.name == "ignore": self.executeIgnore(extraCmd) continue # Check if first command argument is existing variable name. # Commands associated with environment variable # will use corresponding variable method: if self.rteDict.has_key(extraCmd.args[0]): var = self.rteDict[extraCmd.args[0]] self.executeVarCommand(extraCmd, var) continue self.setArchitecture(self.scram.platf) # use scram-defined bintype if cmd.args[1] == "arch": # TO DO: use extra argument to set non-default architecture, # e.g. "use scram arch <some arch>". print "WARNING: Not implemented command: use scram arch" elif cmd.args[0] == "dar": if cmd.args[1] == "base": # Command syntax : use dar base <base dar ball> self.baseDar = cmd.args[2] # Do quick checks just to make sure baseDar could be a dar; # return immediately if base distribution is not found: # It can be dar installation directory or a dar # distribution file: if os.path.isdir(self.baseDar): infoOut('Use Base DAR installation from a directory:'+\ self.baseDar) elif os.path.isfile(self.baseDar): infoOut('Use Base DAR distribution from file:'+\ self.baseDar) else: # Lookup for base darball in the pool infoOut('Base DAR is not a file or a directory: '+\ self.baseDar) infoOut('Will be looked up later in the dar shared pool ') if cmd.args[1] == 'file': # Command syntax : use dar file <darball path (or LFN?)> self.setDarFile(cmd.args[2]) if cmd.args[1] == 'tagname': # Command syntax : use dar tagname <version tag> # TODO: add a check that tag contains allowed characters only self.setVersionTag (cmd.args[2]) elif cmd.args[1] == 'projectname': # Command syntax : use dar projectname <project tag> # TODO: add a check that project name contains # allowed characters only self.setProjectName (cmd.args[2]) if cmd.args[1] == "arch": # use extra argument to set non-default architecture, # e.g. "use scram arch <some arch>". infoOut('set Architecture to ' + cmd.args[2]) self.setArchitecture(cmd.args[2]) else: warning('unrecognized command syntax: ', cmd.line)