8687.15.17
by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
8447.1.2
by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever. |
4 |
# pylint: disable-msg=W0231
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
5 |
|
6 |
"""The content classes for links from source packages to branches.."""
|
|
7 |
||
8 |
__metaclass__ = type |
|
9 |
__all__ = [ |
|
10 |
'SeriesSourcePackageBranch', |
|
11 |
'SeriesSourcePackageBranchSet', |
|
12 |
]
|
|
13 |
||
14 |
from datetime import datetime |
|
15 |
||
16 |
import pytz |
|
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
17 |
from storm.locals import ( |
18 |
DateTime, |
|
19 |
Int, |
|
20 |
Reference, |
|
21 |
Storm, |
|
22 |
)
|
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
23 |
from zope.component import getUtility |
24 |
from zope.interface import implements |
|
25 |
||
14606.3.1
by William Grant
Merge canonical.database into lp.services.database. |
26 |
from lp.code.interfaces.seriessourcepackagebranch import ( |
27 |
IFindOfficialBranchLinks, |
|
28 |
ISeriesSourcePackageBranch, |
|
29 |
)
|
|
30 |
from lp.registry.interfaces.pocket import PackagePublishingPocket |
|
31 |
from lp.services.database.enumcol import DBEnum |
|
14600.2.2
by Curtis Hovey
Moved webapp to lp.services. |
32 |
from lp.services.webapp.interfaces import ( |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
33 |
DEFAULT_FLAVOR, |
34 |
IStoreSelector, |
|
35 |
MAIN_STORE, |
|
36 |
MASTER_FLAVOR, |
|
37 |
)
|
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
38 |
|
39 |
||
40 |
class SeriesSourcePackageBranch(Storm): |
|
41 |
"""See `ISeriesSourcePackageBranch`."""
|
|
42 |
||
43 |
__storm_table__ = 'SeriesSourcePackageBranch' |
|
44 |
implements(ISeriesSourcePackageBranch) |
|
45 |
||
46 |
id = Int(primary=True) |
|
47 |
distroseriesID = Int('distroseries') |
|
48 |
distroseries = Reference(distroseriesID, 'DistroSeries.id') |
|
49 |
||
50 |
pocket = DBEnum(enum=PackagePublishingPocket) |
|
51 |
||
52 |
sourcepackagenameID = Int('sourcepackagename') |
|
53 |
sourcepackagename = Reference( |
|
54 |
sourcepackagenameID, 'SourcePackageName.id') |
|
55 |
||
56 |
branchID = Int('branch') |
|
57 |
branch = Reference(branchID, 'Branch.id') |
|
58 |
||
59 |
registrantID = Int('registrant') |
|
60 |
registrant = Reference(registrantID, 'Person.id') |
|
61 |
||
62 |
date_created = DateTime(allow_none=False) |
|
63 |
||
64 |
def __init__(self, distroseries, pocket, sourcepackagename, branch, |
|
65 |
registrant, date_created): |
|
66 |
"""Construct an `ISeriesSourcePackageBranch`."""
|
|
67 |
self.distroseries = distroseries |
|
68 |
self.pocket = pocket |
|
69 |
self.sourcepackagename = sourcepackagename |
|
70 |
self.branch = branch |
|
71 |
self.registrant = registrant |
|
72 |
self.date_created = date_created |
|
73 |
||
8211.4.12
by Jonathan Lange
Allow branches linked to source packages to be deleted. |
74 |
@property
|
75 |
def sourcepackage(self): |
|
76 |
return self.distroseries.getSourcePackage(self.sourcepackagename) |
|
77 |
||
8852.2.1
by Tim Penhey
Make the decorated branch listing item pass itself through when determining the bazaar_identity so the cached associated product series can be used. |
78 |
@property
|
79 |
def suite_sourcepackage(self): |
|
80 |
return self.sourcepackage.getSuiteSourcePackage(self.pocket) |
|
81 |
||
7349.1.2
by Jonathan Lange
Files I forgot to add |
82 |
|
83 |
class SeriesSourcePackageBranchSet: |
|
84 |
"""See `ISeriesSourcePackageBranchSet`."""
|
|
85 |
||
13139.3.3
by Francis J. Lacoste
Remove IMakeOfficialBranchLinks non-utility. |
86 |
implements(IFindOfficialBranchLinks) |
7349.1.2
by Jonathan Lange
Files I forgot to add |
87 |
|
13139.3.3
by Francis J. Lacoste
Remove IMakeOfficialBranchLinks non-utility. |
88 |
@staticmethod
|
89 |
def new(distroseries, pocket, sourcepackagename, branch, registrant, |
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
90 |
date_created=None): |
13139.3.3
by Francis J. Lacoste
Remove IMakeOfficialBranchLinks non-utility. |
91 |
"""Link a source package in a distribution suite to a branch."""
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
92 |
if date_created is None: |
93 |
date_created = datetime.now(pytz.UTC) |
|
94 |
sspb = SeriesSourcePackageBranch( |
|
95 |
distroseries, pocket, sourcepackagename, branch, registrant, |
|
96 |
date_created) |
|
97 |
store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR) |
|
98 |
store.add(sspb) |
|
99 |
return sspb |
|
8211.4.4
by Jonathan Lange
Add a method for getting the links to branches from a source package. |
100 |
|
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
101 |
def findForBranch(self, branch): |
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
102 |
"""See `IFindOfficialBranchLinks`."""
|
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
103 |
return self.findForBranches([branch]) |
104 |
||
105 |
def findForBranches(self, branches): |
|
106 |
"""See `IFindOfficialBranchLinks`."""
|
|
107 |
branch_ids = set(branch.id for branch in branches) |
|
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
108 |
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) |
109 |
return store.find( |
|
110 |
SeriesSourcePackageBranch, |
|
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
111 |
SeriesSourcePackageBranch.branchID.is_in(branch_ids)) |
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
112 |
|
8211.4.8
by Jonathan Lange
Rename getLinks to findForSourcePackage. |
113 |
def findForSourcePackage(self, sourcepackage): |
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
114 |
"""See `IFindOfficialBranchLinks`."""
|
8211.4.4
by Jonathan Lange
Add a method for getting the links to branches from a source package. |
115 |
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) |
116 |
distroseries = sourcepackage.distroseries |
|
117 |
sourcepackagename = sourcepackage.sourcepackagename |
|
118 |
return store.find( |
|
119 |
SeriesSourcePackageBranch, |
|
120 |
SeriesSourcePackageBranch.distroseries == distroseries.id, |
|
121 |
SeriesSourcePackageBranch.sourcepackagename == |
|
122 |
sourcepackagename.id) |
|
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
123 |
|
8698.11.2
by Tim Penhey
Add SeriesSourcePackageBranchSet.findForDistributionSourcePackage |
124 |
def findForDistributionSourcePackage(self, distrosourcepackage): |
125 |
"""See `IFindOfficialBranchLinks`."""
|
|
126 |
# To prevent circular imports.
|
|
127 |
from lp.registry.model.distroseries import DistroSeries |
|
128 |
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) |
|
129 |
distro = distrosourcepackage.distribution |
|
130 |
sourcepackagename = distrosourcepackage.sourcepackagename |
|
131 |
return store.find( |
|
132 |
SeriesSourcePackageBranch, |
|
133 |
DistroSeries.distribution == distro.id, |
|
134 |
SeriesSourcePackageBranch.distroseries == DistroSeries.id, |
|
135 |
SeriesSourcePackageBranch.sourcepackagename == |
|
136 |
sourcepackagename.id) |
|
137 |
||
13139.3.3
by Francis J. Lacoste
Remove IMakeOfficialBranchLinks non-utility. |
138 |
@staticmethod
|
139 |
def delete(sourcepackage, pocket): |
|
140 |
"""Remove the SeriesSourcePackageBranch for sourcepackage and pocket.
|
|
141 |
||
142 |
:param sourcepackage: An `ISourcePackage`.
|
|
143 |
:param pocket: A `PackagePublishingPocket` enum item.
|
|
144 |
"""
|
|
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
145 |
store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR) |
146 |
distroseries = sourcepackage.distroseries |
|
147 |
sourcepackagename = sourcepackage.sourcepackagename |
|
148 |
return store.find( |
|
149 |
SeriesSourcePackageBranch, |
|
150 |
SeriesSourcePackageBranch.distroseries == distroseries.id, |
|
151 |
SeriesSourcePackageBranch.sourcepackagename == |
|
9032.1.1
by Michael Hudson
test and fix |
152 |
sourcepackagename.id, |
153 |
SeriesSourcePackageBranch.pocket == pocket).remove() |