-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdbfromrepo.py
executable file
·119 lines (104 loc) · 3.46 KB
/
dbfromrepo.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
#!/usr/bin/env python3
# pkgs.void - web catalog of Void Linux packages.
# Copyright (C) 2019-2020 Piotr Wójcik <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import subprocess
import sys
from collections import defaultdict
from datetime import timedelta
import datasource
from sink import now
DISTDIR = os.environ['XBPS_DISTDIR']
_XBPS_SRC_FIELDS = {
'Upstream URL': 'homepage',
'License(s)': 'license',
}
_SINGLE_VALUE_FIELDS = {
'build-date',
'homepage',
'license',
'maintainer',
'pkgname',
'pkgver',
'restricted',
'revision',
'short_desc',
'version',
}
def templatedata(pkgname, arch):
del arch
result = defaultdict(list)
try:
xbps_src = subprocess.run(
[DISTDIR + '/xbps-src', 'show', '-p', 'restricted*', pkgname],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL
)
except subprocess.CalledProcessError:
return result
lines = xbps_src.stdout.decode('utf-8').split('\n')
for line in lines:
try:
field, value = line.split(':', 1)
except ValueError:
continue
result[field].append(value.strip())
return result
def build_db(source, repos):
today = now().date()
tomorrow = today + timedelta(days=1)
srcpkgs = os.path.join(DISTDIR, 'srcpkgs')
for pkgname in os.listdir(srcpkgs):
entry = os.path.join(srcpkgs, pkgname)
if os.path.islink(entry) or not os.path.isdir(entry):
continue
raw_data = templatedata(pkgname, repos[0])
dictionary = {}
for k, v in raw_data.items():
k = _XBPS_SRC_FIELDS.get(k, k)
if k in _SINGLE_VALUE_FIELDS:
dictionary[k] = v[0]
else:
dictionary[k] = v
try:
pkgver = '{pkgname}-{version}_{revision}'.format(**dictionary)
except KeyError:
continue
dictionary['pkgver'] = pkgver
dictionary['source-revisions'] = dictionary['pkgname']
template_json = datasource.to_json(dictionary)
restricted = dictionary.get('restricted', False)
in_source = source.exists(pkgname=pkgname, pkgver=pkgver)
if 'restricted' in dictionary or not in_source:
if restricted == 'yes':
restricted = True
source.create(datasource.PackageRow(
pkgname=pkgname,
pkgver=pkgver,
arch='unknown-unknown',
restricted=restricted,
templatedata=template_json,
mainpkg=pkgname,
repo=''
), dates=[today, tomorrow])
else:
source.update(
pkgname=pkgname,
pkgver=pkgver,
set_templatedata=template_json
)
if __name__ == '__main__':
datasource.update(lambda x: build_db(x, sys.argv[1:]))