Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:58:23

0001 #!/bin/env python
0002 
0003 import os
0004 import sys
0005 import subprocess
0006 # import base64
0007 import datetime
0008 import tarfile
0009 
0010 
0011 def download_extract_archive(filename):
0012     archive_basename = os.path.basename(filename)
0013     target_dir = os.getcwd()
0014     full_output_filename = os.path.join(target_dir, archive_basename)
0015 
0016     if filename.startswith("https:"):
0017         panda_cache_url = os.path.dirname(os.path.dirname(filename))
0018         os.environ["PANDACACHE_URL"] = panda_cache_url
0019     elif "PANDACACHE_URL" not in os.environ and "PANDA_URL_SSL" in os.environ:
0020         os.environ["PANDACACHE_URL"] = os.environ["PANDA_URL_SSL"]
0021     print("PANDACACHE_URL: %s" % os.environ.get("PANDACACHE_URL", None))
0022 
0023     from pandaclient import Client
0024     # status, output = Client.getFile(archive_basename, output_path=full_output_filename, verbose=False)
0025     status, output = Client.getFile(archive_basename, output_path=full_output_filename)
0026     print("Download archive file from pandacache status: %s, output: %s" % (status, output))
0027     if status != 0:
0028         raise RuntimeError("Failed to download archive file from pandacache")
0029     with tarfile.open(full_output_filename, 'r:gz') as f:
0030         f.extractall(target_dir)
0031     print("Extract %s to %s" % (full_output_filename, target_dir))
0032     os.remove(full_output_filename)
0033     print("Remove %s" % full_output_filename)
0034 
0035 
0036 # request_id and signature are added by iDDS for build task
0037 request_id = os.environ.get("IDDS_BUILD_REQUEST_ID", None)
0038 signature = os.environ.get("IDDS_BUIL_SIGNATURE", None)
0039 job_archive = sys.argv[1]
0040 exec_str = sys.argv[2:]
0041 exec_str = " ".join(exec_str)
0042 
0043 if request_id is None:
0044     print("IDDS_BUILD_REQUEST_ID is not defined.")
0045     sys.exit(-1)
0046 if signature is None:
0047     print("IDDS_BUIL_SIGNATURE is not defined")
0048     sys.exit(-1)
0049 
0050 print("INFO: start {}".format(datetime.datetime.utcnow()))
0051 print("INFO: job archive: {}".format(job_archive))
0052 print("INFO: exec string: {}".format(exec_str))
0053 
0054 current_dir = os.getcwd()
0055 
0056 download_extract_archive(job_archive)
0057 
0058 print("INFO: current dir: %s" % current_dir)
0059 
0060 # add current dir to PATH
0061 os.environ['PATH'] = current_dir + ":" + os.environ['PATH']
0062 
0063 p = subprocess.Popen(exec_str, stdout=sys.stdout, stderr=sys.stderr,
0064                      shell=True, universal_newlines=True)
0065 retcode = p.wait()
0066 print("INFO : end {} with retcode={}".format(datetime.datetime.utcnow(), retcode))
0067 exit(retcode)