specfile.sections
Section
class Section(collections.UserList)
Class that represents a spec file section.
Attributes:
name
- Name of the section (without the leading '%').options
- Options of the section.data
- List of lines forming the content of the section, not including newline characters.
__init__
def __init__(name: str,
options: Optional[Options] = None,
delimiter: str = "",
separator: str = "\n",
data: Optional[List[str]] = None) -> None
Initializes a section object.
Arguments:
name
- Name of the section (without the leading '%').options
- Options of the section.delimiter
- Delimiter separating name and option string.separator
- String separating name and options from section content, defaults to newline.data
- List of lines forming the content of the section, not including newline characters.
normalized_name
@property
def normalized_name() -> str
Normalized name of the section. All characters are lowercased.
id
@property
def id() -> str
ID of the section (name and options, without the leading '%').
normalized_id
@property
def normalized_id() -> str
Normalized ID of the section. All characters of name are lowercased.
is_script
@property
def is_script() -> bool
Whether the content of the section is a shell script.
Sections
class Sections(UserList[Section])
Class that represents all spec file sections, hence the entire spec file.
Sections can be accessed by index or conveniently by id as attributes:
# print the third line of the first section
print(sections[0][2])
# remove the last line of %prep section
del sections.prep[-1]
# replace the entire %prep section
sections.prep = ['line 1', 'line 2']
# delete %changelog
del sections.changelog
Attributes:
data
- List of individual sections. Preamble is expected to always be the first.
parse
@classmethod
def parse(cls,
lines: List[str],
context: Optional["Specfile"] = None) -> "Sections"
Parses given lines into sections.
Arguments:
lines
- Lines to parse.context
-Specfile
instance that defines the context for macro expansions.
Returns:
New instance of Sections
class.