[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH v6 4/5] add option for snapshot-id suffix to __version__



1.  The added suffix is in the form YYYYMMDD and that is all.

2.  Code is added to classes my_sdist and my_rpm to check and
see is a snapshot id is requested (--snapshot) and, if
requested, to append the id to the value of cliconfig.__version__

3.  The added suffix only applies to the name of the sdist-tarball
and the rpm spec file it includes ... the "internal" version
remains unchanged.
.
Signed-off-by: Gene Czarcinski <gene czarc net>
---
 setup.py             | 33 +++++++++++++++++++++++++++++----
 virtcli/cliconfig.py |  2 ++
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/setup.py b/setup.py
index aa712c2..ace1c3e 100644
--- a/setup.py
+++ b/setup.py
@@ -5,6 +5,7 @@ import fnmatch
 import os
 import sys
 import unittest
+from datetime import date
 
 from distutils.core import Command, setup
 from distutils.command.sdist import sdist
@@ -20,6 +21,10 @@ from DistUtilsExtra.command.build_icons import build_icons
 
 from virtcli import cliconfig
 
+sdist.user_options.insert(0, ("snapshot", None,
+         "add snapshot id to version"))
+sdist.boolean_options.insert(0, "snapshot")
+
 
 def _generate_potfiles_in():
     def find(dirname, ext):
@@ -178,12 +183,29 @@ class my_install(install):
 
         install.finalize_options(self)
 
+# Note: cliconfig.__snapshot__ by default is 0, it can be set to 1 by
+#       either sdist or rpm and then means snapshot suffix is appended.
+
 class my_sdist(sdist_auto, sdist):
     user_option = []
     description = "Update virt-manager.spec; build sdist-tarball."
 
+    def initialize_options(self):
+        self.snapshot = None
+        sdist.initialize_options(self)
+
+    def finalize_options(self):
+        if self.snapshot is not None:
+            self.snapshot = 1
+            cliconfig.__snapshot__ = 1
+        sdist.finalize_options(self)
+
     def run(self):
         ver = cliconfig.__version__
+        if cliconfig.__snapshot__ == 1:
+            ver = ver + '.' +  date.today().isoformat().replace('-', '')
+        cliconfig.__version__ = ver
+        setattr(self.distribution.metadata, 'version', ver)
         f1 = open('virt-manager.spec.in', 'r')
         f2 = open('virt-manager.spec', 'w')
         for line in f1:
@@ -198,14 +220,17 @@ class my_sdist(sdist_auto, sdist):
 ###################
 
 class my_rpm(Command):
-    user_options = []
-    description = "Build a non-binary rpm."
+    user_options = [("snapshot", None,
+         "add snapshot id to version")]
+    description = "Build src and noarch rpms."
 
     def initialize_options(self):
-        pass
+        self.snapshot = None
 
     def finalize_options(self):
-        pass
+        if self.snapshot is not None:
+            self.snapshot = 1
+            cliconfig.__snapshot__ = 1
 
     def run(self):
         """
diff --git a/virtcli/cliconfig.py b/virtcli/cliconfig.py
index 06bc342..de21643 100644
--- a/virtcli/cliconfig.py
+++ b/virtcli/cliconfig.py
@@ -42,6 +42,8 @@ def _get_param(name, default):
 
 __version__ = "0.9.100"
 
+__snapshot__ = 0
+
 _usr_version = _get_param("pkgversion", "")
 if _usr_version is not None and _usr_version != "":
     __version__ = _usr_version
-- 
1.8.1.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]