Module continuous_delivery_scripts.utils.news_file
Helpers with regards to news files.
Functions
def create_news_file(news_dir: str, news_ref: str | None, news_text: str, news_type: Any) ‑> pathlib.Path-
Expand source code
def create_news_file(news_dir: str, news_ref: Optional[str], news_text: str, news_type: Any) -> pathlib.Path: """Facilitates creating a news file, determining its file name based on the type.""" message_type = NewsType.misc if isinstance(news_type, str): message_type = NewsType[news_type] elif isinstance(news_type, NewsType): message_type = news_type file_path = determine_news_file_path(news_dir, news_ref, message_type) _write_file(file_path, news_text) return file_pathFacilitates creating a news file, determining its file name based on the type.
def determine_basic_new_news_file_name() ‑> str-
Expand source code
def determine_basic_new_news_file_name() -> str: """Returns a new news file name.""" now_ns = time.time_ns() seconds, nanoseconds = divmod(now_ns, 1_000_000_000) return f"{datetime.fromtimestamp(seconds):%Y%m%d%H%M%S}{nanoseconds:09d}"Returns a new news file name.
def determine_news_file_path(news_dir: str,
news_ref: str | None,
news_type: NewsType) ‑> pathlib.Path-
Expand source code
def determine_news_file_path(news_dir: str, news_ref: Optional[str], news_type: NewsType) -> pathlib.Path: """Returns an available file path for given news type.""" news_file_name = news_ref if news_ref else determine_basic_new_news_file_name() news_file_path = pathlib.Path(news_dir, f"{news_file_name}.{news_type.name}") inc = 0 while news_file_path.exists(): inc += 1 news_file_path = news_file_path.with_name(f"{news_file_name}{inc:0=2}.{news_type.name}") return news_file_pathReturns an available file path for given news type.
Classes
class NewsType (*values)-
Expand source code
class NewsType(enum.Enum): """Describes the type of news we're writing.""" bugfix = 0 doc = 1 feature = 2 major = 3 misc = 4 removal = 5Describes the type of news we're writing.
Ancestors
- enum.Enum
Class variables
var bugfix-
The type of the None singleton.
var doc-
The type of the None singleton.
var feature-
The type of the None singleton.
var major-
The type of the None singleton.
var misc-
The type of the None singleton.
var removal-
The type of the None singleton.