-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcommon.py
More file actions
28 lines (21 loc) · 824 Bytes
/
common.py
File metadata and controls
28 lines (21 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from abc import ABCMeta
from enum import Enum
from pathlib import Path
from pydantic import BaseModel
from codemodder.logging import logger
class CaseInsensitiveEnum(str, Enum):
@classmethod
def _missing_(cls, value: object):
if not isinstance(value, str):
return super()._missing_(value)
return cls.__members__.get(value.upper())
class CodeTFWriter(BaseModel, metaclass=ABCMeta):
def write_report(self, outfile: Path | str) -> int:
try:
Path(outfile).write_text(self.model_dump_json(exclude_none=True))
except Exception:
logger.exception("failed to write report file.")
# Any issues with writing the output file should exit status 2.
return 2
logger.debug("wrote report to %s", outfile)
return 0