# `gbp.pkg.pkgpolicy.PkgPolicy(object)` class documentation

Part of `gbp.pkg.pkgpolicy` (View In Hierarchy)

Known subclasses: gbp.deb.policy.DebianPkgPolicy, gbp.rpm.policy.RpmPkgPolicy

Common helpers for packaging policy.

Class Variable | version_mangle_re | Undocumented
Class Variable | packagename_re | Undocumented
Class Variable | packagename_msg | Undocumented
Class Variable | upstreamversion_re | Undocumented
Class Variable | upstreamversion_msg | Undocumented
Class Method | is_valid_packagename | Is this a valid package name?
Class Method | is_valid_upstreamversion | Is this a valid upstream version number?
Static Method | guess_upstream_src_version | Guess the package name and version from the filename of an upstream archive.
Static Method | has_origs | Check orig tarball and additional tarballs exists in dir
Class Method | has_orig | Undocumented
Static Method | symlink_origs | symlink orig tarball from orig_dir to output_dir @return: [] if all links were created, list of failed links otherwise
Class Method | symlink_orig | Undocumented
Class Method | version_subst | Generate a string from a given format and a version. The extracted version can be passed through the sanitizer function argument before being formatted into a string.

version_mangle_re =
Undocumented
(type: `str`)
packagename_re =
Undocumented
packagename_msg =
Undocumented
upstreamversion_re =
Undocumented
upstreamversion_msg =
Undocumented
@classmethod
def is_valid_packagename(cls, name):

Is this a valid package name?

    >>> PkgPolicy.is_valid_packagename('doesnotmatter')
    Traceback (most recent call last):
    ...
    NotImplementedError: Class needs to provide packagename_re

@classmethod
def is_valid_upstreamversion(cls, version):

Is this a valid upstream version number?

    >>> PkgPolicy.is_valid_upstreamversion('doesnotmatter')
    Traceback (most recent call last):
    ...
    NotImplementedError: Class needs to provide upstreamversion_re

@staticmethod
def guess_upstream_src_version(filename, extra_regex=""""""):

Guess the package name and version from the filename of an upstream archive.

Parameters | filename | filename (archive or directory) from which to guess (type: `string`)
| extra_regex | additional regex to apply, needs a 'package' and a 'version' group

Returns

(package name, version) or ('', '') (type: tuple

    >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.orig.tar.gz')
    ('foo-bar', '0.2')
    >>> PkgPolicy.guess_upstream_src_version('foo-Bar_0.2.orig.tar.gz')
    ('', '')
    >>> PkgPolicy.guess_upstream_src_version('git-bar-0.2.tar.gz')
    ('git-bar', '0.2')
    >>> PkgPolicy.guess_upstream_src_version('git-bar-0.2-rc1.tar.gz')
    ('git-bar', '0.2-rc1')
    >>> PkgPolicy.guess_upstream_src_version('git-bar-0.2:~-rc1.tar.gz')
    ('git-bar', '0.2:~-rc1')
    >>> PkgPolicy.guess_upstream_src_version('git-Bar-0A2d:rc1.tar.bz2')
    ('git-Bar', '0A2d:rc1')
    >>> PkgPolicy.guess_upstream_src_version('git-1.tar.bz2')
    ('git', '1')
    >>> PkgPolicy.guess_upstream_src_version('kvm_87+dfsg.orig.tar.gz')
    ('kvm', '87+dfsg')
    >>> PkgPolicy.guess_upstream_src_version('foo-Bar-a.b.tar.gz')
    ('', '')
    >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.orig.tar.xz')
    ('foo-bar', '0.2')
    >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.orig.tar.lzma')
    ('foo-bar', '0.2')
    >>> PkgPolicy.guess_upstream_src_version('foo-bar-0.2.zip')
    ('foo-bar', '0.2')
    >>> PkgPolicy.guess_upstream_src_version('foo-bar-0.2.tlz')
    ('foo-bar', '0.2')
    >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.tar.gz')
    ('foo-bar', '0.2')

)

@staticmethod
def has_origs(orig_files, dir):

Check orig tarball and additional tarballs exists in dir

@classmethod
def has_orig(cls, orig_file, dir):
Undocumented
@staticmethod
def symlink_origs(orig_files, orig_dir, output_dir, force=(False)):

symlink orig tarball from orig_dir to output_dir

Returns | [] if all links were created, list of failed links otherwise

@classmethod
def symlink_orig(cls, orig_file, orig_dir, output_dir, force=(False)):
Undocumented
@classmethod
def version_subst(cls, format, version, sanitizer=(lambda arg: arg)):

Generate a string from a given format and a version. The extracted version can be passed through the sanitizer function argument before being formatted into a string.

%(version)s provides a clean version.

%(hversion)s provides the same thing, but with '.' replaced with '-'. hversion is useful for upstreams with tagging policies that prohibit . characters.

%(version%A%B)s provides %(version)s with string 'A' replaced by 'B'. This way, simple version mangling is possible via substitution. Inside the substition string, '%' needs to be escaped. See the examples below.

    >>> PkgPolicy.version_subst("debian/%(version)s", "0:0~0")
    'debian/0:0~0'
    >>> PkgPolicy.version_subst("libfoo-%(hversion)s", "1.8.1")
    'libfoo-1-8-1'
    >>> PkgPolicy.version_subst("v%(version%.%_)s", "1.2.3")
    'v1_2_3'
    >>> PkgPolicy.version_subst(r'%(version%-%\%)s', "0-1.2.3")
    '0%1.2.3'