File: fix-cheetah-build-str.py

package info (click to toggle)
xmds2 3.1.0%2Bdfsg2-10
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 42,580 kB
  • sloc: python: 64,048; cpp: 4,868; ansic: 1,463; makefile: 144; sh: 54; javascript: 8
file content (34 lines) | stat: -rw-r--r-- 1,224 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
# This script walks through all *.py that are included in the binary
# package and replaces the build-specify timestamp and build path
# generated by Cheetah.  This makes the building of the package
# reproducible.  This script is intended to be called in the
# override_dh_auto_install rule.

import fileinput
import fnmatch
import os
import re
import sys
import time

from dateutil import parser

import debian.changelog as dch

with open("debian/changelog", "r", encoding="utf-8") as fid:
    ch = dch.Changelog(fid)
    dt = ch[0].date
    ts = time.mktime(parser.parse(dt).timetuple())

for dName, sdName, fList in os.walk("debian/xmds2"):
    for fileName in fList:
        if fnmatch.fnmatch(fileName, "*.py"):
            fname = os.path.join(dName, fileName)
            for line in fileinput.input(fname, inplace=True, encoding="utf-8"):
                outline = line
                if re.match("^__CHEETAH_srcLastModified__ = .*$", line):
                    outline = f"__CHEETAH_srcLastModified__ = '{dt}'\n"
                m = re.match("^__CHEETAH_src__ = '.*/(.*)'$", line)
                if m:
                    outline = f"__CHEETAH_src__ = '{m.group(1)}'\n"
                sys.stdout.write(outline)