# -*- coding: utf-8 -*- """ Configure the build process for the plugin dbui """ import datetime import os import re import tempfile from subprocess import call, check_output from IPython.utils.io import stderr NOW = datetime.datetime.now() # ............................................................................ # # JAVASCRIPT LIBRARY # JavaScript source code and compile version # paths are relative to the static directory # SENCHA_CLS = [ "plugin_extjs/packages/core/src", "plugin_extjs/classic/classic/src", "plugin_extjs/classic/classic/overrides", "plugin_dbui/src"] SENCHA_NS = "Ext" JSLIBDEBUG = "plugin_dbui/dbui-debug.js" JSLIBMIN = "plugin_dbui/dbui-min.js" # ........................................................................... # # DOCUMENTATION # output directories for documentation # paths are relative to the static directory # DOCS_DIR = "plugin_dbui/docs" JSDOC = "plugin_dbui/docs/jsduck" LATEXDOC = "plugin_dbui/docs/latex" PDFDOC = "plugin_dbui/docs/pdf" # ........................................................................... # # PLUGINS # ace, dbui, extjs and mathjax # paths are relative to the application directory # PLUGINS_FILES = {} PLUGINS_FILES["default"] = [ "controllers/plugin_%s.py", "models/plugin_%s.py", "modules/plugin_%s", "private/plugin_%s", "static/plugin_%s", "views/plugin_%s"] PLUGINS_FILES["ace"] = [ "static/plugin_ace/src-noconflict/", "static/plugin_ace/src-min-noconflict/ace.js", "static/plugin_ace/src-min-noconflict/mode-javascript.js", "static/plugin_ace/src-min-noconflict/mode-json.js", "static/plugin_ace/src-min-noconflict/mode-markdown.js", "static/plugin_ace/src-min-noconflict/mode-python.js", "static/plugin_ace/src-min-noconflict/mode-text.js", "static/plugin_ace/src-min-noconflict/theme-crimson_editor.js", "static/plugin_ace/src-min-noconflict/worker-javascript.js", "static/plugin_ace/src-min-noconflict/worker-json.js", "static/plugin_ace/src-min-noconflict/snippets/javascript.js", "static/plugin_ace/src-min-noconflict/snippets/json.js", "static/plugin_ace/src-min-noconflict/snippets/markdown.js", "static/plugin_ace/src-min-noconflict/snippets/python.js", "static/plugin_ace/src-min-noconflict/snippets/text.js"] PLUGINS_FILES["dbui"] = [ "modules/plugin_dbui", "models/plugin_dbui.py", "controllers/plugin_dbui.py", "views/plugin_dbui", "static/plugin_dbui/resources/css/kde-oxygen.css", "static/plugin_dbui/resources/css/dbui.css", "static/plugin_dbui/resources/icons", "static/plugin_dbui/src", "static/plugin_dbui/locale/dbui-lang-en.js", "static/plugin_dbui/locale/dbui-lang-fr.js", "static/plugin_dbui/dbui-min.js", "static/plugin_dbui/docs"] PLUGINS_FILES["extjs"] = [ "static/plugin_extjs/build/classic/locale", "static/plugin_extjs/build/classic/theme-classic", "static/plugin_extjs/build/ext-all.js", "static/plugin_extjs/build/ext-all-debug.js", "static/plugin_extjs/classic/classic/src", "static/plugin_extjs/classic/classic/overrides", "static/plugin_extjs/packages/core/src", "static/plugin_extjs/version.properties"] PLUGINS_FILES["mathjax"] = [ "static/plugin_mathjax/fonts/HTML-CSS/TeX/woff", "static/plugin_mathjax/jax", "static/plugin_mathjax/extensions", "static/plugin_mathjax/MathJax.js"] # ............................................................................ # # REFERENCE FILES # CHANGELOG = "static/plugin_dbui/CHANGELOG" DBUIJS = "static/plugin_dbui/src/Dbui.js" VERSION = "VERSION" def commit_release(): """Commit release CHANGELOG, VERSION and DBUIJS files """ print "\n", "."*79 print "\n\tCommit CHANGELOG, DBUIJS, VERSION, ..." # move to the master branch with tempfile.TemporaryFile() as fi: print "\tMove to the master branch" call(["git", "checkout", "master"], stdout=fi, stderr=fi) # Commit modified files print '\n\tgit add', DBUIJS, CHANGELOG, VERSION call(["git", "add", DBUIJS, CHANGELOG, VERSION]) msg = "Start release candidate %s" % get_version() print '\tgit commit:', msg call(["git", "commit", "-m", msg]) def get_plugin_version(plugin): """ Args: plugin (str): name of the plugin Return: str: the plugin version """ if plugin == "ace": cwd = os.getcwd() os.chdir("static/plugin_ace") with tempfile.TemporaryFile() as tmpfile: call(["git", "describe", "--tags"], stdout=tmpfile) tmpfile.seek(0) release = tmpfile.read() release = release.replace("v", "").replace("\n", "") os.chdir(cwd) elif plugin == "dbui": with open(VERSION, "rb") as tmpfile: release = tmpfile.read() elif plugin == "extjs": fn = os.path.join('static', 'plugin_extjs', 'version.properties') if not os.path.exists(fn): error("\n\tNo version file for the plugin extjs !") sys.exit(1) with open(fn, 'rb') as fi: s = fi.read() match = re.search(r"version.release=(\d+(\.\d+)*)", s) if not match: error("\n\tExt JS release number not defined !") sys.exit(1) release = match.group(1) # shrink the release identifier 4.2.1 or 4.2.1.883 -> 421 li = release.split('.') release = ''.join(li) if len(li) < 4 else ''.join(li[:-1]) elif plugin == "mathjax": filename = os.path.join('static', 'plugin_mathjax', 'MathJax.js') with open(filename, 'rb') as tmpfile: text = tmpfile.read() match = re.match(r'.+MathJax.version="(\d+(\.\d+)*)";', text, re.DOTALL) if not match: error("\n\tMathJax release number not defined !") sys.exit(1) release = match.group(1) else: error("\n\tUnknown plugin %" % plugin) sys.exit(1) release = release.replace(".", "") if len(release) == 2: release = "%s0" % release return release def get_version(): """Get the current release identifier in VERSION. Returns: str: the version number """ with open(VERSION, "rb") as fi: return fi.read() def set_version(version): """Set release identifier in CHANGELOG, VERSION and Dbui.js Args: version (str): release identifier """ print "\n", "."*79 print "\tUpdate CHANGELOG and Dbui.js files with release", version, "..." # check tag in git if version in check_output(["git", "tag"]).split("\n"): print "\n\tRelease %s already exit in git" % version sys.exit(1) print '\tSet release', version, 'in', DBUIJS with open(DBUIJS) as fi: txt = fi.read() # look for a pattern Dbui.version = '0.8.3'; in appbase.js # split the the string in 3 parts (pre, version, post) match = re.match(r"(.+ version: ')([\w._-]*)('.+)", txt, re.DOTALL) if match.group(2) == version: msg = '\n\tVersion "%s" already exists in the Dbui.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 txt = match.group(1) + version + match.group(3) with open(DBUIJS, 'w') as fi: fi.write(txt) # look for a pattern HEAD in the CHANGELOG # split the the string in 2 parts (pre HEAD, post HEAD) print '\tSet release', version, 'in', CHANGELOG with open(CHANGELOG) as fi: txt = fi.read() match = re.match("(.+HEAD\n)(.*)", txt, re.DOTALL) if match is 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 tpl = (match.group(1), version, NOW.strftime('%b %Y'), match.group(2)) txt = '%s\n%s (%s)\n%s' % tpl with open(CHANGELOG, 'w') as fi: fi.write(txt) call(["vim", CHANGELOG]) # update VERSION print '\tSet release', version, 'in', VERSION with open(VERSION, 'w') as fi: fi.write(version) # cleaning fn = "%s~" % CHANGELOG if os.path.exists(fn): os.remove(fn)