diff options
Diffstat (limited to 'misc/tools')
-rw-r--r-- | misc/tools/common.py | 38 | ||||
-rwxr-xr-x | misc/tools/versionize-css.py | 18 |
2 files changed, 46 insertions, 10 deletions
diff --git a/misc/tools/common.py b/misc/tools/common.py new file mode 100644 index 000000000..c38ef817b --- /dev/null +++ b/misc/tools/common.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +from __future__ import print_function +import sys, os +from os.path import dirname, abspath, join as pjoin +import subprocess + +# patch PYTHONPATH to include $BASEDIR/build/venv/python/site-packages +BASEDIR = abspath(pjoin(dirname(__file__), os.pardir, os.pardir)) +VENVDIR = pjoin(BASEDIR, 'build', 'venv') +sys.path.append(pjoin(VENVDIR, 'lib', 'python', 'site-packages')) + + +_gitHash = None +def getGitHash(): + global _gitHash + if _gitHash is None: + _gitHash = '' + try: + _gitHash = subprocess.check_output( + ['git', '-C', BASEDIR, 'rev-parse', '--short', 'HEAD'], + shell=False + ).strip() + except: + pass + return _gitHash + + +_version = None +def getVersion(): + global _version + if _version is None: + with open(pjoin(BASEDIR, 'version.txt'), 'r') as f: + _version = f.read().strip() + return _version + + +# update environment to include $VENVDIR/bin +os.environ['PATH'] = os.path.join(VENVDIR, 'bin') + ':' + os.environ['PATH'] diff --git a/misc/tools/versionize-css.py b/misc/tools/versionize-css.py index 0b317462f..5c1d9a9b8 100755 --- a/misc/tools/versionize-css.py +++ b/misc/tools/versionize-css.py @@ -4,22 +4,20 @@ # Updates the "?v=x" in docs/inter-ui.css # from __future__ import print_function -import os, sys, re -from collections import OrderedDict -from ConfigParser import RawConfigParser +import os, sys +from os.path import dirname, basename, abspath, relpath, join as pjoin +sys.path.append(abspath(pjoin(dirname(__file__), 'tools'))) +from common import BASEDIR, getVersion -def main(): - rootDir = os.path.dirname(os.path.dirname(__file__)) +import re - config = RawConfigParser(dict_type=OrderedDict) - config.read(os.path.join(rootDir, 'src', 'fontbuild.cfg')) - version = config.get('main', 'version') +def main(): + version = getVersion() regex = re.compile(r'(url\("[^"]+?v=)([^"]+)("\))') + cssFileName = pjoin(BASEDIR, 'docs', 'inter-ui.css') - cssFileName = os.path.join(rootDir, 'docs', 'inter-ui.css') - s = '' with open(cssFileName, 'r') as f: s = f.read() |