-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkrel.py
executable file
·91 lines (65 loc) · 1.95 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
#!/usr/bin/env python3
#
# Essentia API Server
#
# Copyright (c) 2020-2021 Craig Drummond <[email protected]>
# GPLv3 license.
#
import hashlib
import os
import re
import requests
import shutil
import subprocess
import sys
APP_NAME = "essentia-api"
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" % (APP_NAME, version, APP_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 updateVersion(version):
path = os.path.join('lib', 'version.py')
os.remove(path)
with open(path, "w") as f:
f.write("ESSENTIA_API_VERSION='%s'\n" % version)
def resetVersion():
subprocess.call(['git', 'checkout', os.path.join('lib', 'version.py')], shell=False)
def createZip(version):
info("Creating ZIP")
os.chdir('..')
cmd=["zip", "-r", "%s/%s-%s.zip" % (APP_NAME, APP_NAME, version)]
for f in ["ChangeLog", "config.json", "essentia-api.py", "essentia-api.service", "LICENSE", "README.md"]:
cmd.append("%s/%s" % (APP_NAME, f))
for e in os.listdir("%s/lib" % APP_NAME):
if e.endswith(".py"):
cmd.append("%s/lib/%s" % (APP_NAME, e))
subprocess.call(cmd, shell=False)
os.chdir(APP_NAME)
version=sys.argv[1]
if version!="test":
checkVersion(version)
checkVersionExists(version)
updateVersion(version)
createZip(version)
if version!="test":
resetVersion();