1
1
mirror of https://github.com/rsms/inter.git synced 2024-12-02 15:54:46 +03:00
inter/misc/tools/versionize.py
2019-02-02 14:29:56 -08:00

38 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python
# encoding: utf8
#
# Updates the "?v=x" in files:
# - docs/inter.css
# - docs/inter-ui.css
# - docs/_includes/preload-font-files.html
#
import os, sys, re
from os.path import dirname, basename, abspath, relpath, join as pjoin
sys.path.append(abspath(pjoin(dirname(__file__), 'tools')))
from common import BASEDIR, getVersion
version = getVersion()
def updateCSSFile(filename):
regex = re.compile(r'(url\("[^"]+?v=)([^"]+)("\))')
with open(filename, 'r') as f:
s = f.read()
s = regex.sub(lambda m: '%s%s%s' % (m.group(1), version, m.group(3)), s)
with open(filename, 'w') as f:
f.write(s)
def updateHTMLFile(filename):
regex = re.compile(r'(href="[^"]+?v=)([^"]+)(")')
with open(filename, 'r') as f:
s = f.read()
s = regex.sub(lambda m: '%s%s%s' % (m.group(1), version, m.group(3)), s)
with open(filename, 'w') as f:
f.write(s)
updateCSSFile(pjoin(BASEDIR, 'docs', 'inter.css'))
updateCSSFile(pjoin(BASEDIR, 'docs', 'inter-ui.css'))
updateHTMLFile(pjoin(BASEDIR, 'docs', '_includes', 'preload-font-files.html'))