move dsc handling into deb_utils
authorGuido Guenther <agx@sigxcpu.org>
Sat, 17 May 2008 14:23:52 +0000 (16:23 +0200)
committerGuido Guenther <agx@sigxcpu.org>
Sat, 17 May 2008 14:23:52 +0000 (16:23 +0200)
gbp/deb_utils.py
git-import-dsc

index c7c038f32405258ddb336f8b9c1a4d2a92ac9144..d2886467c38e67ec9a97a4d33c23e9f24f89829b 100644 (file)
@@ -3,11 +3,12 @@
 # (C) 2006,2007 Guido Guenther <agx@sigxcpu.org>
 """provides some debian source package related helpers"""
 
-import email
 import commands
+import email
 import os
-import sys
+import re
 import shutil
+import sys
 import command_wrappers as gbpc
 from errors import GbpError
 
@@ -23,6 +24,70 @@ 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*')
+    version_re = re.compile("Version:\s(\d+\:)?(?P<version>[%s]+)\s*$" % debian_version_chars)
+    tar_re = re.compile('^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+(\.orig)?\.tar\.(gz|bz2))')
+    diff_re = re.compile('^\s\w+\s\d+\s+(?P<diff>[^_]+_[^_]+\.diff.(gz|bz2))')
+
+    def __init__(self, dscfile):
+        self.pkg = ""
+        self.tgz = ""
+        self.diff = ""
+        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:
+                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')
+                continue
+            m = self.pkg_re.match(line)
+            if m:
+                self.pkg = m.group('pkg')
+                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
+        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
+
+
+def parse_dsc(dscfile):
+    """parse dsc by creating a DscFile object"""
+    try:
+        dsc = DscFile(dscfile)
+    except IOError, err:
+        raise GbpError, "Error reading dsc file: %s" % err
+    else:
+        try:
+            if dsc.native:
+                print "Debian Native Package"
+                print "Version:", dsc.upstream_version
+            else:
+                print "Upstream version:", dsc.upstream_version
+                print "Debian version:", dsc.debian_version
+        except AttributeError:
+            raise GbpError, "Error parsing dsc file %s" % dscfile
+    return dsc
+
+
 def parse_changelog(changelog):
     """parse changelog file changelog"""
     if not os.access(changelog, os.F_OK):
index 442cbc1f00842d50d01995f30f79945a08bbb9e9..c8e34a5d829662b07bb1d6808d92f0965b997452 100755 (executable)
@@ -25,77 +25,12 @@ import glob
 import pipes
 from email.Utils import parseaddr
 import gbp.command_wrappers as gbpc
-from gbp.deb_utils import debian_version_chars, parse_changelog, unpack_orig
+from gbp.deb_utils import debian_version_chars, parse_changelog, unpack_orig, parse_dsc, DscFile
 from gbp.git_utils import build_tag, GitRepository, GitRepositoryError, replace_source_tree, rfc822_date_to_git
 from gbp.config import GbpOptionParser
 from gbp.errors import GbpError
 
 
-class DscFile(object):
-    """Keeps all needed data read from a dscfile"""
-    pkg_re = re.compile('Source:\s+(?P<pkg>.+)\s*')
-    version_re = re.compile("Version:\s(\d+\:)?(?P<version>[%s]+)\s*$" % debian_version_chars)
-    tar_re = re.compile('^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+(\.orig)?\.tar\.(gz|bz2))')
-    diff_re = re.compile('^\s\w+\s\d+\s+(?P<diff>[^_]+_[^_]+\.diff.(gz|bz2))')
-
-    def __init__(self, dscfile):
-        self.pkg = ""
-        self.tgz = ""
-        self.diff = ""
-        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:
-                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')
-                continue
-            m = self.pkg_re.match(line)
-            if m:
-                self.pkg = m.group('pkg')
-                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
-        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
-
-
-def parse_dsc(dscfile):
-    """parse dsc by creating a DscFile object"""
-    try:
-        dsc = DscFile(dscfile)
-    except IOError, err:
-        print >>sys.stderr, "Error reading dsc file: %s" % err
-        dsc = None
-    else:
-        try:
-            if dsc.native:
-                print "Debian Native Package"
-                print "Version:", dsc.upstream_version
-            else:
-                print "Upstream version:", dsc.upstream_version
-                print "Debian version:", dsc.debian_version
-        except AttributeError:
-            print >>sys.stderr, "Error parsing dsc file %s" % dscfile 
-            dsc = None
-    return dsc
-
-
 def import_initial(src, dirs, options):
     """
     import the intial version and (in the case of a non native package) create
@@ -225,8 +160,6 @@ def main(argv):
             raise GbpError
         else:
             src = parse_dsc(args[0])
-            if not src:
-                raise GbpError
 
             try:
                 repo = GitRepository('.')