forked from ebsco/edsapi-koha-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·126 lines (90 loc) · 3.39 KB
/
build.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
#!/usr/bin/env python3
## USAGE:
# Update parameter within version.json
# Run build.py
# Commit code
import json
import datetime
import os
now = datetime.datetime.now()
##### Get json settings #####
with open('version.json') as f:
data = json.load(f)
majorVersion = data["MajorVersion"]
minorVersion = data["MinorVersion"]
releaseNotes = data["ReleaseNotes"]
shaAdd = data["ShaAdd"]
##############################
##### Update EDS.pm #####
with open('Koha/Plugin/EDS.pm', 'r') as file :
filedata = file.readlines()
# find and repalce version
for line in range(len(filedata)):
templine = filedata[line].rstrip()
# Set major version
if ("our $MAJOR_VERSION" in templine):
filedata[line] = 'our $MAJOR_VERSION = "' + majorVersion + '";\n'
# Set sub version
if ("our $SUB_VERSION" in templine):
filedata[line] = 'our $SUB_VERSION = "' + minorVersion + '";\n'
# Set sha address
if ("our $SHA_ADD" in templine):
filedata[line] = 'our $SHA_ADD = "' + shaAdd + '";\n'
# Set date
if ("our $DATE_UPDATE" in templine):
filedata[line] = 'our $DATE_UPDATE = \'' + str(now.year) + "-" + str('%02d' % now.month) + "-" + str('%02d' % now.day) + '\';\n'
# write updated array to file
wfile = open('Koha/Plugin/EDS.pm', 'w')
for item in filedata:
wfile.write(item)
#########################
##### Update EDSScript.js #####
with open('Koha/Plugin/EDS/js/EDSScript.tt', 'r') as file :
filedata = file.readlines()
# find and repalce version
for line in range(len(filedata)):
templine = filedata[line].rstrip()
# Set version
if ("var versionEDSKoha =" in templine):
filedata[line] = 'var versionEDSKoha = "' + majorVersion + minorVersion + '";\n'
# write updated array to file
wfile = open('Koha/Plugin/EDS/js/EDSScript.tt', 'w')
for item in filedata:
wfile.write(item)
#########################
##### update release_notes.xml #####
with open('Koha/Plugin/EDS/admin/release_notes.xml', 'r') as file :
filedata = file.readlines()
noted = False
# find and repalce version
for line in range(len(filedata)):
templine = filedata[line].rstrip()
# Set version
if ("<release version" in templine):
filedata[line] = '\t\t<release version="' + majorVersion + "." + minorVersion + '" date="' + str(now.year) + "/" + str('%02d' % now.month) + "/" + str('%02d' % now.day) + '">\n'
# Set version
if ("<latestversion>" in templine):
filedata[line] = '\t<latestversion>' + majorVersion + "." + minorVersion + '</latestversion>\n'
# Set date
if ("<lastupdated>" in templine):
filedata[line] = '\t<lastupdated>' + str(now.year) + "/" + str('%02d' % now.month) + "/" + str('%02d' % now.day) + '</lastupdated>\n'
# add notes
if ("<note id" in templine):
if (noted):
filedata[line] = ''
else:
noted = True
i = 0
superString = ""
for node in releaseNotes:
i+=1
superString+= '\t\t\t<note id="' + str(i) + '" author="' + node["author"] + '">' + node["note"] + '</note>\n'
filedata[line] = superString
# write updated array to file
wfile = open('Koha/Plugin/EDS/admin/release_notes.xml', 'w')
for item in filedata:
wfile.write(item)
#########################
## Update kpz
os.system("rm *.kpz")
os.system("zip -r eds_plugin_" + majorVersion + minorVersion + ".kpz Koha")