summaryrefslogtreecommitdiff
path: root/gbp/pkg/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'gbp/pkg/__init__.py')
-rw-r--r--gbp/pkg/__init__.py77
1 files changed, 63 insertions, 14 deletions
diff --git a/gbp/pkg/__init__.py b/gbp/pkg/__init__.py
index 7769fbe0..83389297 100644
--- a/gbp/pkg/__init__.py
+++ b/gbp/pkg/__init__.py
@@ -139,6 +139,67 @@ class PkgPolicy(object):
return True
return False
+ @classmethod
+ def guess_upstream_src_version(cls, filename, extra_regex=r''):
+ """
+ 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')
+ ('foo-Bar', '0.2.orig')
+ >>> 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.tar.gz')
+ ('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')
+ """
+ version_chars = r'[a-zA-Z\d\.\~\-\:\+]'
+ basename = parse_archive_filename(os.path.basename(filename))[0]
+
+ version_filters = map ( lambda x: x % version_chars,
+ ( # Debian upstream tarball: package_'<version>.orig.tar.gz'
+ r'^(?P<package>[a-z\d\.\+\-]+)_(?P<version>%s+)\.orig',
+ # Upstream 'package-<version>.tar.gz'
+ # or Debian native 'package_<version>.tar.gz'
+ # or directory 'package-<version>':
+ r'^(?P<package>[a-zA-Z\d\.\+\-]+)(-|_)(?P<version>[0-9]%s*)'))
+ if extra_regex:
+ version_filters = extra_regex + version_filters
+
+ for filter in version_filters:
+ m = re.match(filter, basename)
+ if m:
+ return (m.group('package'), m.group('version'))
+ return ('', '')
+
@staticmethod
def guess_upstream_src_version(filename, extra_regex=r''):
"""
@@ -309,24 +370,12 @@ class UpstreamSource(object):
@property
def archive_fmt(self):
- """
- >>> UpstreamSource('foo/bar.tar.gz').archive_fmt
- 'tar'
- >>> UpstreamSource('foo.bar.zip').archive_fmt
- 'zip'
- >>> UpstreamSource('foo.bar.baz').archive_fmt
- """
+ """Archive format of the sources, e.g. 'tar'"""
return self._archive_fmt
@property
def compression(self):
- """
- >>> UpstreamSource('foo/bar.tar.gz').compression
- 'gzip'
- >>> UpstreamSource('foo.bar.zip').compression
- >>> UpstreamSource('foo.bz2').compression
- 'bzip2'
- """
+ """Compression format of the sources, e.g. 'gzip'"""
return self._compression
def unpack(self, dir, filters=[]):