~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/sourcepackagerelease.py

  • Committer: j.c.sackett
  • Date: 2011-08-31 15:00:45 UTC
  • mfrom: (13834 devel)
  • mto: This revision was merged to the branch mainline in revision 13840.
  • Revision ID: jonathan.sackett@canonical.com-20110831150045-7s7u8upka5yx5c5c
MergedĀ inĀ devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
    ]
11
11
 
12
12
 
 
13
import apt_pkg
13
14
import datetime
 
15
from debian.changelog import (
 
16
    Changelog,
 
17
    ChangelogCreateError,
 
18
    ChangelogParseError,
 
19
    )
14
20
import operator
15
21
import re
16
22
from StringIO import StringIO
603
609
        return PackageDiff(
604
610
            from_source=self, to_source=to_sourcepackagerelease,
605
611
            requester=requester, status=status)
 
612
 
 
613
    def aggregate_changelog(self, since_version):
 
614
        """See `ISourcePackagePublishingHistory`."""
 
615
        if self.changelog is None:
 
616
            return None
 
617
 
 
618
        apt_pkg.InitSystem()
 
619
        chunks = []
 
620
        changelog = self.changelog
 
621
        # The python-debian API for parsing changelogs is pretty awful. The
 
622
        # only useful way of extracting info is to use the iterator on
 
623
        # Changelog and then compare versions.
 
624
        try:
 
625
            for block in Changelog(changelog.read()):
 
626
                version = block._raw_version
 
627
                if (since_version and
 
628
                    apt_pkg.VersionCompare(version, since_version) <= 0):
 
629
                    break
 
630
                # Poking in private attributes is not nice but again the
 
631
                # API is terrible.  We want to ensure that the name/date
 
632
                # line is omitted from these composite changelogs.
 
633
                block._no_trailer = True
 
634
                try:
 
635
                    # python-debian adds an extra blank line to the chunks
 
636
                    # so we'll have to sort this out.
 
637
                    chunks.append(str(block).rstrip())
 
638
                except ChangelogCreateError:
 
639
                    continue
 
640
                if not since_version:
 
641
                    # If a particular version was not requested we just
 
642
                    # return the most recent changelog entry.
 
643
                    break
 
644
        except ChangelogParseError:
 
645
            return None
 
646
 
 
647
        output = "\n\n".join(chunks)
 
648
        return output.decode("utf-8", "replace")