-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmkrel.py
executable file
·161 lines (129 loc) · 3.98 KB
/
mkrel.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
#
# LMS-BlissMixer
#
# Copyright (c) 2022-2023 Craig Drummond <craig.p.drummond@gmail.com>
# MIT license.
#
import hashlib
import os
import re
import requests
import shutil
import sys
REPO_XML = "repo.xml"
PLUGIN_NAME = "BlissMixer"
PLUGIN_GIT_NAME = "lms-blissmixer"
def info(s):
print("INFO: %s" %s)
def error(s):
print("ERROR: %s" % s)
exit(-1)
def usage():
print("Usage: %s <major>.<minor>.<patch>" % sys.argv[0])
exit(-1)
def checkVersion(version):
try:
parts=version.split('.')
major=int(parts[0])
minor=int(parts[1])
patch=int(parts[2])
except:
error("Invalid version number")
def releaseUrl(version):
return "https://github.com/CDrummond/%s/releases/download/%s/%s-%s.zip" % (PLUGIN_GIT_NAME, version, PLUGIN_GIT_NAME, version)
def checkVersionExists(version):
url = releaseUrl(version)
info("Checking %s" % url)
request = requests.head(url)
if request.status_code == 200 or request.status_code == 302:
error("Version already exists")
def updateLine(line, startStr, endStr, updateStr):
start=line.find(startStr)
if start!=-1:
start+=len(startStr)
end=line.find(endStr, start)
if end!=-1:
return "%s%s%s" % (line[:start], updateStr, line[end:])
return None
def updateInstallXml(version):
lines=[]
updated=False
installXml = "%s/install.xml" % PLUGIN_NAME
info("Updating %s" % installXml)
with open(installXml, "r") as f:
lines=f.readlines()
for i in range(len(lines)):
updated = updateLine(lines[i], "<version>", "</version>", version)
if updated:
lines[i]=updated
updated=True
break
if not updated:
error("Failed to update version in %s" % installXml)
with open(installXml, "w") as f:
for line in lines:
f.write(line)
def createZip(version):
info("Creating ZIP")
zipFile="%s-%s" % (PLUGIN_GIT_NAME, version)
shutil.make_archive(zipFile, 'zip', PLUGIN_NAME)
zipFile+=".zip"
return zipFile
def getSha1Sum(zipFile):
info("Generating SHA1")
sha1 = hashlib.sha1()
with open(zipFile, 'rb') as f:
while True:
data = f.read(65535)
if not data:
break
sha1.update(data)
return sha1.hexdigest()
def updateRepoXml(repo, version, zipFile, sha1, pluginName=None):
lines=[]
updatedVersion=False
updatedUrl=False
updatedSha=False
info("Updating %s" % repo)
inSection = pluginName is None
with open(repo, "r") as f:
lines=f.readlines()
for i in range(len(lines)):
if pluginName is not None and '<plugin name="' in lines[i]:
inSection = pluginName in lines[i]
if inSection:
updated = updateLine(lines[i], 'version="', '"', version)
if updated:
lines[i]=updated
updatedVersion=True
updated = updateLine(lines[i], '<url>', '</url>', releaseUrl(version))
if updated:
lines[i]=updated
updatedUrl=True
updated = updateLine(lines[i], '<sha>', '</sha>', sha1)
if updated:
lines[i]=updated
updatedSha=True
if updatedVersion and updatedUrl and updatedSha:
break
if not updatedVersion:
error("Failed to update version in %s" % repo)
if not updatedUrl:
error("Failed to url version in %s" % repo)
if not updatedSha:
error("Failed to sha version in %s" % repo)
with open(repo, "w") as f:
for line in lines:
f.write(line)
if 1==len(sys.argv):
usage()
version=sys.argv[1]
if version!="test":
checkVersion(version)
checkVersionExists(version)
updateInstallXml(version)
zipFile = createZip(version)
sha1 = getSha1Sum(zipFile)
if version!="test" and os.path.exists(REPO_XML):
updateRepoXml(REPO_XML, version, zipFile, sha1, PLUGIN_NAME)