Spec content module

class rebasehelper.spec_content.SpecContent(content: str)[source]

Class representing content of a SPEC file.

DISALLOW_INLINE_COMMENTS = ['%package', '%patchlist', '%sourcelist', '%description', '%files', '%changelog']
SECTION_HEADERS = ['%package', '%prep', '%generate_build_requires', '%build', '%install', '%check', '%clean', '%prerun', '%postrun', '%pretrans', '%posttrans', '%pre', '%post', '%files', '%changelog', '%description', '%triggerpostun', '%triggerprein', '%triggerun', '%triggerin', '%trigger', '%verifyscript', '%sepolicy', '%filetriggerin', '%filetrigger', '%filetriggerun', '%filetriggerpostun', '%transfiletriggerin', '%transfiletrigger', '%transfiletriggerun', '%transfiletriggerpostun', '%end', '%patchlist', '%sourcelist']
classmethod get_comment_span(line: str, section: str) → Tuple[int, int][source]

Gets span of a comment depending on the section.

Parameters:
  • line – Line to find the comment in.
  • section – Section the line is in.
Returns:

Span of the comment. If no comment is found, both tuple elements are equal to the length of the line for convenient use in a slice.

replace_section(name: str, content: List[str]) → bool[source]

Replaces content of a section.

In case there are multiple sections with the same name, the first one is replaced.

Parameters:
  • name – Section name.
  • content – Section content as a list of lines.
Returns:

False if section was not found else True.

section(name: str) → Optional[List[str]][source]

Gets content of a section.

In case there are multiple sections with the same name, the first one is returned.

Parameters:name – Section name.
Returns:Section content as a list of lines.