From 6c0cf33cb71e40c324e83f587871b5e852abcc16 Mon Sep 17 00:00:00 2001
From: Sebastien Luttringer <sebastien.luttringer@smartjog.com>
Date: Thu, 8 Dec 2011 12:49:43 +0100
Subject: [PATCH] add option -p to build

build -p recreate payload file if already exsits
---
 bin/is                  | 6 ++++--
 completion/bash/is      | 2 +-
 installsystems/image.py | 8 ++++----
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/bin/is b/bin/is
index 0fa66c2..caaab5a 100755
--- a/bin/is
+++ b/bin/is
@@ -88,7 +88,7 @@ def c_build(parser, args):
     # load source image
     simg = SourceImage(args.path)
     # do the job
-    simg.build(force=args.force, check=not args.no_check)
+    simg.build(force=args.force, force_payload=args.payload, check=not args.no_check)
     # compute building time
     t1 = time.time()
     dt = int(t1 - t0)
@@ -370,7 +370,9 @@ p_build = subparsers.add_parser("build", help=c_build.__doc__.lower())
 p_build.add_argument("-c", "--no-check", action="store_true", default=False,
                      help="do not check compilation before adding scripts")
 p_build.add_argument("-f", "--force", action="store_true", default=False,
-                     help="overwrite existing image")
+                     help="rebuild image if already exists")
+p_build.add_argument("-p", "--payload", action="store_true", default=False,
+                     help="rebuild payloads if already exists")
 p_build.add_argument("path", nargs="?", default=".")
 p_build.set_defaults(func=c_build)
 
diff --git a/completion/bash/is b/completion/bash/is
index d38d9af..785c8c9 100644
--- a/completion/bash/is
+++ b/completion/bash/is
@@ -58,7 +58,7 @@ _is() {
             (( args > 2 )) && _filedir '?(u)isimage'
             ;;
 	build)
-            [[ "$cur" == -* ]] && _opt '-h --help -f --force -c --no-check' && return 0
+            [[ "$cur" == -* ]] && _opt '-h --help -f --force -p --payload -c --no-check' && return 0
 	    _count_args
             (( args == 2 )) && _filedir -d
             ;;
diff --git a/installsystems/image.py b/installsystems/image.py
index 57efb9b..d6fd3be 100644
--- a/installsystems/image.py
+++ b/installsystems/image.py
@@ -156,7 +156,7 @@ class SourceImage(Image):
         if not os.path.exists(os.path.join(self.base_path, "description")):
             raise Exception("No description file")
 
-    def build(self, force=False, check=True):
+    def build(self, force=False, force_payload=False, check=True):
         '''
         Create packaged image
         '''
@@ -168,7 +168,7 @@ class SourceImage(Image):
             self.check_scripts(self.parser_path)
             self.check_scripts(self.setup_path)
         # Create payload files
-        payloads = self.create_payloads()
+        payloads = self.create_payloads(force=force_payload)
         # generate a JSON description
         jdesc = self.generate_json_description(payloads)
         # creating scripts tarball
@@ -204,7 +204,7 @@ class SourceImage(Image):
         tarball.close()
         arrowlevel(-1)
 
-    def create_payloads(self):
+    def create_payloads(self, force=False):
         '''
         Create all data payloads in current directory
         Doesn't compute md5 during creation because tarball can
@@ -231,7 +231,7 @@ class SourceImage(Image):
                                         Payload.extension)
             source_stat = os.stat(source_path)
             isdir = stat.S_ISDIR(source_stat.st_mode)
-            if os.path.exists(dest_path):
+            if os.path.exists(dest_path) and not force:
                 arrow("Payload %s already exists" % dest_path)
             else:
                 arrow("Creating payload %s" % dest_path)
-- 
GitLab