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
|
import argparse
import os
import sys
import subprocess
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
def check_not_in_venv():
if os.environ.get("VIRTUAL_ENV"):
sys.exit("You should not run this in a virtualenv!")
def clean():
cmd = ["git", "clean", "--force", "-d", "-x"]
subprocess.check_call(cmd, cwd=THIS_DIR)
def set_version(version):
pkgbuild = os.path.join(THIS_DIR, "PKGBUILD")
with open(pkgbuild, "r") as fp:
lines = fp.readlines()
new_lines = list()
for line in lines:
if line.startswith("pkgver"):
new_line = "pkgver='%s'\n" % version
new_lines.append(new_line)
else:
new_lines.append(line)
with open(pkgbuild, "w") as fp:
fp.writelines(new_lines)
def get_checksum_line():
cmd = ["makepkg", "--geninteg"]
output = subprocess.check_output(cmd, cwd=THIS_DIR)
return output.decode("utf-8")
def set_checksum(checksum_line):
pkgbuild = os.path.join(THIS_DIR, "PKGBUILD")
with open(pkgbuild, "r") as fp:
lines = fp.readlines()
new_lines = list()
for line in lines:
if line.startswith("md5sums"):
new_lines.append(checksum_line)
else:
new_lines.append(line)
with open(pkgbuild, "w") as fp:
fp.writelines(new_lines)
def run_makepkg():
cmd = ["makepkg"]
subprocess.check_call(cmd, cwd=THIS_DIR)
def run_namcap():
cmd = ["namcap", "PKGBUILD"]
subprocess.check_call(cmd, cwd=THIS_DIR)
contents = os.listdir(THIS_DIR)
pkgs = [x for x in contents if "pkg.tar.xz" in x]
if len(pkgs) != 1:
sys.exit("Expecting one pkg, got %s" % pkgs)
pkg = pkgs[0]
cmd = ["namcap", pkg]
subprocess.check_call(cmd, cwd=THIS_DIR)
def update_srcinfo():
cmd = ["mksrcinfo"]
subprocess.check_call(cmd, cwd=THIS_DIR)
def commit_all(version):
cmd = ["git", "add", "PKGBUILD", ".SRCINFO"]
subprocess.check_call(cmd)
cmd = ["git", "commit", "--message", "Update to %s" % version]
subprocess.check_call(cmd)
def push():
cmd = ["git", "--no-pager", "show", "HEAD"]
subprocess.check_call(cmd)
answer = input("OK to push (y/n)? ")
if answer == "y":
cmd = ["git", "push"]
subprocess.check_call(cmd)
def make_release(version):
clean()
set_version(version)
new_checksum_line = get_checksum_line()
set_checksum(new_checksum_line)
run_makepkg()
print("running namcap ...")
run_namcap()
print("namcap OK")
update_srcinfo()
commit_all(version)
push()
def main():
parser = argparse.ArgumentParser()
parser.add_argument("version")
args = parser.parse_args()
check_not_in_venv()
version = args.version
make_release(version)
if __name__ == "__main__":
main()
|