add vcs value for --record-pkgs to record vcs info
authorGui Chen <gui.chen@intel.com>
Mon, 21 Jan 2013 02:15:48 +0000 (10:15 +0800)
committerGui Chen <gui.chen@intel.com>
Mon, 21 Jan 2013 17:38:02 +0000 (01:38 +0800)
vcs info includes git tree and tag info

Change-Id: Ibe9263de569c888709e46767d08f919046324754
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/creator.py
mic/imager/baseimager.py
plugins/backend/zypppkgmgr.py

index 3fc3ea0..26c44a8 100644 (file)
@@ -197,9 +197,9 @@ class Creator(cmdln.Cmdln):
         if self.options.record_pkgs:
             configmgr.create['record_pkgs'] = []
             for infotype in self.options.record_pkgs.split(','):
-                if infotype not in ('name', 'content', 'license'):
+                if infotype not in ('name', 'content', 'license', 'vcs'):
                     raise errors.Usage('Invalid pkg recording: %s, valid ones:'
-                                       ' "name", "content", "license"' \
+                                       ' "name", "content", "license", "vcs"' \
                                        % infotype)
 
                 configmgr.create['record_pkgs'].append(infotype)
index 466104c..2309471 100644 (file)
@@ -318,6 +318,13 @@ class BaseImageCreator(object):
             f.close()
             self.outimage.append(licensefile)
 
+        if 'vcs' in self._recording_pkgs:
+            vcsfile = os.path.join(destdir, self.name + '.vcs')
+            f = open(vcsfile, "w")
+            f.write('\n'.join(["%s\n    %s" % (k, v)
+                               for (k, v) in self._pkgs_vcsinfo.items()]))
+            f.close()
+
     def _get_required_packages(self):
         """Return a list of required packages.
 
@@ -932,6 +939,7 @@ class BaseImageCreator(object):
         finally:
             self._pkgs_content = pkg_manager.getAllContent()
             self._pkgs_license = pkg_manager.getPkgsLicense()
+            self._pkgs_vcsinfo = pkg_manager.getVcsInfo()
             self.__attachment_packages(pkg_manager)
 
             pkg_manager.close()
index d2a8969..2aa48e1 100755 (executable)
@@ -61,6 +61,7 @@ class Zypp(BackendPlugin):
 
         self.__pkgs_license = {}
         self.__pkgs_content = {}
+        self.__pkgs_vcsinfo = {}
         self.repos = []
         self.to_deselect = []
         self.localpkgs = {}
@@ -495,6 +496,25 @@ class Zypp(BackendPlugin):
         except Exception, e:
             raise CreatorError("Package installation failed: %s" % (e,))
 
+    def getVcsInfo(self):
+        if self.__pkgs_vcsinfo:
+            return
+
+        if not self.ts:
+            self.__initialize_transaction()
+
+        mi = self.ts.dbMatch()
+        for hdr in mi:
+            lname = misc.RPM_FMT % {
+                        'name': hdr['name'],
+                        'arch': hdr['arch'],
+                        'version': hdr['version'],
+                        'release': hdr['release']
+                    }
+            self.__pkgs_vcsinfo[lname] = hdr['VCS']
+
+        return self.__pkgs_vcsinfo
+
     def getAllContent(self):
         if self.__pkgs_content:
             return self.__pkgs_content