cloud-build/cloud_build/rename.py
2021-08-10 16:50:05 +03:00

21 lines
471 B
Python

from typing import Dict
import re
import subprocess
def rename(rename_dict: Dict[str, str], name: str) -> str:
if regex := rename_dict.get('regex'):
to = rename_dict['to']
name = re.sub(regex, to, name)
elif prog := rename_dict.get('prog'):
name = subprocess.run(
[prog, name],
stdout=subprocess.PIPE,
).stdout.decode().strip()
else:
to = rename_dict['to']
name = to
return name