-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrj.py
57 lines (49 loc) · 1.12 KB
/
mrj.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
import tarfile
import tempfile
import sys
from os.path import exists
import json
if len(sys.argv) > 1:
repo = sys.argv[1]
else:
print("error: unset repo value")
exit(1)
db_list_pkgs = {}
tar = tarfile.open(f"{repo}.db.tar.gz", "r")
tmp_dir = tempfile.TemporaryDirectory()
for i in tar.getmembers():
i_sp = i.name.split("/")
if i_sp[-1] == "desc":
i0_sp = i_sp[0].split("-")
namepkg = ""
for j in range(len(i0_sp)-2):
namepkg += i0_sp[j]
if j+1 != len(i0_sp)-2:
namepkg += "-"
tar.extract(i.name, path=tmp_dir.name)
file = open(f"{tmp_dir.name}/{i.name}", "r")
pkginfo = {}
index = None
value = None
for j in file.readlines():
j_rig = j.replace("\n", "")
if "%" in j_rig:
index = j_rig.replace("%", "")
elif j_rig != "":
if value == None:
value = j_rig
else:
if type(value) == str:
value = [value]
value += [j_rig]
else:
if index != "NAME":
pkginfo[index] = value
index = None
value = None
file.close()
db_list_pkgs[namepkg] = pkginfo
tar.close()
tmp_dir.cleanup()
with open(f"{repo}.json", "w") as outfile:
json.dump(db_list_pkgs, outfile)