aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2018-11-23 17:37:42 +0100
committerGuido Günther <agx@sigxcpu.org>2018-11-23 17:37:42 +0100
commit90f0c8c8db6f16e2586c2739091b85031e395ce5 (patch)
tree564b4e823b3601df69e3de699a24e72faa913e5b
parente5aedb16548a6a83223862b96ba2112e0c02c126 (diff)
Deduplicate version_mangle_re
-rw-r--r--gbp/deb/git.py5
-rw-r--r--gbp/pkg/pkgpolicy.py16
2 files changed, 9 insertions, 12 deletions
diff --git a/gbp/deb/git.py b/gbp/deb/git.py
index 85c9da5..12ad34d 100644
--- a/gbp/deb/git.py
+++ b/gbp/deb/git.py
@@ -32,10 +32,7 @@ import gbp.log
class DebianGitRepository(PkgGitRepository):
"""A git repository that holds the source of a Debian package"""
- version_mangle_re = (r'%\(version'
- r'%(?P<M>[^%])'
- r'%(?P<R>([^%]|\\%))+'
- r'\)s')
+ version_mangle_re = PkgPolicy.version_mangle_re
def __init__(self, *args, **kwargs):
super(DebianGitRepository, self).__init__(*args, **kwargs)
diff --git a/gbp/pkg/pkgpolicy.py b/gbp/pkg/pkgpolicy.py
index b525ce2..a81c9ec 100644
--- a/gbp/pkg/pkgpolicy.py
+++ b/gbp/pkg/pkgpolicy.py
@@ -27,6 +27,10 @@ class PkgPolicy(object):
"""
Common helpers for packaging policy.
"""
+ version_mangle_re = (r'%\(version'
+ r'%(?P<M>[^%])'
+ r'%(?P<R>([^%]|\\%))+'
+ r'\)s')
packagename_re = None
packagename_msg = None
upstreamversion_re = None
@@ -167,8 +171,8 @@ class PkgPolicy(object):
def symlink_orig(cls, orig_file, orig_dir, output_dir, force=False):
return cls.symlink_origs([orig_file], orig_dir, output_dir, force=force)
- @staticmethod
- def version_subst(format, version, sanitizer=lambda arg: arg):
+ @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.
@@ -193,13 +197,9 @@ class PkgPolicy(object):
>>> PkgPolicy.version_subst(r'%(version%-%\\%)s', "0-1.2.3")
'0%1.2.3'
"""
- version_mangle_re = (r'%\(version'
- r'%(?P<M>[^%])'
- r'%(?P<R>([^%]|\\%))+'
- r'\)s')
- r = re.search(version_mangle_re, format)
+ r = re.search(cls.version_mangle_re, format)
if r:
- format = re.sub(version_mangle_re, "%(version)s", format)
+ format = re.sub(cls.version_mangle_re, "%(version)s", format)
version = version.replace(r.group('M'), r.group('R').replace(r'\%', '%'))
return format_str(format, dict(version=sanitizer(version),
hversion=sanitizer(version).replace('.', '-')))