Commit 444d71f3 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Move build_version to the new git branching model + directory for documentations.

parent 3d72b5f0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
NAME
buildVersion -- helper script to build and tag a track_publications release
SYNOPSIS
buildVersion [options] release
DESCRIPTION
Helper script to build a release of the track_publications.
The release identifier should contains alphanumeric characters
including ".", "-" and "_".
Push release number in the CHANGELOG.
Commit the new version in git and tag it
Build the epydoc, sphinx documentations
EXAMPLES
> buildVersion -h
> buildVersion -g
> buildVersion -g 0.8.2
> buildVersion -a 0.8.3
AUTHOR
R. Le Gac, renaud.legac@free.fr
Copyright (c) 2012-2015 R. Le Gac
"""
import datetime
import optparse
import os
import re
import subprocess
import sys
import tempfile
import urllib
# constants
APP = os.path.basename(os.getcwd())
CHANGELOG = 'static/CHANGELOG'
LATEXDOC = 'static/docs/latex'
PYDOC = 'static/docs/epydoc'
PDFDOC = 'static/docs/pdf'
SPHINXDOC = 'static/docs/sphinx'
SPHINXSRC = 'documentations/userguide/'
NOW = datetime.datetime.now()
# basic commands
GIT = '/usr/bin/git'
PDFLATEX = '/usr/bin/pdflatex'
SPHINX = '/usr/bin/sphinx-build'
# message
MSG_VERSION = 'Enter the new release identifier: '
def epydoc():
"""Generate the epydoc documentation
The HTML files are located in static/plugin_dbui/docs/epydoc
"""
if not os.path.exists(GIT):
print '\n\tThe application epydoc is missing !'
print '\tSkip this step.\n'
return
# create the directory
if not os.path.exists(PYDOC):
os.makedirs(PYDOC)
# clean the directory
cmd = ["rm", "-rf", PYDOC]
subprocess.call(cmd)
# run epydoc
cmd = ["epydoc", "--docformat", "epytext",
"--html",
"--name", APP,
"-o", PYDOC,
"--parse-only",
"-v",
"modules/*.py"]
subprocess.call(cmd)
print "HTML documentation in", PYDOC
def get_version():
"""Return the identifier of the current version.
"""
fi = tempfile.TemporaryFile()
subprocess.call(["git", "describe", "--tags"], stdout=fi)
fi.seek(0)
return fi.read()
def git(version):
"""Commit the current release.
"""
if not os.path.exists(GIT):
print '\n\tThe application git is missing !'
print '\tSkip this step.\n'
return
# check tag in git
fi = tempfile.TemporaryFile()
subprocess.call(["git", "tag"], stdout=fi)
fi.seek(0)
if version in fi.read():
print "\n\ttag %s already exit in git" % version
sys.exit(1)
# release message
m = "Release %s" % version
# Commit the new release in git an tag it
print 'git add', CHANGELOG
cmd = ["git", "add", CHANGELOG]
subprocess.call(cmd)
print 'git commit'
cmd = ["git", "commit", "-m", m]
subprocess.call(cmd)
def set_version(version):
"""Set version identifier in CHANGELOG
"""
# look for a pattern HEAD in the CHANGELOG
# split the the string in 2 parts (pre HEAD, post HEAD)
print 'Set version in', CHANGELOG
s = open(CHANGELOG, 'rb').read()
m = re.match("(.+HEAD\n)(.*)", s, re.DOTALL)
if m == None:
print '\n\tNo HEAD tag in the CHANGELOG!\n'
rep = raw_input('\tDo you want to continue [n]?')
if rep not in ('y', 'yes'):
sys.exit(1)
# update the version and edit the CHANGELOG
s = '%s\n%s (%s)\n%s' % (m.group(1), version, NOW.strftime('%b %Y'), m.group(2))
fi = open(CHANGELOG, 'wb')
fi.write(s)
fi.close()
subprocess.call(["vim", CHANGELOG])
# cleaning
fn = "%s~" % CHANGELOG
if os.path.exists(fn):
os.remove(fn)
def sphinx(force_pdf=False):
"""Generate the Sphinx documentation.
"""
if not os.path.exists(SPHINX):
print '\nThe application sphinx is missing !'
print 'Skip this step.\n'
return
if not os.path.exists(SPHINXSRC):
print '\nNo sphinx documents.'
print 'Skip this step.\n'
return
# generate the HTML version
cmd = [SPHINX, "-b", "html", SPHINXSRC, SPHINXDOC]
subprocess.call(cmd)
print "\nSphinx HTML documentation in", SPHINXDOC,"\n"
# generate the PDF version
if not os.path.exists(PDFLATEX):
print '\n\tThe application pdflatex is missing !'
print '\tSkip this step.\n'
return
if not force_pdf:
rep = raw_input("Produce the sphinx pdf (y/N) [n]:")
if not rep.lower().startswith("y"):
return
if not os.path.exists(PDFDOC):
os.makedirs(PDFDOC)
# generate the latex
cmd = [SPHINX, "-b", "latex", SPHINXSRC, LATEXDOC]
subprocess.call(cmd)
# find the tex file
cwd = os.getcwd()
os.chdir(LATEXDOC)
li = [el for el in os.listdir('.') if el.endswith('.tex')]
fn = (li[0] if len(li) == 1 else None)
if fn:
pdf = fn.replace('.tex', '.pdf')
cmd = [PDFLATEX, "-output-directory", "../pdf", fn]
# run pdflatex twice to get reference right
subprocess.call(cmd)
subprocess.call(cmd)
# clean the pdf directory
os.chdir(cwd)
for el in os.listdir(PDFDOC):
if el.endswith('.pdf'):
continue
os.remove(os.path.join(PDFDOC, el))
cmd = ["rm", "-rf", LATEXDOC]
subprocess.call(cmd)
print "\nSphinx PDF documentation in", PDFDOC,"\n"
def tag(version):
"""tag the current release in git.
"""
# release message
m = "Release %s" % version
# annotated tag
print 'git tag', version
cmd = ["git", "tag", "-a", version, "-m", m]
subprocess.call(cmd)
if __name__ == '__main__':
ops = optparse.OptionParser()
ops.add_option("-a", "--all",
action="store_true",
dest= "all",
help= "run all steps to prepare a release")
ops.add_option("-e", "--epydoc",
action="store_true",
dest= "epydoc",
help= "generate the epydoc documentation.")
ops.add_option("-i", "--install",
action="store_true",
dest= "install",
help= "generate all documentations.")
ops.add_option("-r", "--release",
action="store_true",
dest= "release",
help= "set the release in CHANGELOG and git.")
ops.add_option("-s", "--sphinx",
action="store_true",
dest= "sphinx",
help= "generate the sphinx documentation.")
ops.add_option("-t", "--tag",
action="store_true",
dest= "tag",
help= "tag the release in git.")
ops.add_option("-v", "--version",
action="store_true",
dest= "version",
help= "get the current version.")
ops.set_defaults(all=False,
epydoc=False,
install=False,
release=False,
sphinx=False,
tag=False,
version=False)
(opt, args) = ops.parse_args()
print '\nStart buildVersion'
# standalone action
if opt.epydoc:
epydoc()
if opt.install:
epydoc()
sphinx(force_pdf=True)
if opt.release:
version = (args[0] if args else raw_input(MSG_VERSION))
set_version(version)
git(version)
if opt.sphinx:
sphinx()
if opt.tag:
version = (args[0] if args else raw_input(MSG_VERSION))
tag(version)
if opt.version:
version = get_version()
print "\nThe current release is %s\n" % version
# run all steps
if opt.all:
version = get_version()
print "\nThe current release is %s\n" % version
version = (args[0] if args else raw_input(MSG_VERSION))
set_version(version)
git(version)
epydoc()
sphinx()
print 'Exit buidVersion\n'
sys.exit(0)
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
NAME
build_version -- build and tag a track_publications version
SYNOPSIS
build_version [options]
DESCRIPTION
Helper script to build a version of the track_publications.
Push version number in the CHANGELOG.
Commit the new version in git and tag it
EXAMPLES
> build_version -h
AUTHOR
R. Le Gac, renaud.legac@free.fr
Copyright (c) 2012-2015 R. Le Gac
"""
import datetime
import optparse
import os
import re
import sys
import tempfile
import urllib
from os.path import join as opj
from subprocess import call
# constants
APP = os.path.basename(os.getcwd())
API = 'api'
CHANGELOG = 'static/CHANGELOG'
DOCS = 'static/docs'
DOCSRC = 'docs'
EXTJSSRC = 'static/plugin_extjs/src'
JSDOC = opj(DOCS, 'jsduck')
JSLIBDEBUG = 'static/%s/dbui-debug.js' % APP
JSLIBMIN = 'static/%s/dbui-min.js' % APP
JSLIBSRC = 'static/%s/src' % APP
LATEX = 'latex'
NOW = datetime.datetime.now()
PDF = "pdf"
PDFDOC = opj(DOCS, PDF)
REFERENCE = 'reference'
USER = 'user'
# basic commands
GIT = '/usr/bin/git'
JSDUCK = os.path.expandvars("$HOME/bin/jsduck")
PDFLATEX = '/usr/bin/pdflatex'
SENCHA = os.path.expandvars("$HOME/bin/sencha")
SPHINX = '/usr/bin/sphinx-build'
MSG_RELEASE = 'Enter the new release: '
def build():
"""Compile the javascript code and build documentations.
"""
compile_js()
build_html()
for doc in (API, REFERENCE, USER):
docsrc = opj(DOCSRC, doc)
if os.path.exists(docsrc):
build_pdf(doc)
def build_html():
"""Build HTML documentations.
The source files are located in the following directory::
myapp/docs
myapp/docs/api
myapp/docs/reference
myapp/docs/user
"""
print "Build the HTML documentations..."
jsduck()
for doc in (API, REFERENCE, USER):
docsrc = opj(DOCSRC, doc)
if os.path.exists(docsrc):
sphinx("-b html", docsrc, opj(DOCS, doc))
def build_pdf(doc):
""" Build PDF documentations...
Args:
doc (str): sub-directory. Possible values are api, reference, user.
"""
print "Build the PDF documentations..."
latexdoc = opj(DOCS, LATEX)
# generate the latex
sphinx("-b latex", opj(DOCSRC, doc), latexdoc)
# the current directory
cwd = os.getcwd()
# find the name of the tex file
os.chdir(latexdoc)
li = [el for el in os.listdir('.') if el.endswith('.tex')]
fn = (li[0] if len(li) == 1 else None)
if not fn:
print "\n\tNo latex file !"
return
# process the latex file twice
call([PDFLATEX, fn])
call([PDFLATEX, fn])
# move the pdf file
os.chdir(cwd)
pdfdir = opj(DOCS, PDF)
if not os.path.exists(pdfdir):
os.mkdir(pdfdir)
fin = fn.replace('.tex', '.pdf')
fout = "%s_%s.pdf" % (os.path.splitext(fn)[0], doc)
os.rename(opj(latexdoc, fin), opj(pdfdir, fout))
# remove the latex directory
call(["rm", "-rf", latexdoc])
print "PDF documentation in", PDFDOC
def change_log():
"""Commit CHANGELOG and App.js.
"""
print "Commit CHANGELOG..."
if not os.path.exists(GIT):
print '\n\tThe application git is missing !'
print '\tSkip this step.\n'
return
# Commit modified files
print 'git add', CHANGELOG
git("add", CHANGELOG)
print 'git commit'
msg = "Start release cycle %s" % get_version()
git("commit -m", msg)
def close_feature():
"""Close the feature cycle.
"""
print "Close the feature cycle..."
print "Current branches are:"
git("branch")
rep = raw_input("Select the feature identifier:")
if not rep:
sys.exit(0)
branch = "feature-%s" % rep
git("checkout develop")
git("merge --no-ff", branch)
rep = raw_input("Delete the locale branch %s [y/N]", branch)
if rep == 'y':
git("branch -d", branch)
def close_hotfix():
"""Close the hotfix cycle.
"""
print "Close the hotfix cycle..."
print "Current branches are:"
git("branch")
release = raw_input("Select the hotfix identifier:")
if not release:
sys.exit(0)
branch = "hotfix-%s" % release
git("checkout master")
git("merge --no-ff", branch)
msg = "Release %s" % release
git("tag -a", release, "-m", msg)
git("checkout develop")
git("merge --no-ff", branch)
rep = raw_input("Delete branch %s [y/N]:" % branch)
if rep == "y":
git("branch -d", branch)
git("checkout master")
build()
print "The hotfix cycle ", release, "is over"
def close_release():
"""Close the release cycle.
"""
print "Close the release cycle..."
print "Current branches are:"
git("branch")
release = raw_input("Select the release identifier:")
if not release:
sys.exit(0)
branch = "release-%s" % release
msg = "Release %s" % release
print msg
git("checkout develop")
git("merge --no-ff", branch, "-m", msg)
git("checkout master")
git("merge --no-ff", branch, "-m", msg)
git("tag -a", release, "-m", msg)
rep = raw_input("Delete branch %s [y/N]:" % branch)
if rep == "y":
git("branch -d", branch)
build()
print "The release cycle ", release, "is over"
def compile_js():
"""compile_js the javascript code and generate the debug version
as well as the minified version of the dbui library.
The compiler verify that the code complied with the class model
and order the file in the proper way.
The minified library can be build in several ways, including
the Ext JS class required by the applications. In the
current version, the library contains only the dbui classes and
the Ext JS ones have to be loaded separately. In that sense
this command is very similar to the yuicompressor one.
Several compressor can be used yui, closure compiler, ....
In the current version, the default yui compressor is used?
This operation relies on the Sencha Cmd:
http://www.sencha.com/products/sencha-cmd/download
The details documantation can be found:
http://docs.sencha.com/extjs/4.2.2/#!/guide/command
"""
print "Compile the javascript code ..."
if not os.path.exists(SENCHA):
print '\n\tThe application sencha is missing !'
print '\tSee: http://www.sencha.com/products/sencha-cmd/download'
print '\tSkip this step.\n'
return
# clean previous version
for el in (JSLIBDEBUG, JSLIBMIN):
if os.path.exists(el):
os.remove(el)
print 'Remove old javascript library', el
# debug version of the javascript library
cwd = os.getcwd()
cmd = ["sencha", "-sdk", opj(cwd, EXTJSSRC),
"compile", "-class", opj(cwd, JSLIBSRC),
"exclude", "--namespace", "Ext",
"and", "concat", opj(cwd, JSLIBDEBUG)]
call(cmd)
print 'Debug version of the javascript library', JSLIBDEBUG, 'is ready'