32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import argparse
|
||
|
from os import fdopen, path
|
||
|
import os
|
||
|
import re
|
||
|
import shutil
|
||
|
from sys import argv
|
||
|
import tempfile
|
||
|
|
||
|
def update_naming_scheme(recipe_path):
|
||
|
original_recipe = path.abspath(recipe_path)
|
||
|
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__":
|
||
|
update_naming_scheme(argv[1])
|