Commit e3528d45 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Polish build_version.py.

parent 293fc398
......@@ -2,14 +2,17 @@
# -*- coding: utf-8 -*-
"""
NAME
build_version -- build and tag a track_publications version
build_version -- set of tool to build release
SYNOPSIS
build_version [options]
DESCRIPTION
Helper script to build a version of the track_publications.
Push version number in the CHANGELOG.
Helper script to build release and to push version number
in CHANGELOG and VERSION files.
It also performed the installation of the plugins, generated
the documentation and minificated javascript libraries.
EXAMPLES
......@@ -31,7 +34,7 @@ import tempfile
from glob import glob
from os.path import join as opj
from subprocess import call
from subprocess import call, check_output
CWD = os.getcwd()
......@@ -146,7 +149,7 @@ def build_pdf(doc):
def change_log():
"""Commit CHANGELOG.
"""Commit CHANGELOG and VERSION files
"""
print "Commit CHANGELOG..."
......@@ -156,8 +159,8 @@ def change_log():
return
# Commit modified files
print 'git add', CHANGELOG
git("add", CHANGELOG)
print 'git add', CHANGELOG, VERSION
git("add", CHANGELOG, VERSION)
print 'git commit'
msg = "Start release %s" % get_version()
......@@ -428,18 +431,15 @@ def set_version(version):
print "Update CHANGELOG with the release", version, "..."
# check tag in git
fichier = tempfile.TemporaryFile()
git("tag", stdout=fichier)
fichier.seek(0)
if version in fichier.read():
if version in check_output(["git", "tag"]):
print "\n\tRelease %s already exit in git" % version
sys.exit(1)
# look for a pattern HEAD in the CHANGELOG
# split the the string in 2 parts (pre HEAD, post HEAD)
print 'Set release', version, 'in', CHANGELOG
txt = open(CHANGELOG, 'rb').read()
with open(CHANGELOG) as fi:
txt = fi.read()
match = re.match("(.+HEAD\n)(.*)", txt, re.DOTALL)
......@@ -452,9 +452,10 @@ def set_version(version):
# update the version and edit the CHANGELOG
tpl = (match.group(1), version, NOW.strftime('%b %Y'), match.group(2))
txt = '%s\n%s (%s)\n%s' % tpl
fichier = open(CHANGELOG, 'wb')
fichier.write(txt)
fichier.close()
with open(CHANGELOG, 'w') as fi:
fi.write(txt)
call(["vim", CHANGELOG])
# cleaning
......@@ -463,8 +464,7 @@ def set_version(version):
os.remove(filename)
# update VERSION
os.remove(VERSION)
with open(VERSION, 'wb') as fichier:
with open(VERSION, 'w') as fichier:
fichier.write(version)
......@@ -526,19 +526,12 @@ def which(cmd):
bool:
"""
tfi = tempfile.TemporaryFile()
call(["which", cmd], stdout=tfi)
tfi.seek(0)
# a good answer is /usr/bin/less
# while a wrong start with /usr/bin/which:
try:
out = tfi.read()
return not out.startswith("/usr/bin/which:")
check_output(["which", cmd])
return True
finally:
tfi.close()
except CalledProcessError:
return False
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment