27 def write(self, useSingularity=True, useApptainer=False, extraDirs=[]):
28 executable = "#!/bin/sh -\n"
29
30
31 if useSingularity:
32 platform = str(os.environ[
'COMPILER_PATH']).
split(
'/')[-1].
replace(
'el9',
'almalinux9')
33 executable += 'if [ "$1" != "--really" ]; then \n'
34 executable += ' exec singularity exec -e --no-home'
35 for dir in ["/cvmfs", "/var", self.basedir, "$(pwd | cut -d '/' -f 1-2)"] + extraDirs:
36 executable += ' -B '+dir
37 executable += ' /cvmfs/atlas.cern.ch/repo/containers/fs/singularity/'
38 executable += platform + ' /bin/bash -- "$0" --really "$@";\n'
39 executable += 'fi\n'
40 executable += "shift;\n\n"
41 executable += "export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase\n"
42 executable += "source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh\n\n"
43 executable += "ulimit -f 1000000;\n"
44 executable += "cd "+self.basedir+"\n\n"
45 executable += "echo 'ncores="+str(self.nCores)+" nhours="+str(self.hours)+" "+self.basedir+"/"+self.name+".sh';\n"
46 for cmd in self.cmds:
47 executable += cmd+"\n"
48 executable += "exit 0\n"
49
50 elif useApptainer:
51 wrapper = ''
52 wrapperfilename = self.basedir+"/"+self.name+"_wrapper.sh"
53 platform = str(os.environ[
'COMPILER_PATH']).
split(
'/')[-1].
replace(
'el9',
'almalinux9')
54 executable += 'export ALRB_CONT_SWTYPE="apptainer"\n'
55 executable += 'export ALRB_CONT_PRESETUP="hostname -f; date; id -a"\n'
56 executable += 'export ALRB_testPath=",,,,,,,,,,,,,,,,,,,,,,,,"\n'
57 executable += 'export ALRB_CONT_RUNPAYLOAD="'+wrapperfilename+'"\n'
58 wrapper += "ulimit -f 1000000;\n"
59 wrapper += "cd "+self.basedir+";\n\n"
60 wrapper += "echo 'ncores="+str(self.nCores)+" nhours="+str(self.hours)+" "+self.basedir+"/"+self.name+".sh';\n"
61 for cmd in self.cmds:
62 wrapper += cmd+'\n'
63 with open(wrapperfilename, 'w') as f:
64 f.write(wrapper)
65 st = os.stat(wrapperfilename)
66 os.chmod(wrapperfilename, st.st_mode | stat.S_IEXEC)
67 executable += "export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase\n"
68 executable += "source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh -c "+platform+" -b -q"
69 if self.mounts != []:
70 executable += "-m"+" ".join(self.mounts)
71 else:
72 executable += "\n"
73 executable += "exit $?\n"
74
75 else:
76 executable += "export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase\n"
77 executable += "source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh\n"
78 executable += "ulimit -f 1000000;\n"
79 executable += "cd "+self.basedir+"\n\n"
80 executable += "echo 'ncores="+str(self.nCores)+" nhours="+str(self.hours)+" "+self.basedir+"/"+self.name+".sh';\n"
81 for cmd in self.cmds:
82 executable += cmd+"\n"
83 executable += "exit 0\n"
84
85 filename = self.basedir+"/"+self.name+".sh"
86 with open(filename, 'w') as f:
87 f.write(executable)
88
89
90 st = os.stat(filename)
91 os.chmod(filename, st.st_mode | stat.S_IEXEC)
92
93
std::string replace(std::string s, const std::string &s2, const std::string &s3)
std::vector< std::string > split(const std::string &s, const std::string &t=":")