102 lines
2.8 KiB
Python
102 lines
2.8 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 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():
|
|
sp = subprocess.Popen(['git','describe'],
|
|
shell = False,
|
|
stdout = subprocess.PIPE,
|
|
stderr = subprocess.PIPE)
|
|
(stdout, stderr) = sp.communicate()
|
|
if sp.returncode != 0:
|
|
raise RuntimeError(stderr)
|
|
return stdout.strip()
|
|
|
|
if not git_is_current():
|
|
sys.stderr.write('Error: Repository is not current compared to ' +
|
|
'working environment.\nRefusing to release\n')
|
|
sys.exit(0)
|
|
|
|
git_d = git_describe()
|
|
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')
|
|
sys.exit(0)
|
|
|
|
# make backup of current setup.cfg
|
|
shutil.copy('setup.cfg','setup.cfg.bup')
|
|
|
|
# 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')
|