Skip to content
Snippets Groups Projects
Commit 738ae7c0 authored by Johannes Schumann's avatar Johannes Schumann
Browse files

Add ctrl for local GiBUU installation w/o docker

parent 4bf3cd98
No related branches found
No related tags found
1 merge request!12Restructure
...@@ -13,6 +13,7 @@ __email__ = "jschumann@km3net.de" ...@@ -13,6 +13,7 @@ __email__ = "jschumann@km3net.de"
__status__ = "Development" __status__ = "Development"
from shutil import copy from shutil import copy
import subprocess
from spython.main import Client from spython.main import Client
from os.path import join, abspath, basename, isdir, isfile from os.path import join, abspath, basename, isdir, isfile
from tempfile import NamedTemporaryFile, TemporaryDirectory from tempfile import NamedTemporaryFile, TemporaryDirectory
...@@ -47,7 +48,7 @@ $CONTAINER_GIBUU_EXEC < {1}; ...@@ -47,7 +48,7 @@ $CONTAINER_GIBUU_EXEC < {1};
""" """
def run_jobcard(jobcard, outdir): def run_jobcard(jobcard, outdir, container=False):
""" """
Method for run Method for run
...@@ -58,6 +59,8 @@ def run_jobcard(jobcard, outdir): ...@@ -58,6 +59,8 @@ def run_jobcard(jobcard, outdir):
of a jobcard object or a path to a jobcard of a jobcard object or a path to a jobcard
outdir: str outdir: str
The path to the directory the output should be written to. The path to the directory the output should be written to.
container: boolean
Call GiBUU inside container environment
""" """
input_dir = TemporaryDirectory() input_dir = TemporaryDirectory()
outdir = abspath(outdir) outdir = abspath(outdir)
...@@ -80,23 +83,29 @@ def run_jobcard(jobcard, outdir): ...@@ -80,23 +83,29 @@ def run_jobcard(jobcard, outdir):
jobcard["neutrino_induced"]["FileNameflux"] = tmp_fluxfile jobcard["neutrino_induced"]["FileNameflux"] = tmp_fluxfile
with open(jobcard_fpath, "w") as f: with open(jobcard_fpath, "w") as f:
f.write(str(jobcard)) f.write(str(jobcard))
log.info("Create temporary file for associated runscript") if container:
script_fpath = join(input_dir.name, "run.sh") log.info("Create temporary file for associated runscript")
with open(script_fpath, "w") as f: script_fpath = join(input_dir.name, "run.sh")
ctnt = GIBUU_SHELL.format(outdir, jobcard_fpath) with open(script_fpath, "w") as f:
f.write(ctnt) ctnt = GIBUU_SHELL.format(outdir, jobcard_fpath)
output = Client.execute( f.write(ctnt)
Config().gibuu_image_path, output = Client.execute(
["/bin/sh", script_fpath], Config().gibuu_image_path,
bind=[outdir, input_dir.name], ["/bin/sh", script_fpath],
return_result=True, bind=[outdir, input_dir.name],
) return_result=True,
with open(join(outdir, jobcard.filename), "w") as f: )
f.write(str(jobcard)) with open(join(outdir, jobcard.filename), "w") as f:
msg = output["message"] f.write(str(jobcard))
if isinstance(msg, str): msg = output["message"]
log.info("GiBUU output:\n %s" % msg) if isinstance(msg, str):
log.info("GiBUU output:\n %s" % msg)
else:
log.info("GiBUU output:\n %s" % msg[0])
log.error("GiBUU stacktrace:\n%s" % msg[1])
return output["return_code"]
else: else:
log.info("GiBUU output:\n %s" % msg[0]) p = subprocess.Popen(
log.error("GiBUU stacktrace:\n%s" % msg[1]) [os.environ["CONTAINER_GIBUU_EXEC"], "<", jobcard_fpath],
return output["return_code"] cwd=outdir)
return p.wait()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment