~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/distroseriesparent.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-23 18:43:31 UTC
  • mfrom: (13084.2.6 page-match-rewrite-url)
  • Revision ID: launchpad@pqm.canonical.com-20110523184331-dhd2c7cgfuu49epw
[r=sinzui][bug=784273] Adds facility to the PageMatch to handle bad
        URIs

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    ]
12
12
 
13
13
from storm.locals import (
14
 
    Bool,
15
14
    Int,
16
15
    Reference,
17
 
    SQL,
18
16
    Storm,
 
17
    Bool,
19
18
    )
20
19
from zope.interface import implements
21
20
 
22
 
from canonical.database.enumcol import EnumCol
23
21
from canonical.launchpad.interfaces.lpstorm import (
24
22
    IMasterStore,
25
23
    IStore,
28
26
    IDistroSeriesParent,
29
27
    IDistroSeriesParentSet,
30
28
    )
31
 
from lp.registry.interfaces.pocket import PackagePublishingPocket
32
29
 
33
30
 
34
31
class DistroSeriesParent(Storm):
46
43
 
47
44
    initialized = Bool(allow_none=False)
48
45
 
49
 
    is_overlay = Bool(allow_none=False, default=False)
50
 
 
51
 
    pocket = EnumCol(
52
 
        dbName='pocket', notNull=False,
53
 
        schema=PackagePublishingPocket)
54
 
 
55
 
    component_id = Int(name='component', allow_none=True)
56
 
    component = Reference(component_id, 'Component.id')
57
 
 
58
46
 
59
47
class DistroSeriesParentSet:
60
48
    """See `IDistroSeriesParentSet`."""
61
49
    implements(IDistroSeriesParentSet)
62
50
    title = "Cross reference of parent and derived distroseries."
63
51
 
64
 
    def new(self, derived_series, parent_series, initialized,
65
 
            is_overlay=False, pocket=None, component=None):
 
52
    def new(self, derived_series, parent_series, initialized):
66
53
        """Make and return a new `DistroSeriesParent`."""
67
54
        store = IMasterStore(DistroSeriesParent)
68
55
        dsp = DistroSeriesParent()
69
56
        dsp.derived_series = derived_series
70
57
        dsp.parent_series = parent_series
71
58
        dsp.initialized = initialized
72
 
        dsp.is_overlay = is_overlay
73
 
        dsp.pocket = pocket
74
 
        dsp.component = component
75
59
        store.add(dsp)
76
60
        return dsp
77
61
 
88
72
        return store.find(
89
73
            DistroSeriesParent,
90
74
            DistroSeriesParent.parent_series_id == parent_series.id)
91
 
 
92
 
    def getByDerivedAndParentSeries(self, derived_series, parent_series):
93
 
        """See `IDistroSeriesParentSet`."""
94
 
        store = IStore(DistroSeriesParent)
95
 
        return store.find(
96
 
            DistroSeriesParent,
97
 
            DistroSeriesParent.parent_series_id == parent_series.id,
98
 
            DistroSeriesParent.derived_series_id == derived_series.id).one()
99
 
 
100
 
    def getFlattenedOverlayTree(self, derived_series):
101
 
        """See `IDistroSeriesParentSet`."""
102
 
        self.getByDerivedSeries(derived_series)
103
 
        rec_overlay_query = '''
104
 
            RECURSIVE t_parents(parent_series) AS (
105
 
                SELECT parent_series
106
 
                FROM DistroSeriesParent
107
 
                WHERE derived_series=? AND
108
 
                    is_overlay = True
109
 
            UNION ALL
110
 
                SELECT dsp.parent_series
111
 
                FROM DistroSeriesParent dsp, t_parents p
112
 
                WHERE dsp.derived_series = p.parent_series AND
113
 
                    dsp.is_overlay = True
114
 
        ) '''
115
 
        store = IStore(DistroSeriesParent)
116
 
        # XXX: rvb 2011-05-20 bug=785733: Order by DSD.id for now.
117
 
        # Once the ordering is specified in the database, it should
118
 
        # be used to sort the results.
119
 
        return store.with_(
120
 
            SQL(rec_overlay_query, (derived_series.id, ))).find(
121
 
                DistroSeriesParent,
122
 
                SQL('DistroSeriesParent.parent_series IN '
123
 
                    '(SELECT parent_series FROM t_parents)')
124
 
                ).order_by(DistroSeriesParent.id)