Skip to content
Snippets Groups Projects
Commit 1474d621 authored by legac's avatar legac
Browse files

Redesign build_version in order to generate all documentations and to be compliant with pylint.

parent 1863cd14
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
"""
NAME
buildVersion -- helper script to build and tag a plugin_dbui version
build_version -- helper script to build and tag a plugin_dbui version
SYNOPSIS
buildVersion [options] version
build_version [options] version
DESCRIPTION
Helper script to build a version of the plugin_dbui.
......@@ -21,12 +21,12 @@
EXAMPLES
> buildVersion -h
> build_version -h
AUTHOR
R. Le Gac, renaud.legac@free.fr
Copyright (c) 2012 R. Le Gac
Copyright (c) 2012-2015 R. Le Gac
"""
......@@ -43,32 +43,157 @@ from subprocess import call
# constants
APP = os.path.basename(os.getcwd())
API = 'api'
BUILDDIR = '../plugin_dbui_build'
CHANGELOG = 'static/plugin_dbui/CHANGELOG'
DBUI_W2P = 'web2py.plugin.dbui.%s.w2p'
DOCS = 'static/plugin_dbui/docs'
DOCSRC = 'docs'
EXTJSSRC = 'static/plugin_extjs/src'
JSBASE = 'static/plugin_dbui/src/App.js'
JSDOC = 'static/plugin_dbui/docs/jsduck'
JSDOC = os.path.join(DOCS, 'jsduck')
JSLIBDEBUG = 'static/plugin_dbui/dbui-debug.js'
JSLIBMIN = 'static/plugin_dbui/dbui-min.js'
JSLIBSRC = 'static/plugin_dbui/src'
SPHINXDOC = 'static/plugin_dbui/docs/sphinx'
SPHINXSRC = 'docs/api'
LATEX = 'latex'
NOW = datetime.datetime.now()
PACK_PLUGIN_URL = 'http://localhost:8000/%s/default/pack_plugin' % APP
PDF = "pdf"
PDFDOC = os.path.join(DOCS, PDF)
REFERENCE = 'reference'
# 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 compile():
"""compile the javascript code and generate the debug version
def build():
"""Compile the javascript code and build documentations.
"""
compile_js()
build_html()
build_pdf()
def build_html():
"""Build HTML documentations
"""
print "Build the HTML documentations..."
jsduck()
sphinx("-b html",
os.path.join(DOCSRC, API),
os.path.join(DOCS, API))
sphinx("-b html",
os.path.join(DOCSRC, REFERENCE),
os.path.join(DOCS, REFERENCE))
def build_pdf():
""" Build PDF documentations...
"""
print "Build the PDF documentations..."
latexdoc = os.path.join(DOCS, LATEX)
# generate the latex for the reference manual
sphinx("-b latex", os.path.join(DOCSRC, REFERENCE), 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
cmd = [PDFLATEX, "-output-directory", os.path.join("..", PDF), fn]
call(cmd)
call(cmd)
# clean the pdf directory
os.chdir(cwd)
if os.path.exists(PDFDOC):
for el in os.listdir(PDFDOC):
if el.endswith('.pdf'):
continue
os.remove(os.path.join(PDFDOC, el))
# remove the latex directory
call(["rm", "-rf", latexdoc])
print "PDF documentation in", PDFDOC
def change_log():
"""Commit CHANGELOG and App.js.
"""
print "Commit CHANGELOG and App.js..."
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', JSBASE, CHANGELOG
git("add", JSBASE, CHANGELOG)
print 'git commit'
msg = "Start release cycle %s" % get_version()
git("commit -m", msg)
def close_release():
"""Close the release cycle.
"""
print "Close the release cycle..."
release = raw_input("Select the release:")
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("Destroy branch %s [y/N]:" % branch)
if rep == "y":
git("branch -d", branch)
build()
web2py()
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
......@@ -90,6 +215,7 @@ def compile():
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'
......@@ -100,7 +226,7 @@ def compile():
for el in (JSLIBDEBUG, JSLIBMIN):
if os.path.exists(el):
os.remove(el)
print ' remove old javascript library', el
print 'Remove old javascript library', el
# debug version of the javascript library
cwd = os.getcwd()
......@@ -112,7 +238,7 @@ def compile():
call(cmd)
print 'Debug version of the javascript library', JSLIBDEBUG
print 'Debug version of the javascript library', JSLIBDEBUG, 'is ready'
# Minified version of the javascript library
cmd = ["sencha", "-sdk", os.path.join(cwd, EXTJSSRC),
......@@ -122,21 +248,24 @@ def compile():
call(cmd)
print 'Minified version of the javascript library', JSLIBMIN
print 'Minified version of the javascript library', JSLIBMIN, 'is ready'
def get_version():
"""Get the current version identifier.
"""
s = open(JSBASE, 'rb').read()
m = re.match("(.+ version: ')([\w._-]*)('.+)", s, re.DOTALL)
return m.group(2)
txt = open(JSBASE, 'rb').read()
match = re.match(r"(.+ version: ')([\w._-]*)('.+)", txt, re.DOTALL)
return match.group(2)
def git():
"""Commit CHANGELOG and App.js.
def git(*args, **kwargs):
"""run any git instruction:
git("add CHANGELOG")
git("add", CHAGELOG, "foo.txt")
git("commit", stdout=fi)
"""
if not os.path.exists(GIT):
......@@ -144,25 +273,13 @@ def git():
print '\tSkip this step.\n'
return
version = get_version()
# check tag in git
fi = tempfile.TemporaryFile()
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)
cmd = [GIT]
cmd.extend(args[0].split())
# Commit modified files
print 'git add', JSBASE, CHANGELOG
cmd = ["git", "add", JSBASE, CHANGELOG]
call(cmd)
if len(args) > 1:
cmd.extend(args[1:])
print 'git commit'
m = "Start release cycle %s" % version
cmd = ["git", "commit", "-m", m]
call(cmd)
call(cmd, **kwargs)
def jsduck():
......@@ -170,6 +287,7 @@ def jsduck():
The HTML files are located in static/plugin_dbui/docs/jsduck
"""
print "Build the javascript documentation..."
if not os.path.exists(JSDUCK):
print '\n\tThe application jsduck is missing !'
print '\tSkip this step.\n'
......@@ -195,45 +313,58 @@ def jsduck():
def set_version(version):
"""Set release identifier in CHANGELOG and appbase.js
"""Set release identifier in CHANGELOG and App.js
"""
print "Update CHANGELOG and App.js files with the release", version, "..."
# check tag in git
fi = tempfile.TemporaryFile()
git("tag", stdout=fi)
fi.seek(0)
if version in fi.read():
print "\n\tRelease %s already exit in git" % version
sys.exit(1)
print 'Set release', version, 'in', JSBASE
s = open(JSBASE, 'rb').read()
txt = open(JSBASE, 'rb').read()
# look for a pattern App.version = '0.8.3'; in appbase.js
# split the the string in 3 parts (pre, version, post)
m = re.match("(.+ version: ')([\w._-]*)('.+)", s, re.DOTALL)
match = re.match(r"(.+ version: ')([\w._-]*)('.+)", txt, re.DOTALL)
if m.group(2) == version:
print '\n\tVersion "%s" already exists in the appbase.js file !' % version
if match.group(2) == version:
msg = '\n\tVersion "%s" already exists in the appbase.js file !'
print msg % version
rep = raw_input('\tDo you want to continue [n]?')
if rep not in ('y', 'yes'):
sys.exit(1)
# update the version and write a new file
s = m.group(1) + version + m.group(3)
txt = match.group(1) + version + match.group(3)
fi = open(JSBASE, 'wb')
fi.write(s)
fi.write(txt)
fi.close()
# 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
s = open(CHANGELOG, 'rb').read()
txt = open(CHANGELOG, 'rb').read()
m = re.match("(.+HEAD\n)(.*)", s, re.DOTALL)
match = re.match("(.+HEAD\n)(.*)", txt, re.DOTALL)
if m == None:
if match == 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))
tpl = (match.group(1), version, NOW.strftime('%b %Y'), match.group(2))
txt = '%s\n%s (%s)\n%s' % tpl
fi = open(CHANGELOG, 'wb')
fi.write(s)
fi.write(txt)
fi.close()
call(["vim", CHANGELOG])
......@@ -243,8 +374,12 @@ def set_version(version):
os.remove(fn)
def sphinx():
"""Generate the Sphinx documentation.
def sphinx(*args, **kwargs):
"""run the sphinx-build:
git("add CHANGELOG")
git("add", CHAGELOG, "foo.txt")
git("commit", stdout=fi)
"""
if not os.path.exists(SPHINX):
......@@ -252,50 +387,68 @@ def sphinx():
print '\tSkip this step.\n'
return
if not os.path.exists(SPHINXSRC):
print '\nNo sphinx source file !'
return
cmd = [SPHINX]
cmd.extend(args[0].split())
# clean the directory
cmd = ["rm", "-rf", SPHINXDOC]
call(cmd)
if len(args) > 1:
cmd.extend(args[1:])
# generate the HTML version
cmd = [SPHINX, "-b", "html", SPHINXSRC, SPHINXDOC]
call(cmd)
call(cmd, **kwargs)
def start_release():
"""Start the release cycle.
"""
print "Start the release cycle..."
old_release = get_version()
print "Current release is", old_release
new_release = raw_input(MSG_RELEASE)
if not new_release:
sys.exit(0)
print "\nSphinx HTML documentation in", SPHINXDOC, "\n"
branch = "release-%s" % new_release
git("checkout", "-b", branch, "develop")
set_version(new_release)
change_log()
build()
def tag():
"""Tag the current release.
"""
print "Tag the release...",
version = get_version()
msg = "Tag %s" % version
# annotated tag
print 'git tag', version
cmd = ["git", "tag", "-a", version, "-m", msg]
call(cmd)
git("tag", "-a", version, "-m", msg)
def web2py():
"""Produce the binary file for the web2py plugin.
"""
print '\nBuild the web2py plugin binary file'
rep = raw_input('Check that the web2py service is running ? Type CR to continue.')
print 'Build the web2py plugin binary file...'
msg = 'Check that the web2py service is running [y/N]'
rep = raw_input(msg)
if rep:
print '\n\tSkip this step.\n'
return
f = urllib.urlopen(PACK_PLUGIN_URL)
s = f.read()
connection = urllib.urlopen(PACK_PLUGIN_URL)
txt = connection.read()
fn = DBUI_W2P % get_version().replace('.', '')
fi = open(fn, 'wb')
fi.write(s)
fi.write(txt)
fi.close()
# move the file to the build directory
......@@ -311,152 +464,121 @@ def web2py():
if __name__ == '__main__':
# define script options
ops = optparse.OptionParser()
OPS = optparse.OptionParser()
ops.add_option("--start-release-cycle",
OPS.add_option("-a", "--api-doc",
action="store_true",
dest="start_release_cycle",
dest="api_doc",
help="build the API documentation.")
OPS.add_option("--start-release",
action="store_true",
dest="start_release",
help="start the new release branch cycle.")
ops.add_option("--close-release-cycle",
OPS.add_option("--close-release",
action="store_true",
dest="close_release_cycle",
dest="close_release",
help="close the release branch cycle.")
ops.add_option("-c", "--compile",
OPS.add_option("-c", "--compile",
action="store_true",
dest="compile",
help="compile the javascript library using sencha command.")
help="compile the javascript library.")
ops.add_option("-g", "--git",
OPS.add_option("--commit-changelog",
action="store_true",
dest="git",
help="commit CHANGELOG, App.js, ..")
dest="changelog",
help="commit CHANGELOG and App.js.")
ops.add_option("-j", "--jsduck",
OPS.add_option("-j", "--jsduck",
action="store_true",
dest="jsduck",
help="generate the JavaScript documentation.")
help="build the JavaScript documentation.")
ops.add_option("-r", "--set-release",
OPS.add_option("-r", "--reference-doc",
action="store_true",
dest="release",
help="set the release in CHANGELOG and App.js.")
dest="reference_doc",
help="build the reference manual in HTML.")
ops.add_option("-s", "--sphinx",
OPS.add_option("--reference-pdf",
action="store_true",
dest="sphinx",
help="generate sphinx documentation.")
dest="reference_pdf",
help="build the reference manual in PDF.")
ops.add_option("-t", "--tag",
OPS.add_option("--write-release",
action="store_true",
dest="release",
help="write the release number in CHANGELOG and App.js.")
OPS.add_option("-t", "--tag",
action="store_true",
dest="tag",
help="tag the release.")
help="tag the release in git.")
ops.add_option("-v", "--get_release",
OPS.add_option("-v", "--version",
action="store_true",
dest="version",
help="get the current release.")
help="get the current release identifier.")
ops.add_option("-w", "--web2py",
OPS.add_option("-w", "--web2py",
action="store_true",
dest="web2py",
help="pack the web2py plugin.")
ops.set_defaults(close_release_cycle=False,
OPS.set_defaults(api_doc=False,
close_release_cycle=False,
changelog=False,
compile=False,
git=False,
jsduck=False,
reference_doc=False,
reference_pdf=False,
release=False,
sphinx=False,
tag=False,
start_release_cycle=False,
tag=False,
version=False)
(opt, args) = ops.parse_args()
(OPT, ARGS) = OPS.parse_args()
print '\nStart buildVersion'
# individual action
if opt.compile:
compile()
if opt.git:
git()
if opt.jsduck:
jsduck()
if opt.release:
version = (args[0] if args else raw_input(MSG_RELEASE))
set_version(version)
if opt.sphinx:
sphinx()
if opt.version:
version = get_version()
print "\nThe current release is %s\n" % version
# start the release cycle
if opt.start_release_cycle:
if OPT.api_doc:
sphinx("-b html",
os.path.join(DOCSRC, API),
os.path.join(DOCS, API))
print "Start the release cycle"
if OPT.close_release_cycle:
close_release()
old_release = get_version()
print "Current release is", old_release
if OPT.compile:
compile_js()
new_release = raw_input(MSG_RELEASE)
if not new_release:
sys.exit(0)
if OPT.changelog:
change_log()
branch = "release-%s" % new_release
call(["git", "checkout", "-b", branch, "develop"])
set_version(new_release)
git()
compile()
if OPT.jsduck:
jsduck()
sphinx()
# close the release cycle
if opt.close_release_cycle:
release = raw_input("Select the release:")
if not release:
sys.exit(0)
branch = "release-%s" % release
if OPT.release:
set_version(raw_input(MSG_RELEASE))
msg = "Release %s" % release
print msg
if OPT.reference_doc:
sphinx("-b html",
os.path.join(DOCSRC, REFERENCE),
os.path.join(DOCS, REFERENCE))
call(["git", "checkout", "develop"])
call(["git", "merge", "--no-ff", branch, "-m", msg])
if OPT.reference_pdf:
build_pdf()
call(["git", "checkout", "master"])
call(["git", "merge", "--no-ff", branch, "-m", msg])
if OPT.version:
print "\nThe current release is %s\n" % get_version()
call(["git", "tag", "-a", release, "-m", msg])
if OPT.start_release_cycle:
start_release()
rep = raw_input("Destroy branch %s [y/N]:" % branch)
if rep == "y":
call(["git", "branch", "-d", branch])
compile()
jsduck()
sphinx()
if OPT.web2py:
build()
web2py()
print "The release cycle ", release, "is over"
if opt.web2py:
compile()
jsduck()
sphinx()
web2py()
print 'Exit buidVersion\n'
sys.exit(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment