]>
Commit | Line | Data |
---|---|---|
a1e62e44 | 1 | #!/usr/bin/python3 |
ed1ec331 | 2 | |
94960bbc JR |
3 | from __future__ import print_function |
4 | ||
ed1ec331 ER |
5 | import os |
6 | import re | |
7 | ||
8 | import rpm | |
9 | ||
b27647ca | 10 | dirs = ['/home/services/ftp/pld/dists/3.0/PLD/x32/RPMS', |
ed1ec331 ER |
11 | '/home/services/ftp/pld/dists/3.0/PLD/i686/RPMS', |
12 | '/home/services/ftp/pld/dists/3.0/PLD/x86_64/RPMS', | |
b27647ca | 13 | '/home/services/ftp/pld/dists/3.0/ready/x32/RPMS', |
ed1ec331 ER |
14 | '/home/services/ftp/pld/dists/3.0/ready/i686/RPMS', |
15 | '/home/services/ftp/pld/dists/3.0/ready/x86_64/RPMS', | |
b27647ca | 16 | '/home/services/ftp/pld/dists/3.0/test/x32/RPMS', |
ed1ec331 ER |
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) | |
9c170c61 | 40 | except Exception as e: |
94960bbc | 41 | print("hdrFromFdno: %s: %s" % (rpm_file, e)) |
ed1ec331 ER |
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: | |
94960bbc | 50 | print("%s: doesn't match src.rpm file name" % (sourcerpm)) |
ed1ec331 ER |
51 | continue |
52 | srcname = m.group(1) | |
53 | pkgs[name] = srcname | |
54 | ||
55 | f = open(outname + ".tmp", "w") | |
94960bbc | 56 | for (pkg, spkg) in iter(pkgs.items()): |
ed1ec331 ER |
57 | f.write("%s:%s\n" % (pkg, spkg)) |
58 | f.close() | |
ff13be59 | 59 | os.chmod(outname + ".tmp", 0o644) |
ed1ec331 ER |
60 | os.rename(outname + ".tmp", outname) |
61 |