2024-01-04 15:35:09 +00:00
|
|
|
import os
|
2024-05-16 16:23:35 +00:00
|
|
|
from contextlib import contextmanager
|
2024-01-04 15:35:09 +00:00
|
|
|
from pathlib import Path
|
2024-05-16 16:23:35 +00:00
|
|
|
from typing import Any, Iterator, List, Union
|
2024-01-04 15:35:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WithIter(type):
|
|
|
|
def __iter__(cls):
|
|
|
|
return (v for k, v in cls.__dict__.items() if not k.startswith("_"))
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def cd(path: Union[Path, str]) -> Iterator[None]:
|
|
|
|
oldpwd = os.getcwd()
|
|
|
|
os.chdir(path)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(oldpwd)
|
2024-02-02 17:10:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_hex(s):
|
|
|
|
try:
|
|
|
|
int(s, 16)
|
|
|
|
return True
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2024-02-04 19:12:37 +00:00
|
|
|
def normalize_string(string: str) -> str:
|
|
|
|
lowercase_string = string.lower()
|
|
|
|
normalized_string = (
|
|
|
|
lowercase_string.replace(" ", "_")
|
|
|
|
.replace("-", "_")
|
|
|
|
.replace("/", "_")
|
|
|
|
.replace("(", "")
|
|
|
|
.replace(")", "")
|
|
|
|
.replace(",", "")
|
|
|
|
)
|
|
|
|
return normalized_string
|
|
|
|
|
|
|
|
|
2024-02-02 17:10:47 +00:00
|
|
|
class GHActions:
|
|
|
|
@staticmethod
|
2024-02-04 19:12:37 +00:00
|
|
|
def print_in_group(group_name: str, lines: Union[Any, List[Any]]) -> None:
|
2024-02-02 17:10:47 +00:00
|
|
|
lines = list(lines)
|
|
|
|
print(f"::group::{group_name}")
|
|
|
|
for line in lines:
|
|
|
|
print(line)
|
|
|
|
print("::endgroup::")
|