summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/opentelemetry-cpp/tools/vcpkg/scripts/file_script.py
blob: de57f2720991fb446d8a89bea063e0da82f5b715 (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
import os
import os.path
import sys


keyword = "include/"

def getFiles(path):
    files = os.listdir(path)
    return list(filter(lambda x: x[0] != '.', files))

def gen_all_file_strings(path, files, headers, output):
    for file in files:
        package = file[:file.find("_")]
        f = open(path + file)
        for line in f:
            idx = line.strip().find(keyword)
            if idx >= 0 and line.strip()[-1] != "/":
                headers.write(package + ":" + line[idx + len(keyword):])
                output.write(package + ":" + line[idx-1:])
            elif line.strip()[-1] != "/":
                output.write(package + ":" + line[line.find("/"):])
        f.close()

def main(path):
    try:
        os.mkdir("scripts/list_files")
    except FileExistsError:
        print("Path already exists, continuing...")

    try:
        headers = open("scripts/list_files/VCPKGHeadersDatabase.txt", mode='w')
        output = open("scripts/list_files/VCPKGDatabase.txt", mode='w')
        gen_all_file_strings(path, getFiles(path), headers, output)
        headers.close()
        output.close()
    except e:
        print("Failed to generate file lists")

if __name__ == "__main__":
    main(sys.argv[1])