File: versionize.py

package info (click to toggle)
fonts-inter 4.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,840 kB
  • sloc: python: 9,184; ansic: 3,776; javascript: 762; makefile: 637; sh: 466; xml: 22
file content (41 lines) | stat: -rwxr-xr-x 1,296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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|src)="[^"]+?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, 'misc', 'dist', 'inter.css'))
# updateHTMLFile(pjoin(BASEDIR, 'docs', '_includes', 'preload-font-files.html'))
updateHTMLFile(pjoin(BASEDIR, 'docs', 'lab', 'index.html'))

# Note: The website CSS file uses Jekyll variables to add ?v= so don't need this anymore.
# updateCSSFile(pjoin(BASEDIR, 'docs', 'inter.css'))
# updateCSSFile(pjoin(BASEDIR, 'docs', 'inter-ui.css'))