Files
ldapuserdir/do_release.py

126 lines
3.4 KiB
Python

#/usr/bin/python
#
# A first simplistic try at a release helper script
# Derek Feichtinger <derek.feichtinger@psi.ch>
import subprocess
import sys
import os
import shutil
from optparse import OptionParser
#from distutils.version import StrictVersion
# StrictVersion('10.4.10') > StrictVersion('10.4.9')
# or use distribute package:
#from pkg_resources import parse_version
#parse_version('1.4') > parse_version('1.4-rc2')
import ldapuserdir
def git_is_current():
sp = subprocess.Popen(['git', 'status', '--porcelain',
'--untracked-files=no'],
shell = False,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
(stdout, stderr) = sp.communicate()
if sp.returncode != 0:
raise RuntimeError(stderr)
if stdout.strip() == '':
return True
return False
def git_describe(*args):
cmd = ['git','describe']
if args:
cmd.extend(args)
sp = subprocess.Popen(cmd,
shell = False,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
(stdout, stderr) = sp.communicate()
if sp.returncode != 0:
raise RuntimeError(stderr)
return stdout.strip()
################################################
# OPTION PARSING
usage = """%prog [options] groupname [usernames]
"""
parser = OptionParser(usage = usage)
parser.add_option('-t', '--test',
action = 'store_true',
dest = 'flag_test',
help = 'do a test release (do not stop at errors)',
default = False
)
(options, args) = parser.parse_args()
flag_test = options.flag_test
if not git_is_current():
sys.stderr.write('Error: Repository is not current compared to ' +
'working environment.\nRefusing to release\n')
if not flag_test:
sys.exit(0)
git_d = git_describe('--tags')
if git_d != 'v' + ldapuserdir.__version__:
sys.stderr.write('Git-describe (%s) differs from internal package' % git_d
+ 'version (%s)\n' % ldapuserdir.__version__)
sys.stderr.write('You need to tag the distribution\n')
if not flag_test:
sys.exit(0)
# make backup of current setup.cfg
shutil.copy('setup.cfg','setup.cfg.bup')
# TODO: this should be done through a template
# add options needed for the distribution
fd = open('setup.cfg','a')
fd.write("""
[build]
executable=/usr/bin/python
[install]
prefix=/usr
[bdist_rpm]
Release=1.el6
Group=Applications/Internet
Vendor=PSI
Packager=Derek Feichtinger
#Provides
Requires=python-ldap
#Conflicts
#Obsoletes
#Distribution
#BuildRequires
#Icon
""")
fd.close()
# clean the build dir first
sp = subprocess.Popen(['python','setup.py','clean','--all'],
shell = False,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
(stdout, stderr) = sp.communicate()
if sp.returncode != 0:
raise RuntimeError(stderr)
sys.stdout.write(stdout)
# Run the RPM build
sp = subprocess.Popen(['python','setup.py','bdist_rpm'],
shell = False,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
(stdout, stderr) = sp.communicate()
if sp.returncode != 0:
raise RuntimeError(stderr)
sys.stdout.write(stdout)
shutil.copy('setup.cfg','setup.cfg.rpm')
shutil.copy('setup.cfg.bup','setup.cfg')