[PATCH] Add an 'epoch' property to pyrpkg.Commands

Mathieu Bridon bochecha at fedoraproject.org
Thu Feb 20 09:12:19 UTC 2014


---
I have an internal app based on pyrpkg which requires knowing the epoch
of packages, and this is a straight-forward way of having it, in the
same way we already get the version and release.

This patch only adds it as a property of the class, though, it doesn't
modify the output of "rpkg verrel". At the time I had made this patch
Jesse preferred not changing the CLI output.

Having it on the class is way enough for my needs, though, as I use it
directly.

 src/pyrpkg/__init__.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index 9086716..c5b4ae4 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -103,6 +103,8 @@ class Commands(object):
         self._distval = None
         # The distvar rpm value
         self._distvar = None
+        # The rpm epoch of the cloned module
+        self._epoch = None
         # An authenticated buildsys session
         self._kojisession = None
         # A web url of the buildsys server
@@ -305,6 +307,14 @@ class Commands(object):
         return self._distvar
 
     @property
+    def epoch(self):
+        """This property ensures the epoch attribute"""
+
+        if not self._epoch:
+            self.load_nameverrel()
+        return self._epoch
+
+    @property
     def kojisession(self):
         """This property ensures the kojisession attribute"""
 
@@ -388,7 +398,7 @@ class Commands(object):
         # We make sure there is a space at the end of our query so that
         # we can split it later.  When there are subpackages, we get a
         # listing for each subpackage.  We only care about the first.
-        cmd.extend(['-q', '--qf', '"%{NAME} %{VERSION} %{RELEASE}??"',
+        cmd.extend(['-q', '--qf', '"%{NAME} %{EPOCH} %{VERSION} %{RELEASE}??"',
                     '--specfile', os.path.join(self.path, self.spec)])
         try:
             output, err = subprocess.Popen(' '.join(cmd), shell=True,
@@ -404,9 +414,15 @@ class Commands(object):
         # Get just the output, then split it by ??, grab the first and split
         # again to get ver and rel
         (self._module_name,
+         self._epoch,
          self._ver,
          self._rel) = output.split('??')[0].split()
 
+        # Most packages don't include a "Epoch: 0" line, in which case RPM
+        # returns '(none)'
+        if self._epoch ==  "(none)":
+            self._epoch = "0"
+
     @property
     def repo(self):
         """This property ensures the repo attribute"""
-- 
1.8.5.3



More information about the rel-eng mailing list