>From e2215d5c6def3e97285bc0028a2fbab83c25b12f Mon Sep 17 00:00:00 2001 From: James Laska Date: Mon, 3 Oct 2011 16:44:16 -0400 Subject: [PATCH oz] Include githash when building pre-release packages A pre-release is any release where %{release} starts with 0. When building RPMs of pre-releases, a datestamp and githash are included in the RPM %{release} string. This allows to easily determine when and what is included in the built packages. v2: clalance: Change some of the code to be more pythonic Signed-off-by: Chris Lalancette --- oz.spec.in | 2 +- setup.py | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/oz.spec.in b/oz.spec.in index ece60ec..ca7583e 100644 --- a/oz.spec.in +++ b/oz.spec.in @@ -1,7 +1,7 @@ Summary: Library and utilities for automated guest OS installs Name: oz Version: @VERSION@ -Release: 1%{?dist} +Release: 0%{?dist} License: LGPLv2 Group: Development/Libraries URL: http://aeolusproject.org/oz.html diff --git a/setup.py b/setup.py index ff2b318..8a4fa63 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,11 @@ from distutils.core import setup, Extension, Command from distutils.command.sdist import sdist as _sdist import os +import subprocess +import re +import time -VERSION = '0.7.0' +VERSION = '0.8.0' datafiles = [('share/man/man1', ['man/oz-install.1', 'man/oz-customize.1', 'man/oz-generate-icicle.1', @@ -13,8 +16,22 @@ class sdist(_sdist): """ custom sdist command, to prep oz.spec file for inclusion """ def run(self): - cmd = (""" sed -e "s/@VERSION@/%s/g" < oz.spec.in """ % - VERSION) + " > oz.spec" + devrelease = False + f = open('oz.spec.in', 'r') + for line in f.xreadlines(): + if re.match("^Release: *0.*", line): + devrelease = True + f.close() + + cmd = 'sed -e "s|@VERSION@|%s|g"' % VERSION + if devrelease: + git_head = subprocess.Popen("git log -1 --pretty=format:%h", + shell=True, + stdout=subprocess.PIPE).communicate()[0].strip() + date = time.strftime("%Y%m%d%H%M%S", time.gmtime()) + git_release = "%sgit%s" % (date, git_head) + cmd += ''' -e "s|^\(Release:[^%%]*\)|\\1.%s|"''' % git_release + cmd += ' < oz.spec.in > oz.spec' os.system(cmd) _sdist.run(self) -- 1.7.4.4