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

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

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

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

Returns:None
static 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
get_archive()[source]

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
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]

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

get_new_log(changelog_entry)[source]

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
get_not_used_patches()[source]

Method returns list of all unpplied patches.

Returns:list of PatchObject
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_tag_value(tag_name: str, section: Union[str, int, None] = None) → Optional[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]

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]
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, 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.

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: Optional[str], 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_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.

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.

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

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.