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.PatchObject(path, number, 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')[source]

Class representing a spec file.


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
download_remote_sources() → None[source]

Downloads sources specified as URL.

expand(s: str, default: str = '') → str[source]
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
classmethod get_comment_span(line: str, script_section: bool) → Tuple[int, int][source]

Gets span of a comment depending on the section.

  • line – Line to find the comment in.
  • script_section – Whether the section the line is in is a shell script.

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.


Finds the exact name of the main %files section.

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

Method returns list of all unpplied patches.

Returns:list of PatchObject
get_other_sources() → List[str][source]

Method returns list of all applied and not applied patches

Returns:list of PatchObject

Function returns whole prep section

get_raw_main_source() → str[source]
get_release() → str[source]

Returns release string without %dist


Get dirname from %setup or %autosetup macro arguments

get_sources() → List[str][source]
static get_subpackage_name(files_section)[source]

Gets subpackage name based on the %files section.


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_release(release: str, preserve_macros: bool = True) → None[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.

substitute_path_with_macros(path: str, condition: Optional[Callable] = None)[source]

Substitutes parts of a path with macros.

  • path – Path to be changed.
  • condition – Condition determining if that particular active macro is a suitable substitution.

Path expressed using macros.

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.