aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2009-06-09 17:35:34 +0200
committerGuido Günther <agx@sigxcpu.org>2009-06-11 18:22:04 +0200
commit55a89e1050a524cfa7559c62e879eb01993fddc8 (patch)
tree8fb498a8b1dc996071f170475343f9aa0f09ce63 /gbp
parentb577f01f365d3d529ee3a823e084b1398a2bd08a (diff)
allow for uppercase characters in the version pattern
and in the package name if it's not a debian source package's name. Also allow for ':' and '~' which are allowed accoring to Debian Policy. Based on a patch by Felipe Sateler. Closes: #531819
Diffstat (limited to 'gbp')
-rw-r--r--gbp/deb_utils.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/gbp/deb_utils.py b/gbp/deb_utils.py
index 28794596..f20033a0 100644
--- a/gbp/deb_utils.py
+++ b/gbp/deb_utils.py
@@ -26,7 +26,6 @@ class ParseChangeLogError(Exception):
"""problem parsing changelog"""
pass
-
class DscFile(object):
"""Keeps all needed data read from a dscfile"""
pkg_re = re.compile('Source:\s+(?P<pkg>.+)\s*')
@@ -216,6 +215,42 @@ def get_arch():
return arch
+def guess_upstream_version(archive, version_regex=r''):
+ """
+ guess the version from the filename of an upstgream archive
+ @archive: filename to guess to version for
+ @version_regex: additional version regex to apply, needs a 'version' group
+
+ >>> guess_upstream_version('foo-bar_0.2.orig.tar.gz')
+ '0.2'
+ >>> guess_upstream_version('foo-Bar_0.2.orig.tar.gz')
+ >>> guess_upstream_version('git-bar-0.2.tar.gz')
+ '0.2'
+ >>> guess_upstream_version('git-bar-0.2-rc1.tar.gz')
+ '0.2-rc1'
+ >>> guess_upstream_version('git-bar-0.2:~-rc1.tar.gz')
+ '0.2:~-rc1'
+ >>> guess_upstream_version('git-Bar-0A2d:rc1.tar.bz2')
+ '0A2d:rc1'
+ >>> guess_upstream_version('foo-Bar_0.2.orig.tar.gz')
+ >>> guess_upstream_version('foo-Bar-a.b.tar.gz')
+ """
+ version_chars = r'[a-zA-Z\d\.\~\-\:]'
+ extensions = r'\.tar\.(gz|bz2)'
+
+ version_filters = map ( lambda x: x % (version_chars, extensions),
+ ( # Debian package_<version>.orig.tar.gz:
+ r'^[a-z\d\.\+\-]+_(?P<version>%s+)\.orig%s',
+ # Upstream package-<version>.tar.gz:
+ r'^[a-zA-Z\d\.\+\-]+-(?P<version>[0-9]%s+)%s'))
+ if version_regex:
+ version_filters = version_regex + version_filters
+ for filter in version_filters:
+ m = re.match(filter, os.path.basename(archive))
+ if m:
+ return m.group('version')
+
+
def _test():
import doctest
doctest.testmod()