]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - wwwbin/dump-packagenames.py
Switch to Python 3 for rpm.org rpm
[projects/pld-ftp-admin.git] / wwwbin / dump-packagenames.py
1 #!/usr/bin/python3
2
3 from __future__ import print_function
4
5 import os
6 import re
7
8 import rpm
9
10 dirs = ['/home/services/ftp/pld/dists/3.0/PLD/x32/RPMS',
11                 '/home/services/ftp/pld/dists/3.0/PLD/i686/RPMS',
12                 '/home/services/ftp/pld/dists/3.0/PLD/x86_64/RPMS',
13                 '/home/services/ftp/pld/dists/3.0/ready/x32/RPMS',
14                 '/home/services/ftp/pld/dists/3.0/ready/i686/RPMS',
15                 '/home/services/ftp/pld/dists/3.0/ready/x86_64/RPMS',
16                 '/home/services/ftp/pld/dists/3.0/test/x32/RPMS',
17                 '/home/services/ftp/pld/dists/3.0/test/i686/RPMS',
18                 '/home/services/ftp/pld/dists/3.0/test/x86_64/RPMS']
19
20 #dirs = ['/home/services/ftp/pld/dists/3.0/test/x86_64/RPMS']
21
22 outname = "/home/pld/admins/th/www/name-srcname.txt"
23
24 re_rpm = re.compile(r'.*\.rpm$')
25 re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.rpm$')
26
27 ts = rpm.ts()
28 ts.setVSFlags(-1)
29 pkgs = {}
30 for dir in dirs:
31         for file in os.listdir(dir):
32                 if not re_rpm.match(file):
33                         continue
34
35                 rpm_file = os.path.join(dir, file)
36
37                 fdno = os.open(rpm_file, os.O_RDONLY)
38                 try:
39                         hdr = ts.hdrFromFdno(fdno)
40                 except Exception as e:
41                         print("hdrFromFdno: %s: %s" % (rpm_file, e))
42                         os.close(fdno)
43                         continue
44                 os.close(fdno)
45
46                 name = hdr[rpm.RPMTAG_NAME]
47                 sourcerpm = hdr[rpm.RPMTAG_SOURCERPM]
48                 m = re_nvr.match(sourcerpm)
49                 if not m:
50                         print("%s: doesn't match src.rpm file name" % (sourcerpm))
51                         continue
52                 srcname = m.group(1)
53                 pkgs[name] = srcname
54
55 f = open(outname + ".tmp", "w")
56 for (pkg, spkg) in iter(pkgs.items()):
57         f.write("%s:%s\n" % (pkg, spkg))
58 f.close()
59 os.chmod(outname + ".tmp", 0o644)
60 os.rename(outname + ".tmp", outname)
61
This page took 0.066862 seconds and 3 git commands to generate.