Skip to main content

specfile.changelog

ChangelogStyle​

@unique
class ChangelogStyle(Enum)

Style of changelog entries

standard​

standard changelog entries parseable by RPM (used in Fedora, RHEL, etc.):

  • $DATE $AUTHOR <$EMAIL> - $EVR $ENTRY

openSUSE​

openSUSE/SUSE style detached changelog:​

$DATE - $AUTHOR <$EMAIL> $ENTRY

ChangelogEntry​

class ChangelogEntry()

Class that represents a changelog entry. Changelog entry consists of a header line starting with *, followed by timestamp, author and optional extra text (usually EVR), and one or more content lines.

Attributes:

  • header - Header of the entry.
  • content - List of lines forming the content of the entry.

__init__​

def __init__(header: str,
content: List[str],
following_lines: Optional[List[str]] = None) -> None

Initializes a changelog entry object.

Arguments:

  • header - Header of the entry.
  • content - List of lines forming the content of the entry.
  • following_lines - Extra lines that follow the entry.

evr​

@property
def evr() -> Optional[EVR]

EVR (epoch, version, release) of the entry.

Parsing is best effort, RPM doesn't impose any format on the text following the timestamp.

extended_timestamp​

@property
def extended_timestamp() -> bool

Whether the timestamp present in the entry header is extended (date and time).

sanitized_day_of_month_padding​

@property
def sanitized_day_of_month_padding() -> str

Padding of day of month in the entry header timestamp. Nonsensical padding (i.e. multiple spaces before double-digit day of month) is corrected.

style​

@property
def style() -> ChangelogStyle

Style of this changelog entry (standard vs openSUSE).

author​

@property
def author() -> Optional[str]

Author of the entry, usually including their email.

Parsing is best effort, see evr. The last word of an entry with neither an email nor an EVR is taken for an EVR.

timestamp​

@property
def timestamp() -> Optional[Union[datetime.datetime, datetime.date]]

Timestamp of the entry, date for the basic format ("Tue May 4 2021"), timezone-aware datetime for the extended one ("Mon Oct 18 12:34:45 CET 2021"). None if it can't be parsed.

Timezones are resolved similarly to RPM:

  • names missing in the system timezone database (e.g. "CEST" or "+03") mean UTC
  • DST is never applied
  • CET is UTC+1 even in summer

Unlike RPM, POSIX TZ strings (e.g. "UTC+2") are not supported and mean UTC as well.

Without zoneinfo (Python < 3.9) only "UTC" and "GMT" are resolved!

assemble​

@classmethod
def assemble(
cls,
timestamp: Union[datetime.date, datetime.datetime],
author: str,
content: List[str],
evr: Optional[str] = None,
day_of_month_padding: str = "0",
append_newline: bool = True,
style: ChangelogStyle = ChangelogStyle.standard) -> "ChangelogEntry"

Assembles a changelog entry.

Arguments:

  • timestamp - Timestamp of the entry. Supply datetime rather than date for extended format. openSUSE-style changelog entries mandate extended format, so if a date is supplied, the timestamp will be set to noon of that day.
  • author - Author of the entry.
  • content - List of lines forming the content of the entry.
  • evr - EVR (epoch, version, release) of the entry. Ignored if style is ChangelogStyle.openSUSE.
  • day_of_month_padding - Padding to apply to day of month in the timestamp.
  • datetime0 - Whether the entry should be followed by an empty line.
  • style - Which style of changelog should be created.

Returns:

New instance of datetime2 class.

Changelog​

class Changelog(UserList[ChangelogEntry])

Class that represents a changelog. It behaves like a list of changelog entries, ordered from bottom to top - the top (newest) entry has index -1, the bottom (oldest) one has index 0.

Attributes:

  • data - List of individual entries.

__init__​

def __init__(data: Optional[List[ChangelogEntry]] = None,
predecessor: Optional[List[str]] = None) -> None

Initializes a changelog object.

Arguments:

  • data - List of individual changelog entries.
  • predecessor - List of lines at the beginning of a section that can't be parsed into changelog entries.

filter​

def filter(since: Optional[Union[str, EVR]] = None,
until: Optional[Union[str, EVR]] = None) -> "Changelog"

Filters changelog entries with EVR between since and until.

Arguments:

  • since - Optional lower bound. If specified, entries with EVR higher than or equal to this will be included.
  • until - Optional upper bound. If specified, entries with EVR lower than or equal to this will be included.

Returns:

Filtered changelog.

parse​

@classmethod
def parse(cls, section: Section) -> "Changelog"

Parses a %changelog section.

Arguments:

  • section - Section to parse.

Returns:

New instance of Changelog class.

get_raw_section_data​

def get_raw_section_data() -> List[str]

Reconstructs section data from changelog.

Returns:

List of lines forming the reconstructed section data.

guess_packager​

def guess_packager() -> str

Guesses the name and e-mail of a packager to use for changelog entries. This function uses logic similar to rpmdev-packager utility.

The following places are searched for this value (in this order):

  • $RPM_PACKAGER environment variable
  • %packager macro
  • git config
  • Unix username

Returns:

A string to use for the changelog entry author. If nothing was detected, an empty string is returned.