From 27f41ce88c1258802c694353abdea8f26cad8a0b Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Wed, 14 Apr 2021 14:56:55 +0200
Subject: [PATCH] Added --force option to overwrite image files.

---
 ogscm/app/builder.py         | 8 ++++++--
 ogscm/building_blocks/ogs.py | 1 -
 ogscm/cli.py                 | 6 ++++++
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/ogscm/app/builder.py b/ogscm/app/builder.py
index e5fba10..0bb9c65 100644
--- a/ogscm/app/builder.py
+++ b/ogscm/app/builder.py
@@ -56,7 +56,9 @@ class builder(object):
             self.image_file = f"{self.__images_out_dir}/{self.__args.sif_file}"
         else:
             self.image_file = f"{image_base_name}.sif"
-        if self.__args.convert and not os.path.exists(self.image_file):
+        if self.__args.convert and (
+            not os.path.exists(self.image_file) or self.__args.force
+        ):
             subprocess.run(
                 f"cd {self.__cwd} && singularity build --force {self.image_file} docker-daemon:{self.__tag}",
                 shell=True,
@@ -66,7 +68,9 @@ class builder(object):
             self.image_file = f"{self.__images_out_dir}/{self.__args.enroot_file}"
         else:
             self.image_file = f"{image_base_name}.sqsh"
-        if self.__args.convert_enroot and not os.path.exists(self.image_file):
+        if self.__args.convert_enroot and (
+            not os.path.exists(self.image_file) or self.__args.force
+        ):
             subprocess.run(
                 # See https://www.mankier.com/1/mksquashfs for options.
                 f"cd {self.__cwd} && rm -f {self.image_file} && ENROOT_SQUASH_OPTIONS='-comp xz -b 512K' enroot import -o {self.image_file} dockerd://{self.__tag}",
diff --git a/ogscm/building_blocks/ogs.py b/ogscm/building_blocks/ogs.py
index ffcc749..c26362b 100644
--- a/ogscm/building_blocks/ogs.py
+++ b/ogscm/building_blocks/ogs.py
@@ -78,7 +78,6 @@ class ogs(bb_base, hpccm.templates.CMakeBuild, hpccm.templates.rm):
             commands=self.__commands,
             _arguments=self.__shell_args,
         )
-        self += runscript(commands=["ogs"])
 
         if self.__environment_variables:
             self += environment(variables=self.__environment_variables)
diff --git a/ogscm/cli.py b/ogscm/cli.py
index e3dab06..c2c6c8e 100644
--- a/ogscm/cli.py
+++ b/ogscm/cli.py
@@ -116,6 +116,12 @@ def main():  # pragma: no cover
         default="",
         help="Overwrite output enroot image file name",
     )
+    build_g.add_argument(
+        "--force",
+        dest="force",
+        action="store_true",
+        help="Forces overwriting of image files!",
+    )
     build_g.add_argument(
         "--runtime-only",
         "-R",
-- 
GitLab