diff options
author | Guido Günther <agx@sigxcpu.org> | 2009-06-09 17:35:34 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2009-06-11 18:22:04 +0200 |
commit | 55a89e1050a524cfa7559c62e879eb01993fddc8 (patch) | |
tree | 8fb498a8b1dc996071f170475343f9aa0f09ce63 | |
parent | b577f01f365d3d529ee3a823e084b1398a2bd08a (diff) | |
download | git-buildpackage-55a89e1050a524cfa7559c62e879eb01993fddc8.tar.gz git-buildpackage-55a89e1050a524cfa7559c62e879eb01993fddc8.tar.bz2 git-buildpackage-55a89e1050a524cfa7559c62e879eb01993fddc8.zip |
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
-rw-r--r-- | gbp/deb_utils.py | 37 | ||||
-rwxr-xr-x | git-import-orig | 22 |
2 files changed, 38 insertions, 21 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() diff --git a/git-import-orig b/git-import-orig index e2529f68..acb012ce 100755 --- a/git-import-orig +++ b/git-import-orig @@ -27,7 +27,7 @@ import subprocess import tarfile import time import gbp.command_wrappers as gbpc -from gbp.deb_utils import parse_changelog, unpack_orig, NoChangelogError, has_epoch, tar_toplevel +from gbp.deb_utils import parse_changelog, unpack_orig, NoChangelogError, has_epoch, tar_toplevel, guess_upstream_version from gbp.git_utils import (GitRepositoryError, GitRepository, build_tag) from gbp.config import GbpOptionParser from gbp.errors import (GbpError, GbpNothingImported) @@ -196,24 +196,6 @@ def fast_import_upstream_tree(repo, tarball, version, options): print "FastImport done." -def guess_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 - """ - version_filters = [ # Debian package_<version>.orig.tar.gz: - r'^[a-z\d\.\+\-]+_(?P<version>[a-z\d\.\~\-]+)\.orig\.tar\.(gz|bz2)', - # Upstream package-<version>.tar.gz: - r'^[a-z\d\.\+\-]+-(?P<version>[a-z\d\.]+)\.tar\.(gz|bz2)' ] - 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 turn_off_fastimport(options, msg): if options.fast_import: print >>sys.stderr, msg @@ -285,7 +267,7 @@ on howto create it otherwise use --upstream-branch to specify it. if options.version: version = options.version else: - version = guess_version(archive) + version = guess_upstream_version(archive) if version: print "Upstream version is %s" % version |