]> TLD Linux GIT Repositories - tld-builder.git/blob - TLD_Builder/poldek.py
- python 3.x fixes
[tld-builder.git] / TLD_Builder / poldek.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import re
4 import types
5 import string
6
7 from chroot import *
8 from util import *
9
10
11 def get_poldek_requires():
12     # precompile regexps
13     name_rx = re.compile(r"\d+\. ([^\s]+)-[^-]+-[^-]+\n")
14     req_rx = re.compile(r" req .* --> (.*)\n")
15     pkg_name_rx = re.compile(r"([^\s]+)-[^-]+-[^-]+")
16
17     # todo: if a and b are sets, then use sets module
18     # and intersection method on set object
19     def intersect(a, b):
20         r = []
21         for x in a:
22             if x in b: r.append(x)
23         return r
24
25     # add given req-list to cur_pkg_reqs
26     def add_req(reqs):
27         if len(reqs) == 1:
28             if reqs[0] not in cur_pkg_reqs:
29                 cur_pkg_reqs.append(reqs[0])
30         else:
31             did = 0
32             for x in cur_pkg_reqs:
33                 if type(x) is types.ListType:
34                     i = intersect(x, reqs)
35                     if len(i) == 0:
36                         continue
37                     did = 1
38                     idx = cur_pkg_reqs.index(x)
39                     if len(i) == 1:
40                         if i[0] in cur_pkg_reqs:
41                             del cur_pkg_reqs[idx]
42                         else:
43                             cur_pkg_reqs[idx] = i[0]
44                     else:
45                         cur_pkg_reqs[idx] = i
46                 else:
47                     if x in reqs:
48                         return
49             if not did:
50                 cur_pkg_reqs.append(reqs)
51
52     pkg_reqs = {}
53     cur_pkg_reqs = None
54     cur_pkg = None
55
56     f = chr_popen("poldek -v -v --verify --unique-pkg-names")
57     for l in f:
58         m = name_rx.match(l)
59         if m:
60             if cur_pkg:
61                 pkg_reqs[cur_pkg] = cur_pkg_reqs
62             cur_pkg = m.groups(1)
63             if cur_pkg in pkg_reqs:
64                 cur_pkg = None
65                 cur_pkg_reqs = None
66             else:
67                 cur_pkg_reqs = []
68             continue
69         m = req_rx.match(l)
70         if m:
71             reqs = []
72             for x in m.group(1).split():
73                 if x in ["RPMLIB_CAP", "NOT", "FOUND", "UNMATCHED"]: continue
74                 m = pkg_name_rx.match(x)
75                 if m:
76                     reqs.append(m.group(1))
77                 else:
78                     msg("poldek_reqs: bad pkg name: %s\n" % x)
79             if len(reqs) != 0: add_req(reqs)
80
81     f.close()
82
83     if cur_pkg:
84         pkg_reqs[cur_pkg] = cur_pkg_reqs
85
86     return pkg_reqs