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