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 import os
0011 
0012 # from pilot.util.container import execute
0013 from pilot.common.errorcodes import ErrorCodes
0014 
0015 import logging
0016 logger = logging.getLogger(__name__)
0017 
0018 errors = ErrorCodes()
0019 
0020 
0021 def verify_setup_command(cmd):
0022     """
0023     Verify the setup command.
0024 
0025     :param cmd: command string to be verified (string).
0026     :return: pilot error code (int), diagnostics (string).
0027     """
0028 
0029     ec = 0
0030     diagnostics = ""
0031 
0032     return ec, diagnostics
0033 
0034 
0035 def get_setup_command(job, prepareasetup):
0036     """
0037     Return the path to asetup command, the asetup command itself and add the options (if desired).
0038     If prepareasetup is False, the function will only return the path to the asetup script. It is then assumed
0039     to be part of the job parameters.
0040 
0041     Handle the case where environmental variables are set -
0042     HARVESTER_CONTAINER_RELEASE_SETUP_FILE, HARVESTER_LD_LIBRARY_PATH, HARVESTER_PYTHONPATH
0043     This will create the string need for the pilot to execute to setup the environment.
0044 
0045     :param job: job object.
0046     :param prepareasetup: not used.
0047     :return: setup command (string).
0048     """
0049 
0050     cmd = ""
0051 
0052     # return immediately if there is no release or if user containers are used
0053     if job.swrelease == 'NULL' or '--containerImage' in job.jobparams:
0054         logger.debug('get_setup_command return value: {}'.format(str(cmd)))
0055         return cmd
0056 
0057     # test if environmental variable HARVESTER_CONTAINER_RELEASE_SETUP_FILE is defined
0058     setupfile = os.environ.get('HARVESTER_CONTAINER_RELEASE_SETUP_FILE', '')
0059     if setupfile != "":
0060         cmd = "source {};".format(setupfile)
0061         # test if HARVESTER_LD_LIBRARY_PATH is defined
0062         if os.environ.get('HARVESTER_LD_LIBRARY_PATH', '') != "":
0063             cmd += "export LD_LIBRARY_PATH=$HARVESTER_LD_LIBRARY_PATH:$LD_LIBRARY_PATH;"
0064         # test if HARVESTER_PYTHONPATH is defined
0065         if os.environ.get('HARVESTER_PYTHONPATH', '') != "":
0066             cmd += "export PYTHONPATH=$HARVESTER_PYTHONPATH:$PYTHONPATH;"
0067         #unset FRONTIER_SERVER variable
0068         cmd += "unset FRONTIER_SERVER"
0069 
0070         logger.debug('get_setup_command return value: {}'.format(str(cmd)))
0071 
0072     return cmd