specfile.macros
Macro
class Macro(collections.abc.Hashable)
Class that represents a RPM macro.
Attributes:
name- Name of the macro.options- Options (parameters) of the macro.body- Macro body.level- Macro level (source).used- Indicates that the macro has been used (expanded).
Macros
class Macros()
dump
@classmethod
def dump(cls) -> List[Macro]
Dumps all macros defined in the global context.
This is not 100% accurate, since macros can be defined multiple times, but only the last definition is listed.
Returns:
List of Macro instances.
expand
@staticmethod
def expand(expression: str, safe: bool = True) -> str
Expands an expression in the global context.
Arguments:
expression- Expression to expand.safe- Whether to disable macro manipulation during expansion.
Returns:
Expanded expression.
Raises:
RPMException- If expansion error occurs.
remove
@classmethod
def remove(cls, macro: str) -> None
Removes all definitions of a macro in the global context.
Arguments:
macro- Macro name.
Raises:
MacroRemovalException- If there were too many unsuccessful retries to remove the macro.
define
@classmethod
def define(cls, macro: str, body: str) -> None
Defines a macro in the global context.
Removes all existing definitions first. It is not possible to define a macro
with options. The new macro will always have MacroLevel.OLDSPEC level.
Arguments:
macro- Macro name.body- Macro body.
reinit
@classmethod
def reinit(cls, level_threshold: MacroLevel = MacroLevel.RPMRC) -> None
Reinitializes macros in the global context.
Arguments:
level_threshold- Only macros up to this level remain defined.