Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-11 08:41:04

0001 #!/usr/bin/env python
0002 # Licensed under the Apache License, Version 2.0 (the "License");
0003 # you may not use this file except in compliance with the License.
0004 # You may obtain a copy of the License at
0005 # http://www.apache.org/licenses/LICENSE-2.0
0006 #
0007 # Authors:
0008 # - Paul Nilsson, paul.nilsson@cern.ch, 2019
0009 
0010 from pilot.util.container import execute
0011 from pilot.common.errorcodes import ErrorCodes
0012 from ..setup import get_asetup, get_asetup_options
0013 
0014 import logging
0015 logger = logging.getLogger(__name__)
0016 
0017 errors = ErrorCodes()
0018 
0019 
0020 def verify_setup_command(cmd):
0021     """
0022     Verify the setup command.
0023 
0024     :param cmd: command string to be verified (string).
0025     :return: pilot error code (int), diagnostics (string).
0026     """
0027 
0028     ec = 0
0029     diagnostics = ""
0030 
0031     exit_code, stdout, stderr = execute(cmd, timeout=5 * 60)
0032     if exit_code != 0:
0033         if "No release candidates found" in stdout:
0034             logger.info('exit_code=%d' % exit_code)
0035             logger.info('stdout=%s' % stdout)
0036             logger.info('stderr=%s' % stderr)
0037             ec = errors.NORELEASEFOUND
0038             diagnostics = stdout + stderr
0039 
0040     return ec, diagnostics
0041 
0042 
0043 def get_setup_command(job, prepareasetup):
0044     """
0045     Return the path to asetup command, the asetup command itself and add the options (if desired).
0046     If prepareasetup is False, the function will only return the path to the asetup script. It is then assumed
0047     to be part of the job parameters.
0048 
0049     :param job: job object.
0050     :param prepareasetup: should the pilot prepare the asetup command itself? boolean.
0051     :return:
0052     """
0053 
0054     # if cvmfs is not available, assume that asetup is not needed
0055     # note that there is an exception for sites (BOINC, some HPCs) that have cvmfs but still
0056     # uses is_cvmfs=False.. these sites do not use containers, so check for that instead
0057     if job.infosys.queuedata.is_cvmfs or not job.infosys.queuedata.container_type:
0058         logger.debug('return asetup path as normal since: is_cvmfs=%s, job.container_type=%s' %
0059                      (job.infosys.queuedata.is_cvmfs, job.infosys.queuedata.container_type))
0060     else:
0061         # if not job.infosys.queuedata.is_cvmfs:
0062         logger.debug('will not return asetup path since: is_cvmfs=%s, job.container_type=%s' %
0063                      (job.infosys.queuedata.is_cvmfs, job.infosys.queuedata.container_type))
0064         return ""
0065 
0066     # return immediately if there is no release or if user containers are used
0067     # if job.swrelease == 'NULL' or (('--containerImage' in job.jobparams or job.imagename) and job.swrelease == 'NULL'):
0068     if job.swrelease == 'NULL' or job.swrelease == '':
0069         logger.debug('will not return asetup path since there is no swrelease set')
0070         return ""
0071 
0072     # Define the setup for asetup, i.e. including full path to asetup and setting of ATLAS_LOCAL_ROOT_BASE
0073     cmd = get_asetup(asetup=prepareasetup)
0074 
0075     if prepareasetup:
0076         options = get_asetup_options(job.swrelease, job.homepackage)
0077         asetupoptions = " " + options
0078         if job.platform:
0079             asetupoptions += " --platform " + job.platform
0080 
0081         # Always set the --makeflags option (to prevent asetup from overwriting it)
0082         asetupoptions += " --makeflags=\'$MAKEFLAGS\'"
0083 
0084         # Verify that the setup works
0085         # exitcode, output = timedCommand(cmd, timeout=5 * 60)
0086         # if exitcode != 0:
0087         #     if "No release candidates found" in output:
0088         #         pilotErrorDiag = "No release candidates found"
0089         #         logger.warning(pilotErrorDiag)
0090         #         return self.__error.ERR_NORELEASEFOUND, pilotErrorDiag, "", special_setup_cmd, JEM, cmtconfig
0091         # else:
0092         #     logger.info("verified setup command")
0093 
0094         cmd += asetupoptions
0095 
0096     return cmd