summaryrefslogtreecommitdiff
path: root/gbp/deb
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2013-03-29 15:35:55 +0100
committerGuido Günther <agx@sigxcpu.org>2013-03-29 15:36:38 +0100
commit733573511a77bd2fdbbff61b9bd62b40ad63eac2 (patch)
tree42efdb5ad2a6d96335425b00d1ca99c30a974cc1 /gbp/deb
parent62d3b9989919664fa81a317d8af320671a94803f (diff)
Move DscFile to separate module
Diffstat (limited to 'gbp/deb')
-rw-r--r--gbp/deb/__init__.py89
-rw-r--r--gbp/deb/dscfile.py113
-rw-r--r--gbp/deb/policy.py3
3 files changed, 118 insertions, 87 deletions
diff --git a/gbp/deb/__init__.py b/gbp/deb/__init__.py
index 3f0bfc3..6dd10a7 100644
--- a/gbp/deb/__init__.py
+++ b/gbp/deb/__init__.py
@@ -28,10 +28,7 @@ from gbp.pkg import UpstreamSource
# Make sure these are available with 'import gbp.deb'
from gbp.deb.changelog import ChangeLog, NoChangeLogError
from gbp.deb.policy import DebianPkgPolicy
-
-# When trying to parse a version-number from a dsc or changes file, these are
-# the valid characters.
-debian_version_chars = 'a-zA-Z\d.~+-'
+from gbp.deb.dscfile import DscFile
class DpkgCompareVersions(gbpc.Command):
cmd='/usr/bin/dpkg'
@@ -57,89 +54,6 @@ class DpkgCompareVersions(gbpc.Command):
return 0
-class DscFile(object):
- """Keeps all needed data read from a dscfile"""
- compressions = r"(%s)" % '|'.join(UpstreamSource.known_compressions())
- pkg_re = re.compile(r'Source:\s+(?P<pkg>.+)\s*')
- version_re = re.compile(r'Version:\s((?P<epoch>\d+)\:)?(?P<version>[%s]+)\s*$' % debian_version_chars)
- tar_re = re.compile(r'^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+(\.orig)?\.tar\.%s)' % compressions)
- diff_re = re.compile(r'^\s\w+\s\d+\s+(?P<diff>[^_]+_[^_]+\.diff.(gz|bz2))')
- deb_tgz_re = re.compile(r'^\s\w+\s\d+\s+(?P<deb_tgz>[^_]+_[^_]+\.debian.tar.%s)' % compressions)
- format_re = re.compile(r'Format:\s+(?P<format>[0-9.]+)\s*')
-
- def __init__(self, dscfile):
- self.pkg = ""
- self.tgz = ""
- self.diff = ""
- self.deb_tgz = ""
- self.pkgformat = "1.0"
- self.debian_version = ""
- self.upstream_version = ""
- self.native = False
- self.dscfile = os.path.abspath(dscfile)
-
- f = file(self.dscfile)
- fromdir = os.path.dirname(os.path.abspath(dscfile))
- for line in f:
- m = self.version_re.match(line)
- if m and not self.upstream_version:
- if '-' in m.group('version'):
- self.debian_version = m.group('version').split("-")[-1]
- self.upstream_version = "-".join(m.group('version').split("-")[0:-1])
- self.native = False
- else:
- self.native = True # Debian native package
- self.upstream_version = m.group('version')
- if m.group('epoch'):
- self.epoch = m.group('epoch')
- else:
- self.epoch = ""
- continue
- m = self.pkg_re.match(line)
- if m:
- self.pkg = m.group('pkg')
- continue
- m = self.deb_tgz_re.match(line)
- if m:
- self.deb_tgz = os.path.join(fromdir, m.group('deb_tgz'))
- continue
- m = self.tar_re.match(line)
- if m:
- self.tgz = os.path.join(fromdir, m.group('tar'))
- continue
- m = self.diff_re.match(line)
- if m:
- self.diff = os.path.join(fromdir, m.group('diff'))
- continue
- m = self.format_re.match(line)
- if m:
- self.pkgformat = m.group('format')
- continue
- f.close()
-
- if not self.pkg:
- raise GbpError("Cannot parse package name from '%s'" % self.dscfile)
- elif not self.tgz:
- raise GbpError("Cannot parse archive name from '%s'" % self.dscfile)
- if not self.upstream_version:
- raise GbpError("Cannot parse version number from '%s'" % self.dscfile)
- if not self.native and not self.debian_version:
- raise GbpError("Cannot parse Debian version number from '%s'" % self.dscfile)
-
- def _get_version(self):
- version = [ "", self.epoch + ":" ][len(self.epoch) > 0]
- if self.native:
- version += self.upstream_version
- else:
- version += "%s-%s" % (self.upstream_version, self.debian_version)
- return version
-
- version = property(_get_version)
-
- def __str__(self):
- return "<%s object %s>" % (self.__class__.__name__, self.dscfile)
-
-
def parse_dsc(dscfile):
"""parse dsc by creating a DscFile object"""
try:
@@ -149,6 +63,7 @@ def parse_dsc(dscfile):
return dsc
+
def parse_changelog_repo(repo, branch, filename):
"""
Parse the changelog file from given branch in the git
diff --git a/gbp/deb/dscfile.py b/gbp/deb/dscfile.py
new file mode 100644
index 0000000..6f450e2
--- /dev/null
+++ b/gbp/deb/dscfile.py
@@ -0,0 +1,113 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2006,2007,2011,2013 Guido Günther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""provides some debian source package related helpers"""
+
+import os
+import re
+
+from gbp.errors import GbpError
+from gbp.pkg import UpstreamSource
+from gbp.deb.policy import DebianPkgPolicy
+
+class DscFile(object):
+ """Keeps all needed data read from a dscfile"""
+ compressions = r"(%s)" % '|'.join(UpstreamSource.known_compressions())
+ pkg_re = re.compile(r'Source:\s+(?P<pkg>.+)\s*')
+ version_re = re.compile(r'Version:\s((?P<epoch>\d+)\:)?'
+ '(?P<version>[%s]+)\s*$'
+ % DebianPkgPolicy.debianversion_chars)
+ tar_re = re.compile(r'^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+'
+ '(\.orig)?\.tar\.%s)' % compressions)
+ diff_re = re.compile(r'^\s\w+\s\d+\s+(?P<diff>[^_]+_[^_]+'
+ '\.diff.(gz|bz2))')
+ deb_tgz_re = re.compile(r'^\s\w+\s\d+\s+(?P<deb_tgz>[^_]+_[^_]+'
+ '\.debian.tar.%s)' % compressions)
+ format_re = re.compile(r'Format:\s+(?P<format>[0-9.]+)\s*')
+
+ def __init__(self, dscfile):
+ self.pkg = ""
+ self.tgz = ""
+ self.diff = ""
+ self.deb_tgz = ""
+ self.pkgformat = "1.0"
+ self.debian_version = ""
+ self.upstream_version = ""
+ self.native = False
+ self.dscfile = os.path.abspath(dscfile)
+
+ f = file(self.dscfile)
+ fromdir = os.path.dirname(os.path.abspath(dscfile))
+ for line in f:
+ m = self.version_re.match(line)
+ if m and not self.upstream_version:
+ if '-' in m.group('version'):
+ self.debian_version = m.group('version').split("-")[-1]
+ self.upstream_version = "-".join(m.group('version').split("-")[0:-1])
+ self.native = False
+ else:
+ self.native = True # Debian native package
+ self.upstream_version = m.group('version')
+ if m.group('epoch'):
+ self.epoch = m.group('epoch')
+ else:
+ self.epoch = ""
+ continue
+ m = self.pkg_re.match(line)
+ if m:
+ self.pkg = m.group('pkg')
+ continue
+ m = self.deb_tgz_re.match(line)
+ if m:
+ self.deb_tgz = os.path.join(fromdir, m.group('deb_tgz'))
+ continue
+ m = self.tar_re.match(line)
+ if m:
+ self.tgz = os.path.join(fromdir, m.group('tar'))
+ continue
+ m = self.diff_re.match(line)
+ if m:
+ self.diff = os.path.join(fromdir, m.group('diff'))
+ continue
+ m = self.format_re.match(line)
+ if m:
+ self.pkgformat = m.group('format')
+ continue
+ f.close()
+
+ if not self.pkg:
+ raise GbpError("Cannot parse package name from '%s'" % self.dscfile)
+ elif not self.tgz:
+ raise GbpError("Cannot parse archive name from '%s'" % self.dscfile)
+ if not self.upstream_version:
+ raise GbpError("Cannot parse version number from '%s'" % self.dscfile)
+ if not self.native and not self.debian_version:
+ raise GbpError("Cannot parse Debian version number from '%s'" % self.dscfile)
+
+ def _get_version(self):
+ version = [ "", self.epoch + ":" ][len(self.epoch) > 0]
+ if self.native:
+ version += self.upstream_version
+ else:
+ version += "%s-%s" % (self.upstream_version, self.debian_version)
+ return version
+
+ version = property(_get_version)
+
+ def __str__(self):
+ return "<%s object %s>" % (self.__class__.__name__, self.dscfile)
+
+# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
diff --git a/gbp/deb/policy.py b/gbp/deb/policy.py
index 9c1b018..b35603c 100644
--- a/gbp/deb/policy.py
+++ b/gbp/deb/policy.py
@@ -54,6 +54,9 @@ class DebianPkgPolicy(PkgPolicy):
letters (a-z), digits (0-9), full stops (.), plus signs (+), minus signs
(-), colons (:) and tildes (~)"""
+ # Valid characters in a debian version
+ debianversion_chars = 'a-zA-Z\\d.~+-'
+
@staticmethod
def build_tarball_name(name, version, compression, dir=None):
"""