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

Merge branch 'master' into 'production'

Release 0.5.2

* Consolidation release

See merge request !8
parents ee032cee b1d537f3
......@@ -9,7 +9,6 @@ cache/
cron/
databases
databases*/
*build*
*jsduck*
*epydoc*
*sphinx*
......@@ -20,5 +19,7 @@ private/
*plugin_extjs*
*plugin_mathjax*
sessions/
static/*-debug.js
static/*-min.js
static/docs/
uploads/
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
NAME
buildVersion -- helper script to build and tag a track_lhcbfrance version
SYNOPSIS
buildVersion [options] version
DESCRIPTION
Helper script to build a version of the track_lhcbfrance.
The version identifier should contains alphanumeric characters
including ".", "-" and "_".
Push version identifier in the javascript library.
Push version number in the CHANGELOG.
Build debug and minified version of the javascript library.
Commit the new version in git and tag it
Build the web2py plugin file
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-2014 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'
DBUIJSSRC = 'static/plugin_dbui/src'
EXTJSSRC = 'static/plugin_extjs/src'
JSDOC = 'static/docs/jsduck'
JSLIBMIN = 'static/%s-min.js' % APP
JSLIBSRC = 'static/src'
LATEXDOC = 'static/docs/latex'
PYDOC = 'static/docs/epydoc'
PDFDOC = 'static/docs/pdf'
SPHINXDOC = 'static/docs/sphinx'
SPHINXSRC = 'docs/userguide/'
NOW = datetime.datetime.now()
# basic commands
JSDUCK = os.path.expandvars("$HOME/bin/jsduck")
GIT = '/usr/bin/git'
PDFLATEX = '/usr/bin/pdflatex'
SENCHA = os.path.expandvars("$HOME/bin/sencha")
SPHINX = '/usr/bin/sphinx-build'
# message
MSG_VERSION = "Enter the new version: "
def compile():
"""compile the javascript code and generate the minified version
of the application 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 application classes and
the Ext JS ones have to be loaded separately.
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
"""
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 build
if os.path.exists(JSLIBMIN):
os.remove(JSLIBMIN)
# Minified version of the javascript library
print '\nMinified version of the javascript library', JSLIBMIN
cwd = os.getcwd()
cmd = ["sencha", "-sdk", os.path.join(cwd, EXTJSSRC),
"compile", "-classpath", os.path.join(cwd, DBUIJSSRC),
"-classpath", os.path.join(cwd, JSLIBSRC),
"exclude", "--namespace", "Ext", "--namespace", "App",
"and", "concat", "--yui", os.path.join(cwd, JSLIBMIN)]
subprocess.call(cmd)
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 and tag 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)
# Commit the new release in git an tag it
print 'git add', CHANGELOG
cmd = ["git", "add", CHANGELOG]
subprocess.call(cmd)
print 'git commit'
m = "Release version %s" % version
cmd = ["git", "commit", "-m", m]
subprocess.call(cmd)
def jsduck():
"""Generate the JavaScript documentation.
The HTML files are located in static/docs/jsduck
"""
if not os.path.exists(JSDUCK):
print '\n\tThe application jsduck is missing !'
print '\tSkip this step.\n'
return
# create the directory
if not os.path.exists(JSDOC):
os.makedirs(JSDOC)
# clean the directory
cmd = ["rm", "-rf", JSDOC]
subprocess.call(cmd)
# run JsDuck
cmd = ["jsduck", EXTJSSRC, DBUIJSSRC, JSLIBSRC, \
"--output", JSDOC, \
"--title", "%s %s" % (APP, get_version()), \
"--warnings=-all:"+EXTJSSRC]
subprocess.call(cmd)
print "JavaScript documentation in", JSDOC
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 '\n\tThe application sphinx is missing !'
print '\tSkip this step.\n'
return
if not os.path.exists(SPHINXSRC):
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.
"""
# annotated tag
print 'git tag', version
m = "Tag release %s" % 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.")
ops.add_option("-c", "--compile",
action="store_true",
dest="compile",
help="compile the javascript library using sencha command.")
ops.add_option("-e", "--epydoc",
action="store_true",
dest= "epydoc",
help= "generate the epydoc documentation.")
ops.add_option("-g", "--git",
action="store_true",
dest= "git",
help= "commit and tag the current release.")
ops.add_option("-i", "--install",
action="store_true",
dest= "install",
help= "compile javascript and generate documentations.")
ops.add_option("-j", "--jsduck",
action="store_true",
dest= "jsduck",
help= "generate the JavaScript documentation.")
ops.add_option("-r", "--release",
action="store_true",
dest= "release",
help= "set the release number.")
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 current release.")
ops.add_option("-v", "--version",
action="store_true",
dest= "version",
help= "get the tag of the current release and exit.")
ops.set_defaults(all=False,
compile=False,
epydoc=False,
get_version=False,
git=False,
install=False,
jsduck=False,
release=False,
sphinx=False,
tag=False,
version=False)
(opt, args) = ops.parse_args()
print '\nStart buildVersion'
# standalone action
if opt.compile:
compile()
if opt.epydoc:
epydoc()
if opt.git:
version = raw_input(MSG_VERSION)
git(version)
if opt.install:
epydoc()
jsduck()
sphinx(force_pdf=True)
compile()
if opt.jsduck:
jsduck()
if opt.release:
version = (args[0] if args else raw_input(MSG_VERSION))
set_version(version)
if opt.sphinx:
sphinx()
if opt.tag:
version = raw_input(MSG_VERSION)
tag(version)
if opt.version:
version = get_version()
print "\nThe version of the current release is %s\n" % version
# run all steps
if opt.all:
version = get_version()
print "\nThe version of the current release is %s\n" % version
version = (args[0] if args else raw_input(MSG_VERSION))
set_version(version)
git(version)
epydoc()
jsduck()
sphinx()
compile()
print 'Exit buidVersion\n'
sys.exit(0)
#!/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.
EXAMPLES
> build_version -h
AUTHOR
R. Le Gac, renaud.legac@cppm.in2p3.fr
Copyright (c) 2012-2015 R. Le Gac
"""
import argparse
import datetime
import os
import re
import sys
import tempfile
from os.path import join as opj
from subprocess import call
# constants
APP = os.path.basename(os.getcwd())
API = 'api'
CHANGELOG = 'static/CHANGELOG'
DBUISRC = 'static/plugin_dbui/src'
DOCS = 'static/docs'
DOCSRC = 'docs'
EXTJSSRC = 'static/plugin_extjs/src'
JSDOC = opj(DOCS, 'jsduck')
JSLIBDEBUG = 'static/%s-debug.js' % APP
JSLIBMIN = 'static/%s-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/lib/Sencha/Cmd/latest/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 (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)
filenames = [el for el in os.listdir('.') if el.endswith('.tex')]
filename = (filenames[0] if len(filenames) == 1 else None)
if not filename:
print "\n\tNo latex file !"
return
# process the latex file twice
call([PDFLATEX, filename])
call([PDFLATEX, filename])
# move the pdf file
os.chdir(cwd)
pdfdir = opj(DOCS, PDF)
if not os.path.exists(pdfdir):
os.mkdir(pdfdir)
fin = filename.replace('.tex', '.pdf')
fout = "%s_%s.pdf" % (os.path.splitext(filename)[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.
"""
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 %s" % get_version()
git("commit -m", msg)
def compile_js():
"""compile_js the javascript code and generate the debug version
as well as the minified version.