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