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 |
||
5731.3.3
by Celso Providelo
Consolidating PPA-dependencies backend. |
4 |
# pylint: disable-msg=E0611,W0212
|
5 |
||
6 |
"""Database class for ArchiveDependency."""
|
|
7 |
||
8 |
__metaclass__ = type |
|
9 |
||
10 |
__all__ = ['ArchiveDependency'] |
|
11 |
||
12 |
||
13 |
from sqlobject import ForeignKey |
|
14 |
from zope.interface import implements |
|
15 |
||
16 |
from canonical.database.constants import UTC_NOW |
|
17 |
from canonical.database.datetimecol import UtcDateTimeCol |
|
7053.1.1
by Celso Providelo
First take on bug #249860 (configurable archive dependencies). This change simply extends the ArchiveDependency model to support the 'pocket' and 'component' columns and update the callsites to start filling them. |
18 |
from canonical.database.enumcol import EnumCol |
5731.3.3
by Celso Providelo
Consolidating PPA-dependencies backend. |
19 |
from canonical.database.sqlbase import SQLBase |
9113.7.4
by Jonathan Lange
Update many imports of pocket. |
20 |
from lp.registry.interfaces.pocket import PackagePublishingPocket |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
21 |
from lp.soyuz.adapters.archivedependencies import component_dependencies |
22 |
from lp.soyuz.interfaces.archivedependency import IArchiveDependency |
|
5731.3.3
by Celso Providelo
Consolidating PPA-dependencies backend. |
23 |
|
24 |
||
25 |
class ArchiveDependency(SQLBase): |
|
5796.1.2
by Celso Providelo
merging -frontend branch, r=bigjools, barry. |
26 |
"""See `IArchiveDependency`."""
|
5731.3.3
by Celso Providelo
Consolidating PPA-dependencies backend. |
27 |
|
28 |
implements(IArchiveDependency) |
|
29 |
||
30 |
_table = 'ArchiveDependency' |
|
31 |
_defaultOrder = 'id' |
|
32 |
||
33 |
date_created = UtcDateTimeCol( |
|
34 |
dbName='date_created', notNull=True, default=UTC_NOW) |
|
35 |
||
36 |
archive = ForeignKey( |
|
37 |
foreignKey='Archive', dbName='archive', notNull=True) |
|
38 |
||
39 |
dependency = ForeignKey( |
|
40 |
foreignKey='Archive', dbName='dependency', notNull=True) |
|
41 |
||
7053.1.1
by Celso Providelo
First take on bug #249860 (configurable archive dependencies). This change simply extends the ArchiveDependency model to support the 'pocket' and 'component' columns and update the callsites to start filling them. |
42 |
pocket = EnumCol( |
43 |
dbName='pocket', notNull=True, schema=PackagePublishingPocket) |
|
44 |
||
45 |
component = ForeignKey( |
|
7159.1.3
by Celso Providelo
Establishing a better ArchiveDependency API and sane DB model. |
46 |
foreignKey='Component', dbName='component') |
7310.6.2
by Celso Providelo
Implemeting IArchiveDependency.title to be more objective about primary archive dependencies. |
47 |
|
48 |
@property
|
|
9032.3.1
by William Grant
Decorate IArchiveDependency, and give it a component_name. |
49 |
def component_name(self): |
50 |
"""See `IArchiveDependency`"""
|
|
51 |
if self.component: |
|
52 |
return self.component.name |
|
53 |
else: |
|
54 |
return None |
|
55 |
||
56 |
@property
|
|
7310.6.2
by Celso Providelo
Implemeting IArchiveDependency.title to be more objective about primary archive dependencies. |
57 |
def title(self): |
58 |
"""See `IArchiveDependency`."""
|
|
59 |
if self.dependency.is_ppa: |
|
7976.2.1
by Celso Providelo
Renaming IArchive.title to IArchive.displayname in preparation to have user-defined titles, bug #340457. |
60 |
return self.dependency.displayname |
7310.6.2
by Celso Providelo
Implemeting IArchiveDependency.title to be more objective about primary archive dependencies. |
61 |
|
7310.6.18
by Celso Providelo
applying review comments, r=bac. Incomplete. |
62 |
pocket_title = "%s - %s" % ( |
7976.2.1
by Celso Providelo
Renaming IArchive.title to IArchive.displayname in preparation to have user-defined titles, bug #340457. |
63 |
self.dependency.displayname, self.pocket.name) |
7310.6.18
by Celso Providelo
applying review comments, r=bac. Incomplete. |
64 |
|
7310.6.3
by Celso Providelo
basic UI for adjusting PPA primary archive dependencies. |
65 |
if self.component is None: |
66 |
return pocket_title |
|
7310.6.2
by Celso Providelo
Implemeting IArchiveDependency.title to be more objective about primary archive dependencies. |
67 |
|
7469.4.3
by Celso Providelo
Improving ArchiveDependencies title. |
68 |
component_part = ", ".join( |
69 |
component_dependencies[self.component.name]) |
|
70 |
||
71 |
return "%s (%s)" % (pocket_title, component_part) |