Specfile module

class rebasehelper.specfile.PackageCategory[source]

An enumeration.

R = re.compile('^R-')
haskell = re.compile('^ghc-')
nodejs = re.compile('^nodejs-')
perl = re.compile('^perl-')
php = re.compile('^php-')
python = re.compile('^python[23]?-')
ruby = re.compile('^rubygem-')
rust = re.compile('^rust-')
class rebasehelper.specfile.PatchList[source]
class rebasehelper.specfile.PatchObject(path, index, strip)[source]

Class represents set of information about patches

class rebasehelper.specfile.SpecFile(path: str, sources_location: str = '', predefined_macros: Optional[Dict[str, str]] = None, lookaside_cache_preset: str = 'fedpkg', keep_comments: bool = False)[source]

Class representing a SPEC file. Be aware that using SpecFile modifies RPM macros in global context.


Creates a copy of the current object and copies the SPEC file to a new location.

Parameters:new_path (str) – Path to copy the new SPEC file to.
Returns:The created SpecFile instance.
Return type:SpecFile

Method that iterates over all sources and downloads ones, which contain URL instead of just a file.

static extract_version_from_archive_name(archive_path: str, main_source: str) → str[source]

Extracts version string from source archive name.

  • archive_path – Path to the main sources archive.
  • main_source – Value of Source0 tag.

Extracted version string.


RebaseHelperError in case version can’t be determined.


Tries to find a command that is used to extract the specified archive and attempts to determine target path from it. ‘tar’ and ‘unzip’ commands are supported so far.

Parameters:archive – Path to archive
Returns:Target path relative to builddir or None if not determined
get_NVR() → str[source]

Method returns list of all applied patches.

Returns:list of PatchObject

Method returns the basename of first Source in SPEC file a.k.a. Source0

Returns:basename of first Source in SPEC file
Return type:str

Finds the exact name of the main %files section.

Returns:Name of the main files section.
Return type:str
get_main_source() → str[source]

Provide the main source, returns empty string if there are no sources


Constructs a new changelog entry.

Parameters:changelog_entry (str) – Message to use in the entry.
Returns:List of lines of the new entry.
Return type:list

Method returns list of all unpplied patches.

Returns:list of PatchObject

Method returns list of all applied and not applied patches

Returns:list of PatchObject

Function returns whole prep section

get_raw_tag_value(tag_name: str, section: Union[str, int, None] = None) → Optional[str][source]
get_release() → str[source]

Returns release string without %dist


Get dirname from %setup or %autosetup macro arguments

get_sources() → List[str][source]

Gets a list of local sources.

static get_subpackage_name(files_section)[source]

Gets subpackage name based on the %files section.

get_version() → str[source]

Returns whether test suite is enabled during the build time

Returns:True if enabled or False if not
parse_release() → Tuple[bool, int, Optional[str]][source]

Parses release string.

Returns:Tuple of is_prerelease, release_number and extra_version.
Raises:RebaseHelperError in case release string is not valid.
process_patch_macros(comment_out: Optional[List[int]] = None, remove: Optional[List[int]] = None, annotate: Optional[List[int]] = None, note: Optional[str] = None) → None[source]

Processes %patch macros in %prep section.

  • comment_out – List of patch numbers to comment out.
  • remove – List of patch numbers to remove.
  • annotate – List of patch numbers to annotate.
  • note – Message to annotate patches with.

Reloads the whole Spec file.

save() → None[source]

Saves changes made to SpecContent and updates the internal state.

set_extra_version(extra_version: Optional[str], version_changed: bool) → None[source]

Updates SPEC file with the specified extra version.

  • extra_version – Extra version string or None.
  • version_changed – Whether version (the value of Version tag) changed.
set_raw_tag_value(tag_name: str, value: str, section: Union[str, int, None] = None) → None[source]
set_release(release: str, preserve_macros: bool = True) → None[source]
set_release_number(release: str) → None[source]
set_tag(*args, **kwargs)[source]
set_version(version: str, preserve_macros: bool = True) → None[source]
static split_version_string(version_string: str, current_version: str) → Tuple[str, Optional[str]][source]

Splits version string into version and extra version.

  • version_string – Complete version string.
  • current_version – Current version (the value of Version tag).

Tuple of version and extra_version.


RebaseHelperError in case passed version string is not valid.

tag(name: str, section: Union[str, int, None] = None) → Optional[rebasehelper.tags.Tag][source]

Returns the first non-unique tag.

update() → None[source]
update_changelog(*args, **kwargs)[source]
update_paths_to_sources_and_patches(*args, **kwargs)[source]
update_setup_dirname(*args, **kwargs)[source]
write_updated_patches(*args, **kwargs)[source]
rebasehelper.specfile.get_rebase_name(dir_name, name)[source]

Function returns a name in results directory

  • dir_name
  • name

full path to results dir with name


Decorator for saving the SpecFile after a method is run.