gbp.pkg.pkgpolicy.PkgPolicy(object) class documentationgbp.pkg.pkgpolicy
(View In Hierarchy)
Known subclasses: gbp.deb.policy.DebianPkgPolicy, gbp.rpm.policy.RpmPkgPolicy
Common helpers for packaging policy.
| 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. |
Is this a valid package name?
>>> PkgPolicy.is_valid_packagename('doesnotmatter')
Traceback (most recent call last):
...
NotImplementedError: Class needs to provide packagename_re
Is this a valid upstream version number?
>>> PkgPolicy.is_valid_upstreamversion('doesnotmatter')
Traceback (most recent call last):
...
NotImplementedError: Class needs to provide upstreamversion_re
Guess the package name and version from the filename of an upstream
archive.
@param filename: filename (archive or directory) from which to guess
@type filename: C{string}
@param extra_regex: additional regex to apply, needs a 'package' and a
'version' group
@return: (package name, version) or ('', '')
@rtype: 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')
Check orig tarball and additional tarballs exists in dir
symlink orig tarball from orig_dir to output_dir
@return: [] if all links were created, list of
failed links otherwise
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'