SERVER-96380 buildozer_utils additions (#30401)

GitOrigin-RevId: 9eac886ef5981d3248699e0182dbc57f57e7237c
This commit is contained in:
Zac 2024-12-16 15:40:11 -06:00 committed by MongoDB Bot
parent eaac003960
commit 73452cc012
1 changed files with 27 additions and 2 deletions

View File

@ -3,14 +3,19 @@ from typing import List
def _bd_command(cmd: str, labels: List[str]):
print(
f"buildozer '{cmd}' " + " ".join(labels),
)
p = subprocess.run(
f"buildozer '{cmd}' " + " ".join(labels),
capture_output=True,
shell=True,
text=True,
check=True,
check=False,
)
if p.returncode != 0:
print(p.stdout, p.stderr)
raise Exception()
return p
@ -18,6 +23,10 @@ def bd_add(labels: List[str], attr: str, values: List[str]) -> None:
_bd_command(f'add {attr} {" ".join(values)}', labels)
def bd_set(labels: List[str], attr: str, value: str) -> None:
_bd_command(f"set {attr} {value}", labels)
def bd_remove(labels: List[str], attr: str, values: List[str]) -> None:
_bd_command(f'remove {attr} {" ".join(values)}', labels)
@ -28,3 +37,19 @@ def bd_new(package: str, rule_kind: str, rule_name: str) -> None:
def bd_comment(labels: List[str], comment: str, attr: str = "", value: str = "") -> None:
_bd_command(f"comment {attr} {value} {comment}", labels)
def bd_print(labels: List[str], attrs: List[str]) -> None:
_bd_command(f'print {" ".join(attrs)}', labels)
def bd_new_load(packages: List[str], path: str, rules: List[str]) -> None:
_bd_command(f'new_load {path} {" ".join(rules)}', packages)
def bd_fix(fixes: List[str]) -> None:
_bd_command(f'fix {" ".join(fixes)}', [])
def bd_copy(labels: List[str], attr: str, from_rule: str) -> None:
_bd_command(f"copy {attr} {from_rule}", labels)