This adds a function parse_changelog_file that can be passed a filename
(as used to happen with parse_changelog) and changes parse_changelog to
accept the contents of a changelog file.

There should be no functional changes from this commit.

Git-Dch: Ignore
---
 gbp/deb.py       |   29 +++++++++++++++++++++++------
 git-buildpackage |    4 ++--
 git-dch          |    6 +++---
 git-import-dsc   |    4 ++--
 git-import-orig  |    6 +++---
 5 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/gbp/deb.py b/gbp/deb.py
index 3220b51..0b94386 100644
--- a/gbp/deb.py
+++ b/gbp/deb.py
@@ -125,21 +125,38 @@ def parse_dsc(dscfile):
     return dsc
 
 
-def parse_changelog(changelog):
+def parse_changelog_file(filename):
     """
     parse changelog file changelog
 
+    See parse_changelog for the return value.
+    """
+
+    if os.access(filename, os.F_OK):
+        f = open(filename, 'r')
+        contents = f.read()
+        f.close()
+
+        return parse_changelog(contents)
+    else:
+        raise NoChangelogError, "Changelog %s not found or not readable" % 
(filename, )
+
+def parse_changelog(contents):
+    """
+    Parse the content of a changelog file.
+
+    Returns:
+
     cp['Version']: full version string including epoch
     cp['Upstream-Version']: upstream version, if not debian native
     cp['Debian-Version']: debian release
     cp['Epoch']: epoch, if any
     cp['NoEpoch-Version']: full version string excluding epoch
     """
-    if not os.access(changelog, os.F_OK):
-        raise NoChangelogError, "Changelog %s not found" % (changelog, )
-    status, output = commands.getstatusoutput('dpkg-parsechangelog -l%s' % 
(changelog, ))
-    if status:
-        raise ParseChangeLogError, output
+    cmd = subprocess.Popen(['dpkg-parsechangelog', '-l-'], 
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    (output, errors) = cmd.communicate(contents)
+    if cmd.returncode:
+        raise ParseChangeLogError, "Failed to parse changelog.  
dpkg-parsechangelog said:\n%s" % (errors, )
     cp = email.message_from_string(output)
     try:
         if ':' in cp['Version']:
diff --git a/git-buildpackage b/git-buildpackage
index 649b9dd..238ac5b 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -317,7 +317,7 @@ def main(argv):
                 raise GbpError, "Use --git-ignore-branch to ignore or 
--git-debian-branch to set the branch name."
 
         try:
-            cp = du.parse_changelog(changelog)
+            cp = du.parse_changelog_file(changelog)
             version = cp['Version']
             version_no_epoch = cp['NoEpoch-Version']
             if du.is_native(cp):
@@ -376,7 +376,7 @@ def main(argv):
 
                 print "Exporting '%s' to '%s'" % (options.export, tmp_dir)
                 dump_tree(tmp_dir, tree)
-                cp = du.parse_changelog(os.path.join(tmp_dir, 'debian', 
'changelog'))
+                cp = du.parse_changelog_file(os.path.join(tmp_dir, 'debian', 
'changelog'))
                 export_dir = os.path.join(output_dir, "%s-%s" % (cp['Source'], 
major))
                 print "Moving '%s' to '%s'" % (tmp_dir, export_dir)
                 move_old_export(export_dir)
diff --git a/git-dch b/git-dch
index debb974..b6c15f7 100755
--- a/git-dch
+++ b/git-dch
@@ -28,7 +28,7 @@ import gbp.command_wrappers as gbpc
 from gbp.git import (GitRepositoryError, GitRepository, build_tag)
 from gbp.config import GbpOptionParser, GbpOptionGroup
 from gbp.errors import GbpError
-from gbp.deb import parse_changelog, NoChangelogError
+from gbp.deb import parse_changelog_file, NoChangelogError
 from gbp.command_wrappers import (Command, CommandExecFailed)
 
 snapshot_re = re.compile("\s*\*\* SNAPSHOT build 
@(?P<commit>[a-z0-9]+)\s+\*\*")
@@ -215,7 +215,7 @@ def do_snapshot(changelog, repo, next_snapshot):
     """
     commit = head_commit(repo)
 
-    cp = parse_changelog(changelog)
+    cp = parse_changelog_file(changelog)
     (release, snapshot) = snapshot_version(cp['Version'])
     snapshot = int(eval(next_snapshot))
 
@@ -400,7 +400,7 @@ def main(argv):
             print >>sys.stderr, "You are not on branch '%s' but on '%s'" % 
(options.debian_branch, branch)
             raise GbpError, "Use --ignore-branch to ignore or --debian-branch 
to set the branch name."
 
-        cp = parse_changelog(changelog)
+        cp = parse_changelog_file(changelog)
 
         if options.since:
             since = options.since
diff --git a/git-import-dsc b/git-import-dsc
index 8def4ec..fa3bc98 100755
--- a/git-import-dsc
+++ b/git-import-dsc
@@ -26,7 +26,7 @@ import glob
 import pipes
 from email.Utils import parseaddr
 import gbp.command_wrappers as gbpc
-from gbp.deb import (debian_version_chars, parse_changelog, unpack_orig,
+from gbp.deb import (debian_version_chars, parse_changelog_file, unpack_orig,
                      parse_dsc, DscFile, tar_toplevel)
 from gbp.git import (build_tag, create_repo, GitRepository,
                      GitRepositoryError, rfc822_date_to_git)
@@ -97,7 +97,7 @@ def apply_debian_patch(repo, unpack_dir, src, options, 
parents):
         os.chmod('debian/rules', 0755)
         os.chdir(repo.path)
 
-        dch = parse_changelog(os.path.join(unpack_dir, 'debian/changelog'))
+        dch = parse_changelog_file(os.path.join(unpack_dir, 
'debian/changelog'))
         date= rfc822_date_to_git(dch['Date'])
         author, email = parseaddr(dch['Maintainer'])
         if not (author and email):
diff --git a/git-import-orig b/git-import-orig
index f70b8bf..c6de631 100755
--- a/git-import-orig
+++ b/git-import-orig
@@ -28,7 +28,7 @@ import tarfile
 import time
 import tempfile
 import gbp.command_wrappers as gbpc
-from gbp.deb import (parse_changelog, unpack_orig, repack_orig,
+from gbp.deb import (parse_changelog_file, unpack_orig, repack_orig,
                      NoChangelogError, has_epoch, tar_toplevel,
                      guess_upstream_version, do_uscan)
 from gbp.git import (FastImport, GitRepositoryError, GitRepository, build_tag)
@@ -331,7 +331,7 @@ on howto create it otherwise use --upstream-branch to 
specify it.
 
         # Try to find the source package name
         try:
-            cp = parse_changelog('debian/changelog')
+            cp = parse_changelog_file('debian/changelog')
             sourcepackage = cp['Source']
         except NoChangelogError:
             sourcepackage = ask_package_name(guessed_package)
@@ -418,7 +418,7 @@ on howto create it otherwise use --upstream-branch to 
specify it.
                 if options.postimport:
                     epoch = ''
                     if os.access('debian/changelog', os.R_OK):
-                        cp = parse_changelog('debian/changelog')
+                        cp = parse_changelog_file('debian/changelog')
                         if has_epoch(cp):
                             epoch = '%s:' % cp['Epoch']
                     info = { 'version': "%s%s-1" % (epoch, version) }
-- 
1.7.1




-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to