Commit 916453e7 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Modify build_version to run jsduck via a docker container.

parent 36510812
......@@ -34,31 +34,40 @@ import tempfile
from glob import glob
from os.path import join as opj
from subprocess import call, check_output
from subprocess import call, CalledProcessError, check_output
CWD = os.getcwd()
# constants
API = "api"
APP = os.path.basename(os.getcwd())
API = 'api'
CHANGELOG = os.path.join(CWD, 'static/CHANGELOG')
DBUISRC = os.path.join(CWD, 'static/plugin_dbui/src')
DOCS = os.path.join(CWD, 'static/docs')
DOCSRC = 'docs'
EXTJSSRC = os.path.join(CWD, 'static/plugin_extjs/src')
JSDOC = opj(DOCS, 'jsduck')
JSLIBDEBUG = os.path.join(CWD, 'static/%s-debug.js' % APP)
JSLIBMIN = os.path.join(CWD, 'static/%s-min.js' % APP)
JSLIBSRC = os.path.join(CWD, 'static/%s/src' % APP)
LATEX = 'latex'
DOCSRC = "docs"
LATEX = "latex"
MSG_RELEASE = "Enter the new release: "
NOW = datetime.datetime.now()
PDF = "pdf"
PDFDOC = opj(DOCS, PDF)
REFERENCE = 'reference'
USER = 'user'
VERSION = 'VERSION'
MSG_RELEASE = 'Enter the new release: '
REFERENCE = "reference"
USER = "user"
VERSION = "VERSION"
# path running on the localhost
APP_DIR = os.getcwd()
APP_STATIC = opj(APP_DIR, "static")
CHANGELOG = opj(APP_STATIC, "CHANGELOG")
DBUISRC = opj(APP_STATIC, "plugin_dbui", "src")
EXTJSSRC = opj(APP_STATIC, "plugin_extjs", "src")
JSDOC = opj(APP_STATIC, "docs", "jsduck")
JSLIBDEBUG = opj(APP_STATIC, "%s-debug.js" % APP)
JSLIBMIN = opj(APP_STATIC, "%s-min.js" % APP)
JSLIBSRC = opj(APP_STATIC, APP, "src")
PDFDOC = opj(APP_STATIC, "docs", PDF)
# path running behind a docker container
W2P_DIR_CNT = "/opt/web2py"
APP_DIR_CNT = opj(W2P_DIR_CNT, "applications", APP)
APP_STATIC_CNT = opj(APP_DIR_CNT, "static")
EXTJSSRC_CNT = opj(APP_STATIC_CNT, "plugin_extjs", "src")
JSDOC_CNT = opj(APP_STATIC_CNT, "docs", "jsduck")
JSLIBSRC_CNT = opj(APP_STATIC_CNT, APP, "src")
def build():
......@@ -393,32 +402,55 @@ def jsduck():
"""
print "Build the javascript documentation..."
if not which("jsduck"):
cmd = which("jsduck")
if len(cmd) == 0:
print '\n\tThe application jsduck is missing !'
print '\tSkip this step.\n'
return
if not os.path.exists(JSLIBSRC):
print 'No javascript library. Exit.'
print '\n\tNo javascript library. Exit.'
return
# create the directory
if not os.path.exists(JSDOC):
os.makedirs(JSDOC)
# clean
call(["rm", "-rf", JSDOC])
# clean the directory
cmd = ["rm", "-rf", JSDOC]
call(cmd)
# NOTE
# the processing depend on the localisation of jsduck
# either on the localhost or behind a dcoker container
# the length of the cmd list allows to separate the two cases
# run JsDuck
cmd = ["jsduck", EXTJSSRC, JSLIBSRC,
"--output", JSDOC,
"--title", "plugin_dbui %s" % get_version(),
"--warnings=-all:" + EXTJSSRC]
# localhost
if len(cmd) == 1:
call(cmd)
cmd.extend([EXTJSSRC, JSLIBSRC,
"--output", JSDOC,
"--title", "plugin_dbui %s" % get_version(),
"--warnings=-all:" + EXTJSSRC])
call(cmd)
# docker container
else:
cmd.extend([EXTJSSRC_CNT, JSLIBSRC_CNT,
"--output", JSDOC_CNT,
"--title", "plugin_dbui %s" % get_version(),
"--warnings=-all:" + EXTJSSRC_CNT])
call(cmd)
print "JavaScript documentation in", JSDOC
# container is running as root
# change permission for the current user
uid = check_output(["id", "-u"]).strip("\n")
gid = check_output(["id", "-g"]).strip("\n")
perm = "%s:%s" % (uid, gid)
cnt = ARGS.docker_container
call(["docker", "exec", cnt, "chown", "-R", perm, JSDOC_CNT])
print "\n\tJavaScript documentation in", JSDOC
def set_version(version):
......@@ -517,21 +549,48 @@ def start_release():
def which(cmd):
"""Test if the command exists on the system.
"""Test if the command exists on the localhost or on a docker container.
Return the sequence to execute it. Priority is given to the localhost.
Args:
name (str): name of the command
cmd (str): name of the command
Returns:
bool:
list: command to be executed. The list is empty when the command is
not found.
"""
# local host
try:
out = check_output(["which", cmd])
return [out.strip("\n")]
except CalledProcessError:
print "\n\tCommand", cmd, "not found on the localhost"
# docker container is running ?
container = ARGS.docker_container
is_running = False
for line in check_output(["docker", "ps"]).split("\n"):
li = line.split()
if li[-1] == container:
is_running = True
break
if not is_running:
print "\n\tDocker container", container, "is not running !"
return []
# docker container
try:
check_output(["which", cmd])
return True
out = check_output(["docker", "exec", container, "which", cmd])
path = out.strip("\n")
return ["docker", "exec", container, path]
except CalledProcessError:
return False
print "\n\tCommand", cmd, "not found on the %s container" % container
return []
if __name__ == '__main__':
......@@ -561,6 +620,12 @@ if __name__ == '__main__':
"To be used with --write-release. "
"Recommend to use --start-release.")
APS.add_argument("-d", "--docker-container",
default="dev",
help="docker container housing jsduck, sencha and sphinx "
"commands [%(default)s]. The container has to ran.",
metavar = "<name>")
APS.add_argument("-j", "--jsduck",
action="store_true",
help="build the JavaScript documentation.")
......
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