forked from gregorio-project/gregorio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VersionUpdate.py
executable file
·77 lines (63 loc) · 2.29 KB
/
VersionUpdate.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
#! /usr/bin/env python2
#################################################################
# A script that inserts the Version into the the necessary files.
#
# GREGORIOTEX_API_VERSION is the version of gregoriotex.
# GREGORIO_VERSION is the version of gregorio.
#################################################################
import re
version_file = 'VERSION'
gregorio_files = ["configure.ac",
"windows/gregorio.iss"]
gregoriotex_api_files = ["tex/gregoriotex.lua",
"plugins/gregoriotex/gregoriotex.h"]
result = []
GREGORIOTEX_API_VERSION = ''
GREGORIO_VERSION = ''
def get_version(versionfile):
with open(versionfile, 'r') as vfile:
apiver = vfile.readline()
grever = vfile.readline()
return (apiver.split(' = ')[1].strip('\n'),
grever.split(' = ')[1].strip('\n'))
def fileinput(infile):
with open(infile, 'r') as source:
filein = source.readlines()
return filein
def replace_api_version(infile, newver):
for line in infile:
if re.search(r'internalversion =', line):
result.append(re.sub(r'[0-9.]+$', newver, line))
elif re.search(r'GREGORIOTEX_API_VERSION', line):
result.append(re.sub(r'[0-9.]+$', newver, line))
else:
result.append(line)
def replace_gregorio_version(infile, newver):
for line in infile:
if re.search(r'AC_INIT\(\[', line):
result.append(re.sub
(r'[0-9.]+-?[a-z]*(\],)', newver + r'\1', line))
elif re.search(r'AppVersion', line):
result.append(re.sub(r'[0-9.]+', newver, line))
else:
result.append(line)
def writeout(filename):
with open(filename, 'w') as out:
out.write(re.sub(r'\n ', r'\n', ' '.join(result)))
def main():
global result
global GREGORIOTEX_API_VERSION
global GREGORIO_VERSION
GREGORIOTEX_API_VERSION, GREGORIO_VERSION = get_version(version_file)
for f in gregoriotex_api_files:
src = fileinput(f)
replace_api_version(src, GREGORIOTEX_API_VERSION)
writeout(f)
result = []
for f in gregorio_files:
src = fileinput(f)
replace_gregorio_version(src, GREGORIO_VERSION)
writeout(f)
result = []
if __name__ == "__main__":
main()