forked from reutenauer/polyglossia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-version.py
executable file
·140 lines (116 loc) · 4.74 KB
/
update-version.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#! /usr/bin/python3
# -*- coding: utf-8 -*-
# Importing re module
import re, os
#
# Adapt these before a new release an run the script
#
new_version = "1.62"
new_date = "2023/04/22"
# Replace version and date in all files
def replacetext():
for dname, dirs, files in os.walk("tex/"):
search_text = "\{polyglossia\}\[\d\d\d\d/\d\d/\d\d v\d\.\d+"
replace_text = "{polyglossia}[" + new_date + " v" + new_version
for fname in files:
if fname != "polyglossia.sty":
continue
fpath = os.path.join(dname, fname)
file = ""
with open(fpath) as f:
# Read file data and store it in a file variable
file = f.read()
# Replace pattern
file = re.sub(search_text, replace_text, file)
with open(fpath, "w") as f:
f.write(file)
# Report success
print("polyglossia.sty updated")
for dname, dirs, files in os.walk("tex/"):
search_text = "Language definition file \(part of polyglossia v\d\.\d+ \-\- \d\d\d\d/\d\d/\d\d"
replace_text = "Language definition file (part of polyglossia v" + new_version + " -- " + new_date
search_text_lde = "\{\d\d\d\d/\d\d/\d\d\}\{v\d\.\d+\}"
replace_text_lde = "{" + new_date + "}{v" + new_version + "}"
for fname in files:
extension = os.path.splitext(fname)[1]
if extension != ".ldf" and extension != ".lde":
continue
fpath = os.path.join(dname, fname)
file = ""
with open(fpath) as f:
# Read file data and store it in a file variable
file = f.read()
# Replace pattern
file_new = re.sub(search_text, replace_text, file)
if file == file_new:
print("No version string found, or version already updated, in " + fname + "!")
# Also consider Bastien's experimental macro
file_new = re.sub(search_text_lde, replace_text_lde, file_new)
with open(fpath, "w") as f:
f.write(file_new)
# Report success
print("ldf and lde versions updated")
for dname, dirs, files in os.walk("tex/"):
search_text = "part of polyglossia v\d\.\d+ \-\- \d\d\d\d/\d\d/\d\d"
replace_text = "part of polyglossia v" + new_version + " -- " + new_date
for fname in files:
extension = os.path.splitext(fname)[1]
if extension != ".lua":
continue
fpath = os.path.join(dname, fname)
file = ""
with open(fpath) as f:
# Read file data and store it in a file variable
file = f.read()
# Replace pattern
file_new = re.sub(search_text, replace_text, file)
if file == file_new:
# Report back if we didn't find a match
print("No version string found in " + fname + "!")
with open(fpath, "w") as f:
f.write(file_new)
# Report success
print("lua module versions updated")
for dname, dirs, files in os.walk("doc/"):
search_text = "\d\.\d+ \(forthcoming\)"
replace_text = new_version + " (" + new_date + ")"
for fname in files:
if fname != "polyglossia.tex":
continue
fpath = os.path.join(dname, fname)
file = ""
with open(fpath) as f:
# Read file data and store it in a file variable
file = f.read()
# Replace pattern
file = re.sub(search_text, replace_text, file)
with open(fpath, "w") as f:
f.write(file)
# Report success
print("Manual version updated")
# Opening the file in read and write mode
with open('README.md','r+') as f:
udate = new_date.split("/")
search_text = "THE POLYGLOSSIA PACKAGE v\d\.\d+"
replace_text = "THE POLYGLOSSIA PACKAGE v" + new_version
search_ctext = "(\-\d\d\d\d) ([Arthur|Bastien|Jürgen])"
replace_ctext = "-" + new_date[:4] + r" \2"
# Reading the file data and store
# it in a file variable
file = f.read()
# Replacing Version
file = re.sub(search_text, replace_text, file)
# Updating Copyright Year
file = re.sub(search_ctext, replace_ctext, file)
# Setting the position to the top
# of the page to insert data
f.seek(0)
# Writing replaced data in the file
f.write(file)
# Truncating the file size
f.truncate()
# Report success
print("README.md updated")
return "All replacements done!"
# Call main function
print(replacetext())