aboutsummaryrefslogtreecommitdiff
blob: f9902c8337678d29823cc15e0647f580aa9e72b1 (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
import os
from subprocess import getstatusoutput
from urllib.request import urlopen

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("`gcc -print-prog-name=cc1` -v ^C")
    #"`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)
    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()

    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:
        #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!")
        print("file not found was: " + dep)
        print("a dummy dep will be placed in the ebuild, fix it!")
        matching_packages = ["dummy_for_" + dep]

    return [matching_packages.pop()]

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