aboutsummaryrefslogtreecommitdiff
blob: 3a036a3e002eb437329d3947def908a47778e2e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3

import hashlib, portage

def format_deps(dep_list):
    for item in list(dep_list):
        if "||" in item:
            dep_list.remove(item)
        if "?" in item:
            dep_list.remove(item)

    index = 0
    for item in list(dep_list):
        dep_list[index] = item.split('[')[0]
        dep_list[index] = portage.dep.dep_getcpv(item)
        index += 1

    index = 0
    for item in list(dep_list):
        if portage.getCPFromCPV(item):
            dep_list[index] = portage.getCPFromCPV(item)
        index += 1

    return dep_list

def join_deps(f_depend, f_rdepend, f_pdepend):
    return ';'.join(sorted(list(set(f_depend + f_rdepend + f_pdepend))))

def get_deps(cpv):
    depend, rdepend, pdepend = portage.portdb.aux_get(cpv, ['DEPEND', 'RDEPEND', 'PDEPEND'])
    depend = portage.dep.flatten(portage.dep.paren_reduce(depend, 1))
    rdepend = portage.dep.flatten(portage.dep.paren_reduce(rdepend, 1))
    pdepend = portage.dep.flatten(portage.dep.paren_reduce(pdepend, 1))
    return join_deps(format_deps(depend), format_deps(rdepend), format_deps(pdepend))

def format_output(cpv, slot, iuse, keyword):
    category, pkgname, version, revision = portage.catpkgsplit(cpv)
    sha1 = hashlib.sha1(open(PORTTREE.dbapi.findname(cpv), 'rb').read()).hexdigest()
    print(sha1 + ' ' + \
            category + ' ' + \
            pkgname + ' ' + \
            version + ' ' + \
            revision + ' ' + \
            slot + ' ' + \
            keyword, \
            end=' ')
    if 'ruby_targets_ruby20' in iuse:
        print('ruby20', end=' ')
    else:
        print('nil', end=' ')
    if 'ruby_targets_ruby21' in iuse:
        print('ruby21', end=' ')
    else:
        print('nil', end=' ')
    if 'ruby_targets_ruby22' in iuse:
        print('ruby22', end=' ')
    else:
        print('nil', end=' ')
    if 'ruby_targets_ruby23' in iuse:
        print('ruby23', end=' ')
    else:
        print('nil', end=' ')
    print(get_deps(cpv), end=' ')
    print()


PORTTREE = portage.db[portage.root]['porttree']
for cp in PORTTREE.dbapi.cp_all():
    slot_dict = {}
    for cpv in PORTTREE.dbapi.cp_list(cp):
        slot, iuse = PORTTREE.dbapi.aux_get(cpv, ['SLOT', 'IUSE'])
        slot_dict.setdefault(slot, {})[cpv] = (iuse)
    for slot, cpvd in slot_dict.items():
        if 'ruby_targets_' in iuse:

            cpvbs = (PORTTREE.dep_bestmatch(cp))
            if cpvbs:
                slot, iuse, keywords = PORTTREE.dbapi.aux_get(cpvbs, ['SLOT', 'IUSE', 'KEYWORDS'])
                if '~amd64' not in keywords and 'amd64' in keywords:
                    format_output(cpvbs, slot, iuse, 'amd64')

            cpvbu = portage.best(list(cpvd))
            if cpvbu:
                slot, iuse, keywords = PORTTREE.dbapi.aux_get(cpvbu, ['SLOT', 'IUSE', 'KEYWORDS'])
                if '~amd64' in keywords:
                    format_output(cpvbu, slot, iuse, '~amd64')