Specfile module

class rebasehelper.specfile.BaseSpecHook[source]

Base class for a spec hook

classmethod get_categories()[source]

Returns list of categories of a spec hook

classmethod get_name()[source]

Returns the name of a spec hook

classmethod run(spec_file, rebase_spec_file, **kwargs)[source]

Runs a spec hook.

Parameters:
  • spec_file – Original spec file object
  • rebase_spec_file – Rebased spec file object
  • kwargs – Keyword arguments from Application instance
class rebasehelper.specfile.PatchList[source]
class rebasehelper.specfile.PatchObject(path, index, option)[source]

Class represents set of information about patches

get_index()[source]
get_option()[source]
get_patch_name()[source]
get_path()[source]
git_generated = ''
index = ''
option = ''
path = ''
set_path(new_path)[source]
class rebasehelper.specfile.SpecFile(path, changelog_entry, sources_location='', download=True)[source]

Class representing a SPEC file

category = None
static construct_string_with_comment(lines)[source]

Wraps the line in a rebase-helper specific comments

Parameters:lines – line (or list of lines) to be wrapped
Returns:list with lines
copy(new_path=None)[source]

Create a copy of the current object and copy the SPEC file the new object represents to a new location.

Parameters:new_path – new path to which to copy the SPEC file
Returns:copy of the current object
defined_sections = ['%package', '%description', '%prep', '%build', '%install', '%check', '%files', '%changelog']
download = False
download_remote_sources()[source]

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

Returns:None
extra_version = None
static extract_version_from_archive_name(archive_path, source_string='')[source]

Method extracts the version from archive name based on the source string from SPEC file. It extracts also an extra version such as ‘b1’, ‘rc1’, …

Parameters:
  • archive_path – archive name or path with archive name from which to extract the version
  • source_string – Source string from SPEC file used to construct version extraction regex
Returns:

tuple of strings with (extracted version, extra version) or (None, None) if extraction failed

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

Method for getting epoch of the package

Returns:
get_extra_version()[source]

Returns an extra version of the package - like b1, rc2, …

Returns:String
get_extra_version_separator()[source]

Returns the separator between version and extra version as used by upstream. If there is not separator or extra version, it returns an empty string.

Returns:String with the separator between version as extra version as used by upstream.
Return type:str
get_full_version()[source]

Returns the full version string, which is a combination of version, separator and extra version.

Returns:String with full version, including the extra version part.
Return type:str
get_new_log()[source]
get_not_used_patches()[source]

Method returns list of all unpplied patches.

Returns:list of PatchObject
get_package_name()[source]

Function returns a package name

Returns:
get_patch_option(line)[source]

Function returns a patch options

Parameters:line
Returns:patch options like -p1
get_patches()[source]

Method returns list of all applied and not applied patches

Returns:list of PatchObject
get_path()[source]

Return only spec file path

Returns:
static get_paths_with_rpm_macros(files)[source]

Method modifies paths in passed list to use RPM macros

Parameters:files – list of absolute paths
Returns:modified list of paths with RPM macros
get_prep_section(complete=False)[source]

Function returns whole prep section

get_release()[source]

Method for getting full release string of the package

Returns:
get_release_number()[source]

Method for getting the release of the package

Returns:
get_requires()[source]

Function returns a package requirements

Returns:
get_setup_dirname()[source]

Get dirname from %setup or %autosetup macro arguments

Returns:dirname
get_sources()[source]

Method returns dictionary with local sources list.

Returns:list of Sources with absolute path
Return type:list of str
get_spec_section(section_name)[source]

Returns the section of selected name

Parameters:section_name – section name to get
Returns:list of lines contained in the selected section
get_version()[source]

Method returns the version

Returns:
hdr = None
insert_changelog(new_log)[source]
is_test_suite_enabled()[source]

Returns whether test suite is enabled during the build time

Returns:True if enabled or False if not
modify_spec_files_section(files)[source]

Function repairs spec file according to new sources.

Parameters:files
Returns:
patches = None
path = ''
prep_section = []
redefine_release_with_macro(macro)[source]

Method redefines the Release: line to include passed macro and comments out the old line

Parameters:macro
Returns:
removed_patches = []
revert_redefine_release_with_macro(macro)[source]

Method removes the redefined the Release: line with given macro and uncomments the old Release line.

Parameters:macro
Returns:
rpm_sections = {}
save()[source]

Save changes made to the spec_content to the disc and update internal variables

set_extra_version(extra_version)[source]

Method to update the extra version in the SPEC file. Redefined Source0 if needed and also changes Release accordingly.

Parameters:extra_version – the extra version string, if any (e.g. ‘b1’, ‘rc2’, …)
Returns:None
set_extra_version_separator(separator)[source]

Set the string that separates the version and extra version

Parameters:separator
Returns:
set_release_number(release)[source]

Method to set release number

Parameters:release
Returns:
set_spec_section(section_name, new_section)[source]

Returns the section of selected name

Parameters:section_name – section name to get
Returns:list of lines contained in the selected section
set_tag(tag, value, preserve_macros=False)[source]

Sets value of a tag while trying to preserve macros if requested

set_version(version)[source]

Method to update the version in the SPEC file

Parameters:version – string with new version
Returns:None
set_version_using_archive(archive_path)[source]

Method to update the version in the SPEC file using a archive path. The version is extracted from the archive name.

Parameters:archive_path
Returns:
sources = None
spc = None
spec_content = []
static split_version_string(version_string='')[source]

Method splits version string into version and possibly extra string as ‘rc1’ or ‘b1’, …

Parameters:version_string – version string such as ‘1.1.1’ or ‘1.2.3b1’, …
Returns:tuple of strings with (extracted version, extra version, separator) or (None, None, None) if extraction failed
update_changelog(new_log)[source]

Function updates changelog with new version

update_paths_to_patches()[source]
update_setup_dirname(dirname)[source]

Update %setup or %autosetup dirname argument if needed

Parameters:dirname – new dirname to be used
write_updated_patches(patches, disable_inapplicable)[source]

Function writes the patches to -rebase.spec file

class rebasehelper.specfile.SpecHooksRunner[source]

Class representing the process of running various spec file hooks.

get_available_spec_hooks()[source]

Returns a list of all available spec hooks

run_spec_hooks(spec_file, rebase_spec_file, **kwargs)[source]

Runs all spec hooks.

Parameters:
  • spec_file – Original spec file object
  • rebase_spec_file – Rebased spec file object
  • kwargs – Keyword arguments from Application instance
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