7675.1113.1
by Julian Edwards
schema, model and interface |
1 |
# Copyright 2011 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Database class for table DistroSeriesParent."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
__all__ = [ |
|
9 |
'DistroSeriesParent', |
|
10 |
'DistroSeriesParentSet', |
|
11 |
]
|
|
12 |
||
13 |
from storm.locals import ( |
|
7675.1140.1
by Raphael Badin
Add is_overlay, pocket and component to DSP. |
14 |
Bool, |
7675.1113.1
by Julian Edwards
schema, model and interface |
15 |
Int, |
16 |
Reference, |
|
7675.1146.5
by Raphael Badin
Fix WITH RECURSIVE syntax. |
17 |
SQL, |
7675.1113.1
by Julian Edwards
schema, model and interface |
18 |
Storm, |
19 |
)
|
|
20 |
from zope.interface import implements |
|
21 |
||
7675.1140.1
by Raphael Badin
Add is_overlay, pocket and component to DSP. |
22 |
from canonical.database.enumcol import EnumCol |
7675.1113.1
by Julian Edwards
schema, model and interface |
23 |
from canonical.launchpad.interfaces.lpstorm import ( |
24 |
IMasterStore, |
|
25 |
IStore, |
|
26 |
)
|
|
27 |
from lp.registry.interfaces.distroseriesparent import ( |
|
28 |
IDistroSeriesParent, |
|
29 |
IDistroSeriesParentSet, |
|
30 |
)
|
|
7675.1140.1
by Raphael Badin
Add is_overlay, pocket and component to DSP. |
31 |
from lp.registry.interfaces.pocket import PackagePublishingPocket |
7675.1113.1
by Julian Edwards
schema, model and interface |
32 |
|
33 |
||
34 |
class DistroSeriesParent(Storm): |
|
35 |
"""See `IDistroSeriesParent`."""
|
|
36 |
implements(IDistroSeriesParent) |
|
37 |
__storm_table__ = 'DistroSeriesParent' |
|
38 |
||
39 |
id = Int(primary=True) |
|
40 |
||
41 |
parent_series_id = Int(name='parent_series', allow_none=False) |
|
7675.1113.4
by Julian Edwards
start of tests |
42 |
parent_series = Reference(parent_series_id, 'DistroSeries.id') |
7675.1113.1
by Julian Edwards
schema, model and interface |
43 |
|
44 |
derived_series_id = Int(name='derived_series', allow_none=False) |
|
7675.1113.4
by Julian Edwards
start of tests |
45 |
derived_series = Reference(derived_series_id, 'DistroSeries.id') |
7675.1113.1
by Julian Edwards
schema, model and interface |
46 |
|
47 |
initialized = Bool(allow_none=False) |
|
48 |
||
7675.1140.1
by Raphael Badin
Add is_overlay, pocket and component to DSP. |
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 |
||
7675.1113.1
by Julian Edwards
schema, model and interface |
58 |
|
59 |
class DistroSeriesParentSet: |
|
60 |
"""See `IDistroSeriesParentSet`."""
|
|
61 |
implements(IDistroSeriesParentSet) |
|
62 |
title = "Cross reference of parent and derived distroseries." |
|
63 |
||
7675.1140.1
by Raphael Badin
Add is_overlay, pocket and component to DSP. |
64 |
def new(self, derived_series, parent_series, initialized, |
65 |
is_overlay=False, pocket=None, component=None): |
|
7675.1113.1
by Julian Edwards
schema, model and interface |
66 |
"""Make and return a new `DistroSeriesParent`."""
|
67 |
store = IMasterStore(DistroSeriesParent) |
|
68 |
dsp = DistroSeriesParent() |
|
69 |
dsp.derived_series = derived_series |
|
70 |
dsp.parent_series = parent_series |
|
71 |
dsp.initialized = initialized |
|
7675.1140.1
by Raphael Badin
Add is_overlay, pocket and component to DSP. |
72 |
dsp.is_overlay = is_overlay |
73 |
dsp.pocket = pocket |
|
74 |
dsp.component = component |
|
7675.1113.1
by Julian Edwards
schema, model and interface |
75 |
store.add(dsp) |
76 |
return dsp |
|
77 |
||
78 |
def getByDerivedSeries(self, derived_series): |
|
79 |
"""See `IDistroSeriesParentSet`."""
|
|
80 |
store = IStore(DistroSeriesParent) |
|
81 |
return store.find( |
|
82 |
DistroSeriesParent, |
|
83 |
DistroSeriesParent.derived_series_id == derived_series.id) |
|
84 |
||
85 |
def getByParentSeries(self, parent_series): |
|
86 |
"""See `IDistroSeriesParentSet`."""
|
|
87 |
store = IStore(DistroSeriesParent) |
|
88 |
return store.find( |
|
89 |
DistroSeriesParent, |
|
90 |
DistroSeriesParent.parent_series_id == parent_series.id) |
|
7675.1146.1
by Raphael Badin
Add recursive getFlattenedOverlayTree method to DSP. |
91 |
|
92 |
def getFlattenedOverlayTree(self, derived_series): |
|
93 |
"""See `IDistroSeriesParentSet`."""
|
|
94 |
self.getByDerivedSeries(derived_series) |
|
95 |
rec_overlay_query = ''' |
|
7675.1146.5
by Raphael Badin
Fix WITH RECURSIVE syntax. |
96 |
RECURSIVE t_parents(parent_series) AS (
|
7675.1146.1
by Raphael Badin
Add recursive getFlattenedOverlayTree method to DSP. |
97 |
SELECT parent_series
|
98 |
FROM DistroSeriesParent
|
|
99 |
WHERE derived_series=? AND
|
|
100 |
is_overlay = True
|
|
101 |
UNION ALL
|
|
102 |
SELECT dsp.parent_series
|
|
103 |
FROM DistroSeriesParent dsp, t_parents p
|
|
104 |
WHERE dsp.derived_series = p.parent_series AND
|
|
105 |
dsp.is_overlay = True
|
|
7675.1146.5
by Raphael Badin
Fix WITH RECURSIVE syntax. |
106 |
) '''
|
7675.1146.3
by Raphael Badin
Fix style and ASCII-art diagrams. |
107 |
store = IStore(DistroSeriesParent) |
7675.1146.14
by Raphael Badin
Explicitely sort the results of getFlattenedOverlayTree. |
108 |
# XXX: rvb 2011-05-20 bug=785733: Order by DSD.id for now.
|
109 |
# Once the ordering is specified in the database, it should
|
|
110 |
# be used to sort the results.
|
|
7675.1146.5
by Raphael Badin
Fix WITH RECURSIVE syntax. |
111 |
return store.with_( |
112 |
SQL(rec_overlay_query, (derived_series.id, ))).find( |
|
113 |
DistroSeriesParent, |
|
114 |
SQL('DistroSeriesParent.parent_series IN ' |
|
115 |
'(SELECT parent_series FROM t_parents)') |
|
7675.1146.14
by Raphael Badin
Explicitely sort the results of getFlattenedOverlayTree. |
116 |
).order_by(DistroSeriesParent.id) |