aboutsummaryrefslogtreecommitdiff
blob: 655af1cdd07a8722c42b795fe9edf25a776c92ed (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
from subprocess import getstatusoutput
from urllib.request import urlopen
import gentoopm

def deptopackage(dep,addpaths):
    #return pfltopackage(dep,addpaths)
    return qfiletopackage(dep,addpaths)

def qfiletopackage(dep,addpaths):
    """Converts supplied deps with additional include paths to portage packages

    This uses qfile to quess which package certain files belongs to.
    """

    print(dep)
    (statuscode,outstr) = getstatusoutput('echo "" | `gcc -print-prog-name=cc1` -v -q')
    #"`gcc -print-prog-name=cc1plus` -v" for cpp
    outlst = outstr.split("\n")
    incpaths = []
    for item in outlst:
        if item[:2] == " /":
            incpaths += [item[1:]]
    incpaths += addpaths
    depname = os.path.split(dep)[1]

    (statuscode,packagestr) = getstatusoutput("qfile -C " + depname)
    if not statuscode == 0:
        package = pfltopackage(dep,incpaths)

    else:
        packagelst = packagestr.split()
        package = []
        n = 0
        for depfile in packagelst[1::2]:
            for incpath in incpaths:
                if depfile.strip("()") == (incpath + "/" + dep):
                    package.append(packagelst[n])
            n += 2

        if len(package) > 1:
            print("more than one matching package were found!")

        if not package:
            package = pfltopackage(dep,incpaths)

    print(package)
    #check if package exists
    pm=gentoopm.get_package_manager()
    if package:
        #does the package exist in this computers package manager?
        if pm.stack.filter(package[0]):
            return package[0]
        else:
            print("No package named: " + package[0] + " found localy, ignoring")
            return []
    else:
        return package

def pfltopackage(dep,addpaths):
    """This uses the online ply database to guess packages

    """

    print(dep)
    incpaths = addpaths

    url_lines = []
    depname = os.path.split(dep)[1]
    matching_packages = set()
    all_packages = set()

    url = urlopen("http://www.portagefilelist.de/index.php/Special:PFLQuery2?file="
            + depname + "&searchfile=lookup&lookup=file&txt")

    for line in url:
        url_lines += [line.decode("utf-8").split()]

    #First line does not contain any useful information, skip it
    url_lines = url_lines[1:]
    #structure of lines: [portage_category, package, path, file, misc, version]

    for line in url_lines:
        all_packages.add(line[0] + "/" + line[1])
        #check if path is correct
        for path in incpaths:
            if line[2] + "/" + line[3] == path + "/" + dep:
                matching_packages.add(line[0] + "/" + line[1])

    if len(matching_packages) > 1:
        print("More than one matching package for dep found!\nPicking the last one...")

    if not matching_packages:
        print("no matching package found within the include paths!")
        if len(all_packages) == 1:
            print("but only one package matches the headerfile, picking that one")
            matching_packages = all_packages
        elif all_packages:
            print("file not found was: " + dep)
            print("a dummy dep will be placed in the ebuild, fix it!")
            matching_packages = ["dummy_for_" + dep]
        else:
            print("No package supplies the headerfile, ignoring...")
            return []

    return [matching_packages.pop()]

#qfiletopackage("jack/ringbuffer.h",[])