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
|
#!/usr/bin/python
from __future__ import print_function
import os
import re
import rpm
dirs = ['/home/services/ftp/pld/dists/3.0/PLD/x32/RPMS',
'/home/services/ftp/pld/dists/3.0/PLD/i686/RPMS',
'/home/services/ftp/pld/dists/3.0/PLD/x86_64/RPMS',
'/home/services/ftp/pld/dists/3.0/ready/x32/RPMS',
'/home/services/ftp/pld/dists/3.0/ready/i686/RPMS',
'/home/services/ftp/pld/dists/3.0/ready/x86_64/RPMS',
'/home/services/ftp/pld/dists/3.0/test/x32/RPMS',
'/home/services/ftp/pld/dists/3.0/test/i686/RPMS',
'/home/services/ftp/pld/dists/3.0/test/x86_64/RPMS']
#dirs = ['/home/services/ftp/pld/dists/3.0/test/x86_64/RPMS']
outname = "/home/pld/admins/th/www/name-srcname.txt"
re_rpm = re.compile(r'.*\.rpm$')
re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.rpm$')
ts = rpm.ts()
ts.setVSFlags(-1)
pkgs = {}
for dir in dirs:
for file in os.listdir(dir):
if not re_rpm.match(file):
continue
rpm_file = os.path.join(dir, file)
fdno = os.open(rpm_file, os.O_RDONLY)
try:
hdr = ts.hdrFromFdno(fdno)
except Exception as e:
print("hdrFromFdno: %s: %s" % (rpm_file, e))
os.close(fdno)
continue
os.close(fdno)
name = hdr[rpm.RPMTAG_NAME]
sourcerpm = hdr[rpm.RPMTAG_SOURCERPM]
m = re_nvr.match(sourcerpm)
if not m:
print("%s: doesn't match src.rpm file name" % (sourcerpm))
continue
srcname = m.group(1)
pkgs[name] = srcname
f = open(outname + ".tmp", "w")
for (pkg, spkg) in iter(pkgs.items()):
f.write("%s:%s\n" % (pkg, spkg))
f.close()
os.chmod(outname + ".tmp", 0o644)
os.rename(outname + ".tmp", outname)
|