|
3 | 3 | import logging
|
4 | 4 | from pathlib import Path
|
5 | 5 | from subprocess import check_call
|
| 6 | +import shutil |
| 7 | +import re |
6 | 8 |
|
7 | 9 | from .swaggertosdk.SwaggerToSdkCore import (
|
8 | 10 | CONFIG_FILE,
|
|
22 | 24 | _LOGGER = logging.getLogger(__name__)
|
23 | 25 |
|
24 | 26 |
|
| 27 | +def del_outdated_samples(readme: str): |
| 28 | + python_readme = Path(readme).parent / "readme.python.md" |
| 29 | + if not python_readme.exists(): |
| 30 | + _LOGGER.info(f"do not find python configuration: {python_readme}") |
| 31 | + return |
| 32 | + |
| 33 | + with open(python_readme, "r") as file_in: |
| 34 | + content = file_in.readlines() |
| 35 | + pattern = "$(python-sdks-folder)" |
| 36 | + for line in content: |
| 37 | + if pattern in line: |
| 38 | + sdk_folder = re.findall("[a-z]+/[a-z]+-[a-z]+-[a-z]+", line)[0] |
| 39 | + sample_folder = Path(f"sdk/{sdk_folder}/generated_samples") |
| 40 | + if sample_folder.exists(): |
| 41 | + shutil.rmtree(sample_folder) |
| 42 | + _LOGGER.info(f"remove sample folder: {sample_folder}") |
| 43 | + else: |
| 44 | + _LOGGER.info(f"sample folder does not exist: {sample_folder}") |
| 45 | + return |
| 46 | + |
| 47 | + _LOGGER.info(f"do not find {pattern} in {python_readme}") |
| 48 | + |
| 49 | + |
25 | 50 | def main(generate_input, generate_output):
|
26 | 51 | with open(generate_input, "r") as reader:
|
27 | 52 | data = json.load(reader)
|
@@ -53,6 +78,7 @@ def main(generate_input, generate_output):
|
53 | 78 | _LOGGER.info(f"[CODEGEN]({input_readme})codegen begin")
|
54 | 79 | if "resource-manager" in input_readme:
|
55 | 80 | relative_path_readme = str(Path(spec_folder, input_readme))
|
| 81 | + del_outdated_samples(relative_path_readme) |
56 | 82 | config = generate(
|
57 | 83 | CONFIG_FILE,
|
58 | 84 | sdk_folder,
|
|
0 commit comments