use the value of --pack-to option as filename to match all outputs
authorDohyung Kim <dohyung2.kim@samsung.com>
Thu, 20 Jul 2017 07:39:49 +0000 (16:39 +0900)
committermao xiaojuan <xiaojuan.mao@samsung.com>
Fri, 26 Jan 2018 07:59:26 +0000 (15:59 +0800)
AS-IS:
$ sudo mic cr loop PLATFORM.ks --release SNAPSHOT --pack-to IMAGENAME.tar.gz
  IMAGENAME.tar.gz
  IMAGENAME.xml
  SNAPSHOT-PLATFORM.packages
  SNAPSHOT-PLATFORM.files
  SNAPSHOT-PLATFORM.license
  SNAPSHOT-PLATFORM.ks
  ...

TO-BE:
$ sudo mic cr loop PLATFORM.ks --release SNAPSHOT --pack-to IMAGENAME.tar.gz
  IMAGENAME.tar.gz
  IMAGENAME.xml
  IMAGENAME.packages
  IMAGENAME.files
  IMAGENAME.license
  IMAGENAME.ks
  ...

Change-Id: I5cc148a09b3e4cc4ed863100f0fde4df362038cd
Signed-off-by: Dohyung Kim <dohyung2.kim@samsung.com>
mic/conf.py
mic/imager/baseimager.py
mic/utils/misc.py

index 819c8d7d319678ac3bb9fd24e02b3076621c40da..77de681743c37caf6f1efa5c72ae6310f0d9124e 100755 (executable)
@@ -226,6 +226,12 @@ class ConfigMgr(object):
                                                            self.create['release'],
                                                            self.create['name'])
             self.create['name'] = self.create['release'] + '_' + self.create['name']
+            if self.create['pack_to'] is not None:
+                if '@NAME@' in self.create['pack_to']:
+                    self.create['pack_to'] = self.create['pack_to'].replace('@NAME@', self.create['name'])
+                self.create['name'] = misc.strip_archive_suffix(self.create['pack_to'])
+                if self.create['name'] is None:
+                    raise errors.CreatorError("Not supported archive file format: %s" % self.create['pack_to'])
 
             if not self.create['logfile']:
                 self.create['logfile'] = os.path.join(self.create['destdir'],
@@ -233,6 +239,13 @@ class ConfigMgr(object):
                 self.create['releaselog'] = True
                 self.set_logfile()
 
+        elif self.create['pack_to'] is not None:
+            if '@NAME@' in self.create['pack_to']:
+                self.create['pack_to'] = self.create['pack_to'].replace('@NAME@', self.create['name'])
+            self.create['name'] = misc.strip_archive_suffix(self.create['pack_to'])
+            if self.create['name'] is None:
+                raise errors.CreatorError("Not supported archive file format: %s" % self.create['pack_to'])
+
         msger.info("Retrieving repo metadata:")
         ksrepos = kickstart.get_repos(ks,
                                       self.create['extrarepos'],
index 8f8b17df3e32a5329cc786976595bfca75ec44fe..2daeb822bd5522d8d673e2c7077ffac82339b05e 100755 (executable)
@@ -117,8 +117,6 @@ class BaseImageCreator(object):
             self.destdir = os.path.abspath(os.path.expanduser(self.destdir))
 
             if self.pack_to:
-                if '@NAME@' in self.pack_to:
-                    self.pack_to = self.pack_to.replace('@NAME@', self.name)
                 (tar, ext) = os.path.splitext(self.pack_to)
                 if ext in (".gz", ".bz2", ".lzo", ".bz") and tar.endswith(".tar"):
                     ext = ".tar" + ext
index 03c508ac48903f40629142669a0d891d536cb406..cc1a0e02392c2184130227edae8e65a6e9b1644a 100755 (executable)
@@ -41,6 +41,7 @@ except ImportError:
 xmlparse = cElementTree.parse
 
 from mic import msger
+from mic.archive import get_archive_suffixes
 from mic.utils.errors import CreatorError, SquashfsError
 from mic.utils.fs_related import find_binary_path, makedirs
 from mic.utils.grabber import myurlgrab
@@ -1043,3 +1044,11 @@ def strip_end(text, suffix):
     if not text.endswith(suffix):
         return text
     return text[:-len(suffix)]
+
+def strip_archive_suffix(filename):
+    for suffix in get_archive_suffixes():
+        if filename.endswith(suffix):
+            return filename[:-len(suffix)]
+    else:
+        msger.warning("Not supported archive file format: %s" % filename)
+    return None