|
1 | 1 | #!/usr/bin/env python
|
| 2 | +import glob |
2 | 3 | import os
|
| 4 | +import shutil |
3 | 5 | import sys
|
4 | 6 | from typing import Set
|
5 | 7 |
|
|
17 | 19 | os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
18 | 20 |
|
19 | 21 |
|
| 22 | +def clear_directory(path: str): |
| 23 | + for file_or_directory in glob.glob(os.path.join(path, "*")): |
| 24 | + if os.path.isdir(file_or_directory): |
| 25 | + shutil.rmtree(file_or_directory) |
| 26 | + else: |
| 27 | + os.remove(file_or_directory) |
| 28 | + |
| 29 | + |
20 | 30 | def generate(whitelist: Set[str]):
|
21 | 31 | path_whitelist = {os.path.realpath(e) for e in whitelist if os.path.exists(e)}
|
22 | 32 | name_whitelist = {e for e in whitelist if not os.path.exists(e)}
|
23 | 33 |
|
24 | 34 | test_case_names = set(get_directories(inputs_path))
|
25 | 35 |
|
26 | 36 | for test_case_name in sorted(test_case_names):
|
27 |
| - test_case_path = os.path.realpath(os.path.join(inputs_path, test_case_name)) |
| 37 | + test_case_input_path = os.path.realpath( |
| 38 | + os.path.join(inputs_path, test_case_name) |
| 39 | + ) |
28 | 40 |
|
29 | 41 | if (
|
30 | 42 | whitelist
|
31 |
| - and test_case_path not in path_whitelist |
| 43 | + and test_case_input_path not in path_whitelist |
32 | 44 | and test_case_name not in name_whitelist
|
33 | 45 | ):
|
34 | 46 | continue
|
35 | 47 |
|
36 |
| - case_output_dir_reference = os.path.join(output_path_reference, test_case_name<
8000
/span>) |
37 |
| - case_output_dir_betterproto = os.path.join( |
| 48 | + test_case_output_path_reference = os.path.join( |
| 49 | + output_path_reference, test_case_name |
| 50 | + ) |
| 51 | + test_case_output_path_betterproto = os.path.join( |
38 | 52 | output_path_betterproto, test_case_name
|
39 | 53 | )
|
40 | 54 |
|
41 | 55 | print(f"Generating output for {test_case_name}")
|
42 |
| - os.makedirs(case_output_dir_reference, exist_ok=True) |
43 |
| - os.makedirs(case_output_dir_betterproto, exist_ok=True) |
| 56 | + os.makedirs(test_case_output_path_reference, exist_ok=True) |
| 57 | + os.makedirs(test_case_output_path_betterproto, exist_ok=True) |
| 58 | + |
| 59 | + clear_directory(test_case_output_path_reference) |
| 60 | + clear_directory(test_case_output_path_betterproto) |
44 | 61 |
|
45 |
| - protoc_reference(test_case_path, case_output_dir_reference) |
46 |
| - protoc_plugin(test_case_path, case_output_dir_betterproto) |
| 62 | + protoc_reference(test_case_input_path, test_case_output_path_reference) |
| 63 | + protoc_plugin(test_case_input_path, test_case_output_path_betterproto) |
47 | 64 |
|
48 | 65
|
49 | 66 | HELP = "\n".join(
|
|
0 commit comments