-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect_source.py
More file actions
executable file
·178 lines (141 loc) · 5.1 KB
/
inspect_source.py
File metadata and controls
executable file
·178 lines (141 loc) · 5.1 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/python3
# vim: sw=4 et
import argparse
import datetime
import json
import logging as LOG
import os
import re
from pathlib import Path
import rpm
rpm_ts = rpm.TransactionSet()
CUTOFF_TIMESTAMP = datetime.datetime(2019, 1, 1).timestamp()
def stat_src_changes(fname):
global rpm_ts
try:
fdno = os.open(fname, os.O_RDONLY)
rpm_ts.setVSFlags(~(rpm.RPMVSF_NEEDPAYLOAD))
try:
hdr = rpm_ts.hdrFromFdno(fdno)
except rpm.error as e:
LOG.warning(f'{fname}: {e}')
hdr = None
if not isinstance(hdr, rpm.hdr):
hdr = None
finally:
rpm_ts.setVSFlags(0)
os.close(fdno)
package_name = '%s' % (hdr[rpm.RPMTAG_NAME],)
package_date = hdr[rpm.RPMTAG_BUILDTIME]
r = {
'employee_changes': {},
'community_changes': {},
'version_changes': {},
'patches_changes': {},
'jira_changes': {},
'bugs_changes': {},
}
for name, time, text in zip(
hdr[rpm.RPMTAG_CHANGELOGNAME],
hdr[rpm.RPMTAG_CHANGELOGTIME],
hdr[rpm.RPMTAG_CHANGELOGTEXT],
):
if time < CUTOFF_TIMESTAMP:
continue
changes_timestamp = datetime.datetime.fromtimestamp(time)
year: str = f'{changes_timestamp.year}Q{(1 + (changes_timestamp.month-1) // 3)}'
# LOG.debug(f"{fname}: {name}, {time}, {text}")
if name.partition('@')[2].lower() in ('suse.de', 'suse.cz', 'suse.com'):
r['employee_changes'][year] = r['employee_changes'].setdefault(year, 0) + 1
else:
r['community_changes'][year] = (
r['community_changes'].setdefault(year, 0) + 1
)
patches_mentioned = 0
for p in re.finditer(r'\.(patch|diff)\b', text, re.IGNORECASE):
patches_mentioned += 1
updates_mentioned = 0
for u in re.finditer(
r'^[-+*]\s+update.*\d+\.', text, re.IGNORECASE | re.MULTILINE
):
LOG.debug(f'found version update {u.group(0)}')
updates_mentioned += 1
jiras_mentioned = 0
for u in re.finditer(r'jsc#[A-Z]+-\d+', text, re.IGNORECASE | re.MULTILINE):
jiras_mentioned += 1
bugs_mentioned = 0
for b in re.finditer(r'(bsc|bnc|boo)#\d+', text, re.IGNORECASE | re.MULTILINE):
bugs_mentioned += 1
if updates_mentioned:
r['version_changes'][year] = r['version_changes'].setdefault(year, 0) + 1
elif patches_mentioned:
r['patches_changes'][year] = r['patches_changes'].setdefault(year, 0) + 1
if jiras_mentioned:
r['jira_changes'][year] = r['jira_changes'].setdefault(year, 0) + 1
if bugs_mentioned:
r['bugs_changes'][year] = r['bugs_changes'].setdefault(year, 0) + 1
metric_sum = {}
for metric in r.keys():
metric_sum[metric + '_total'] = sum(r[metric].values())
r.update(metric_sum)
return package_name, package_date, {package_name: r}
def gather_source_rpms(repodir: Path):
packages = {}
r = {}
for p in repodir.iterdir():
if (repodir / p).is_dir():
subdir_pac_set = gather_source_rpms(repodir / p)
r.update(subdir_pac_set)
continue
if not p.name.endswith('.src.rpm') and not p.name.endswith('.nosrc.rpm'):
continue
pac_name, package_date, pacstat = stat_src_changes(repodir / p)
if pac_name not in packages or package_date > packages[pac_name]:
# print(f'New version of {pac_name} found; {package_date};')
packages[pac_name] = package_date
r[pac_name] = pacstat[pac_name]
# r.update(pacstat)
return r
def main():
parse = argparse.ArgumentParser(description='Inspect source DVD')
parse.add_argument('-d', '--debug', action='store_true')
parse.add_argument('repodir', nargs='+', help='path to the source DVD repo')
args = parse.parse_args()
LOG.basicConfig(
level=LOG.DEBUG if args.debug else LOG.INFO,
datefmt='%y-%m-%d %H:%M:%S',
format='%(asctime)s %(message)s',
)
for repostr in args.repodir:
repo = Path(repostr)
if not repo.is_dir():
LOG.fatal(f'Repo {repo} does not exist')
return
repo_pacs = gather_source_rpms(repo)
for tag in (
'employee_changes',
'community_changes',
'version_changes',
'patches_changes',
'jira_changes',
'bugs_changes',
):
print(f'{tag}:')
print('------')
report = {}
for y in (2019, 2020, 2021, 2022, 2023, 2024):
for q in (1, 2, 3, 4):
y_sum = 0
y_quarter = f'{y}Q{q}'
for pac, stats in repo_pacs.items():
if 'kernel' in pac:
continue
if y_quarter in stats[tag]:
y_sum += stats[tag][y_quarter]
print(f'{y_quarter}: {y_sum}')
report[y_quarter] = y_sum
print(report)
print()
# print(json.dumps(repo_pacs))
if __name__ == '__main__':
main()