|
2 | 2 |
|
3 | 3 | packages = []
|
4 | 4 |
|
| 5 | + |
5 | 6 | def get_packages(parent_directory):
|
6 |
| - valid_dirs_count = 0 |
7 |
| - for first_level_subdir in os.listdir(parent_directory): |
8 |
| - first_level_path = os.path.join(parent_directory, first_level_subdir) |
9 |
| - if os.path.isdir(first_level_path): |
10 |
| - for second_level_subdir in os.listdir(first_level_path): |
11 |
| - second_level_path = os.path.join(first_level_path, second_level_subdir) |
12 |
| - if os.path.isdir(second_level_path): |
13 |
| - files = os.listdir(second_level_path) |
14 |
| - if any(file.endswith('.ebuild') for file in files): |
15 |
| - valid_dirs_count += 1 |
16 |
| - packages.append(second_level_path[2:]) |
| 7 | + valid_dirs_count = 0 |
| 8 | + for first_level_subdir in os.listdir(parent_directory): |
| 9 | + first_level_path = os.path.join(parent_directory, first_level_subdir) |
| 10 | + if os.path.isdir(first_level_path): |
| 11 | + for second_level_subdir in os.listdir(first_level_path): |
| 12 | + second_level_path = os.path.join(first_level_path, second_level_subdir) |
| 13 | + if os.path.isdir(second_level_path): |
| 14 | + files = os.listdir(second_level_path) |
| 15 | + if any(file.endswith('.ebuild') for file in files): |
| 16 | + valid_dirs_count += 1 |
| 17 | + packages.append(second_level_path[2:]) |
| 18 | + |
17 | 19 |
|
18 | 20 | def processEbuild_cpp(file):
|
19 |
| - with open(file, 'r', encoding='utf-8') as f: |
20 |
| - for line in f: |
21 |
| - if "toolchain-funcs" in line and "inherit" in line: |
22 |
| - return True |
23 |
| - elif "cmake" in line: |
24 |
| - return True |
25 |
| - elif "emake" in line: |
26 |
| - return True |
27 |
| - elif "CFLAGS" in line: |
28 |
| - return True |
29 |
| - elif "CXXFLAGS" in line: |
30 |
| - return True |
31 |
| - elif "toolchain" in line: |
32 |
| - return True |
33 |
| - elif "meson" in line: |
34 |
| - return True |
35 |
| - return False |
| 21 | + with open(file, 'r', encoding='utf-8') as f: |
| 22 | + for line in f: |
| 23 | + if "toolchain-funcs" in line and "inherit" in line: |
| 24 | + return True |
| 25 | + elif "cmake" in line: |
| 26 | + return True |
| 27 | + elif "emake" in line: |
| 28 | + return True |
| 29 | + elif "CFLAGS" in line: |
| 30 | + return True |
| 31 | + elif "CXXFLAGS" in line: |
| 32 | + return True |
| 33 | + elif "toolchain" in line: |
| 34 | + return True |
| 35 | + elif "meson" in line: |
| 36 | + return True |
| 37 | + return False |
| 38 | + |
36 | 39 |
|
37 | 40 | def processEbuild_trunk(file):
|
38 |
| - with open(file, 'r', encoding='utf-8') as f: |
39 |
| - for line in f: |
40 |
| - if "KEYWORDS" in line and "amd64 " in line and "~amd64 " not in line: |
41 |
| - return True |
42 |
| - return False |
| 41 | + with open(file, 'r', encoding='utf-8') as f: |
| 42 | + for line in f: |
| 43 | + if "KEYWORDS" in line and "amd64 " in line and "~amd64 " not in line: |
| 44 | + return True |
| 45 | + return False |
| 46 | + |
43 | 47 |
|
44 | 48 | def readpackage(package):
|
45 |
| - files = os.listdir(package) |
46 |
| - for file in files: |
47 |
| - if file.endswith('.ebuild'): |
48 |
| - with open(os.path.join(package,file), 'r', encoding='utf-8') as f: |
49 |
| - for line in f: |
50 |
| - print(line[:-1]) |
51 |
| - return |
52 |
| - |
| 49 | + files = os.listdir(package) |
| 50 | + for file in files: |
| 51 | + if file.endswith('.ebuild'): |
| 52 | + with open(os.path.join(package, file), 'r', encoding='utf-8') as f: |
| 53 | + for line in f: |
| 54 | + print(line[:-1]) |
| 55 | + return |
| 56 | + |
| 57 | + |
53 | 58 | def main():
|
54 |
| - ebuild_directory = "./" |
55 |
| - get_packages(ebuild_directory) |
56 |
| - cpp_pkgs = [] |
57 |
| - for pkg in packages: |
58 |
| - files = os.listdir(pkg) |
59 |
| - for file in files: |
60 |
| - if file.endswith('.ebuild'): |
61 |
| - if processEbuild_trunk(os.path.join(pkg,file)): |
62 |
| - if processEbuild_cpp(os.path.join(pkg,file)): |
63 |
| - cpp_pkgs.append(pkg) |
64 |
| - continue |
65 |
| - |
66 |
| - cpp_pkgs = list(set(cpp_pkgs)) |
67 |
| - with open("../../corpus_descriptions_test/portage_pkg.list", 'w', encoding='utf-8') as f: |
68 |
| - for i in cpp_pkgs: |
69 |
| - f.write(i+"\n") |
70 |
| - |
| 59 | + ebuild_directory = "./" |
| 60 | + get_packages(ebuild_directory) |
| 61 | + cpp_pkgs = [] |
| 62 | + for pkg in packages: |
| 63 | + files = os.listdir(pkg) |
| 64 | + for file in files: |
| 65 | + if file.endswith('.ebuild'): |
| 66 | + if processEbuild_trunk(os.path.join(pkg, file)): |
| 67 | + if processEbuild_cpp(os.path.join(pkg, file)): |
| 68 | + cpp_pkgs.append(pkg) |
| 69 | + continue |
| 70 | + |
| 71 | + cpp_pkgs = list(set(cpp_pkgs)) |
| 72 | + with open( |
| 73 | + "../../corpus_descriptions_test/portage_pkg.list", 'w', |
| 74 | + encoding='utf-8') as f: |
| 75 | + for i in cpp_pkgs: |
| 76 | + f.write(i + "\n") |
| 77 | + |
| 78 | + |
71 | 79 | if __name__ == "__main__":
|
72 |
| - main() |
| 80 | + main() |
0 commit comments