Specfile module

class rebasehelper.specfile.PackageCategory(value)[source]

An enumeration.

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

Class represents set of information about patches

get_patch_name()[source]
class rebasehelper.specfile.SpecFile(path: str, sources_location: str = '', predefined_macros: Dict[str, str] | None = None, lookaside_cache_preset: str = 'fedpkg')[source]

Class representing a spec file.

copy(new_path)[source]

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.

Parameters:
  • archive_path – Path to the main sources archive.

  • main_source – Value of Source0 tag.

Returns:

Extracted version string.

Raises:

RebaseHelperError in case version can't be determined.

find_archive_target_in_prep(archive)[source]

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]
get_applied_patches()[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.

Parameters:
  • line – Line to find the comment in.

  • script_section – Whether the section the line is in is a shell script.

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.

get_main_files_section()[source]

Finds the exact name of the main %files section.

Returns:

Name of the main files section.

Return type:

str

get_main_source() str[source]
get_not_used_patches()[source]

Method returns list of all unpplied patches.

Returns:

list of PatchObject

get_other_sources() List[str][source]
get_patches()[source]

Method returns list of all applied and not applied patches

Returns:

list of PatchObject

get_prep_section()[source]

Function returns whole prep section

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

Returns release string without %dist

get_setup_dirname()[source]

Get dirname from %setup or %autosetup macro arguments

Returns:

dirname

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

Gets subpackage name based on the %files section.

is_test_suite_enabled()[source]

Returns whether test suite is enabled during the build time

Returns:

True if enabled or False if not

parse_release() Tuple[bool, int, str | None][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: List[int] | None = None, remove: List[int] | None = None, annotate: List[int] | None = None, note: str | None = None) None[source]

Processes %patch macros in %prep section.

Parameters:
  • 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.

reload()[source]

Reloads the whole Spec file.

save() None[source]

Saves changes made to SpecContent and updates the internal state.

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

Updates SPEC file with the specified extra version.

Parameters:
  • 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, str | None][source]

Splits version string into version and extra version.

Parameters:
  • version_string – Complete version string.

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

Returns:

Tuple of version and extra_version.

Raises:

RebaseHelperError in case passed version string is not valid.

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

Substitutes parts of a path with macros.

Parameters:
  • path – Path to be changed.

  • condition – Condition determining if that particular active macro is a suitable substitution.

Returns:

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

Parameters:
  • dir_name

  • name

Returns:

full path to results dir with name

rebasehelper.specfile.saves(func)[source]

Decorator for saving the SpecFile after a method is run.