2025-02-17 15:50:33 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2025-02-17 15:13:27 +00:00
|
|
|
import argparse
|
|
|
|
from os import fdopen, path
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
from sys import argv
|
|
|
|
import tempfile
|
|
|
|
|
2025-02-17 15:50:33 +00:00
|
|
|
def update_naming_scheme(recipe_path):
|
|
|
|
original_recipe = path.abspath(recipe_path)
|
2025-02-17 15:13:27 +00:00
|
|
|
original_meta = path.join(original_recipe, "meta.yaml")
|
|
|
|
new_fd, new_file_path = tempfile.mkstemp()
|
|
|
|
with fdopen(new_fd, "w") as new_file_handle:
|
|
|
|
with open(original_meta, "r") as original_file_handle:
|
|
|
|
for line in original_file_handle:
|
|
|
|
matches = re.finditer(r"\{\{\s*name\|lower()\s+\}\}", line)
|
|
|
|
modified_line = line
|
|
|
|
for match in matches:
|
|
|
|
modified_line = modified_line[:match.start(1)] + r'|replace(".", "-")' + modified_line[match.end(1):]
|
|
|
|
new_file_handle.write(modified_line)
|
|
|
|
shutil.move(new_file_path, original_meta)
|
|
|
|
new_recipe_name = path.join(
|
|
|
|
path.dirname(original_recipe),
|
|
|
|
path.basename(original_recipe).replace(".", "-").lower())
|
|
|
|
shutil.rmtree(new_recipe_name, ignore_errors=True)
|
|
|
|
os.replace(original_recipe,
|
|
|
|
new_recipe_name)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2025-02-17 15:50:33 +00:00
|
|
|
update_naming_scheme(argv[1])
|