~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/scripts/gina/dominate.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-21 16:55:38 UTC
  • mfrom: (13931.3.7 bug-844550)
  • Revision ID: launchpad@pqm.canonical.com-20110921165538-ymgh2xcq6ljbpjmf
[r=gmb][bug=844550] Replace transitional Gina domination with its
 permanent form.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    series = getUtility(IDistributionSet)[distro_name].getSeries(series_name)
21
21
    dominator = Dominator(logger, series.main_archive)
22
22
 
23
 
    # XXX JeroenVermeulen 2011-09-08, bug=844550: This is a transitional
24
 
    # hack.  Gina used to create SPPHs in Pending state.  We cleaned up
25
 
    # the bulk of them, and changed the code to create Published ones, but
26
 
    # some new ones will have been created since.
27
 
    # Update those to match what the new Gina does.
28
 
    from canonical.launchpad.interfaces.lpstorm import IStore
29
 
    from lp.soyuz.enums import PackagePublishingStatus
30
 
    from lp.soyuz.model.publishing import SourcePackagePublishingHistory
31
 
    SPPH = SourcePackagePublishingHistory
32
 
    store = IStore(SPPH)
33
 
    spphs = store.find(
34
 
        SPPH,
35
 
        SPPH.archive == series.main_archive,
36
 
        SPPH.distroseries == series,
37
 
        SPPH.pocket == pocket,
38
 
        SPPH.status == PackagePublishingStatus.PENDING)
39
 
    spphs.set(status=PackagePublishingStatus.PUBLISHED)
40
 
 
41
 
    # Dominate packages found in the Sources list we're importing.
 
23
    # Dominate all packages published in the series.  This includes all
 
24
    # packages listed in the Sources file we imported, but also packages
 
25
    # that have been recently deleted.
42
26
    package_names = dominator.findPublishedSourcePackageNames(series, pocket)
43
27
    for package_name in package_names:
44
 
        entries = packages_map.src_map.get(package_name)
45
 
 
46
 
        if entries is None:
47
 
            # XXX JeroenVermeulen 2011-09-08, bug=844550: This is a
48
 
            # transitional hack.  The database is full of "Published"
49
 
            # Debian SPPHs whose packages have actually been deleted.
50
 
            # In the future such publications should simply be marked
51
 
            # Deleted, but for the legacy baggage we currently carry
52
 
            # around we'll just do traditional domination first: pick
53
 
            # the latest Published version, and mark the rest of the
54
 
            # SPPHs as superseded by that version.  The latest version
55
 
            # will then, finally, be marked appropriately Deleted once
56
 
            # we remove this transitional hack.
57
 
            # To remove the transitional hack, just let live_versions
58
 
            # default to the empty list instead of doing this:
59
 
            import apt_pkg
60
 
            from lp.services.database.bulk import load_related
61
 
            from lp.soyuz.model.sourcepackagerelease import (
62
 
                SourcePackageRelease,
63
 
                )
64
 
            pubs = list(
65
 
                dominator.findPublishedSPPHs(series, pocket, package_name))
66
 
            if len(pubs) <= 1:
67
 
                # Without at least two published SPPHs, the transitional
68
 
                # code will make no changes.  Skip, and leave the
69
 
                # algorithm free to assume there's a pubs[0].
70
 
                continue
71
 
            load_related(
72
 
                SourcePackageRelease, pubs, ['sourcepackagereleaseID'])
73
 
 
74
 
            # Close off the transaction to avoid being idle-killed.
75
 
            # Nothing else is going to supersede or delete these
76
 
            # publications in the meantime, so our data stays valid; and
77
 
            # if new ones become published, they still won't be
78
 
            # considered anyway.
79
 
            txn.commit()
80
 
 
81
 
            # Find the "latest" publication.  A purely in-memory
82
 
            # operation; won't open a new transaction.
83
 
            def is_newer(candidate, reference):
84
 
                comparison = apt_pkg.VersionCompare(
85
 
                    candidate.sourcepackagerelease.version,
86
 
                    reference.sourcepackagerelease.version)
87
 
                if comparison > 0:
88
 
                    return True
89
 
                elif comparison < 0:
90
 
                    return False
91
 
                else:
92
 
                    return candidate.datecreated > reference.datecreated
93
 
 
94
 
            latest_pub = pubs[0]
95
 
            for pub in pubs[1:]:
96
 
                if is_newer(pub, latest_pub):
97
 
                    latest_pub = pub
98
 
            live_versions = [latest_pub.sourcepackagerelease.version]
99
 
        else:
100
 
            live_versions = [
101
 
                entry['Version']
102
 
                for entry in entries if 'Version' in entry]
 
28
        entries = packages_map.src_map.get(package_name, [])
 
29
        live_versions = [
 
30
            entry['Version'] for entry in entries if 'Version' in entry]
103
31
 
104
32
        dominator.dominateRemovedSourceVersions(
105
33
            series, pocket, package_name, live_versions)