-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkgbuild.py
38 lines (31 loc) · 1.32 KB
/
pkgbuild.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
#!/usr/bin/env python
import fileinput
import json
import os
import re
import sys
from urllib.request import urlopen
__all__ = ['enable_arch']
def enable_arch(bases, arch_to_enable, require_already_enabled_arch=None):
if require_already_enabled_arch:
require_already_enabled_arch = re.escape(f"'{require_already_enabled_arch}'")
else:
require_already_enabled_arch = ""
arch_to_enable = re.escape(arch_to_enable)
linere = re.compile(r"^mingw_arch=.*" + require_already_enabled_arch +
r"(?!.*'" + arch_to_enable + r"').*$")
for base in bases:
if not os.path.exists(os.path.join(base, "PKGBUILD")):
with urlopen("https://packages.msys2.org/api/search?query=%s&qtype=pkg" % base) as f:
x = json.load(f)
base = x["results"]["exact"]["source_url"].rsplit("/", 1)[1]
del x
if not os.path.exists(os.path.join(base, "PKGBUILD")):
print('%s PKGBUILD not found!' % (base,), file=sys.stderr)
continue
with fileinput.input(os.path.join(base, "PKGBUILD"), inplace=True) as f:
for line in f:
if linere.match(line):
print(re.sub(r"(\)\s*)$", r" '" + arch_to_enable + r"'\1", line), end="")
else:
print(line, end="")