summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/ctex/script/update-version.py
blob: 5353ab650f4ed91cf36c66ec0bffc7a67a308e71 (plain)
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
#!/usr/bin/env python

import sys, os, re

def update_version(file, date, version):
    f = open(file)
    update_next = False
    line_re = re.compile("^(\s*)\[(\d+/\d+/\d+) ([^\s]+) (.*)$")
    lines = ""

    for line in f:
        if update_next:
            update_next = False
            m = line_re.match(line)
            if m:
                line = "%s[%s %s %s\n" % (m.group(1), date, version, m.group(4))

        elif "ProvidesPackage" in line or "ProvidesClass" in line or "ProvidesFile" in line:
            update_next = True

        lines += line

    f.close()
    f = open(file, "w")
    f.write(lines)
    f.close()

if len(sys.argv) != 3:
    print("%s %s" % (sys.argv[0], "<date> <version>"))
    print("like: %s %s" % (sys.argv[0], "2009/05/20 v0.91"))
    sys.exit(1)

file_list = [ "../ctex.sty", "../ctexcap.sty", "../ctexart.cls", "../ctexbook.cls", "../ctexrep.cls",
    "../back/ctexutf8.sty", "../back/ctexcaputf8.sty", "../back/ctexartutf8.cls",
    "../back/ctexbookutf8.cls", "../back/ctexreputf8.cls",]

for file in file_list:
    update_version(file, sys.argv[1], sys.argv[2])