~launchpad-pqm/launchpad/devel

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
4983.1.2 by Curtis Hovey
Added pylint exceptions to database classes.
4
# pylint: disable-msg=E0611,W0212
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
5
6
__metaclass__ = type
7675.585.1 by William Grant
Add new classes to __all__s, to please the import fascist.
7
__all__ = [
8
    'BinaryPackageRelease',
9
    'BinaryPackageReleaseDownloadCount',
10
    ]
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
11
1063 by Canonical.com Patch Queue Manager
soyuz restructing, first landing
12
7675.788.1 by Henning Eggers
Merged reformat-imports branch and resolved conflicts.
13
import simplejson
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
14
from sqlobject import (
15
    BoolCol,
16
    ForeignKey,
17
    IntCol,
18
    SQLMultipleJoin,
19
    StringCol,
20
    )
21
from storm.locals import (
22
    Date,
23
    Int,
24
    Reference,
12301.2.1 by William Grant
Turn BPR.files into a cachedproperty.
25
    Store,
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
26
    Storm,
27
    )
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
28
from zope.interface import implements
29
14606.3.1 by William Grant
Merge canonical.database into lp.services.database.
30
from lp.services.database.constants import UTC_NOW
31
from lp.services.database.datetimecol import UtcDateTimeCol
32
from lp.services.database.enumcol import EnumCol
33
from lp.services.database.sqlbase import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
34
    quote,
35
    quote_like,
36
    SQLBase,
37
    sqlvalues,
38
    )
12301.2.1 by William Grant
Turn BPR.files into a cachedproperty.
39
from lp.services.propertycache import (
40
    cachedproperty,
41
    get_property_cache,
42
    )
11411.6.6 by Julian Edwards
move BinaryPackageFormat and BinaryPackageFileType
43
from lp.soyuz.enums import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
44
    BinaryPackageFileType,
45
    BinaryPackageFormat,
11411.6.12 by Julian Edwards
Move PackagePublishingStatus/Priority
46
    PackagePublishingPriority,
47
    PackagePublishingStatus,
11411.6.6 by Julian Edwards
move BinaryPackageFormat and BinaryPackageFileType
48
    )
49
from lp.soyuz.interfaces.binarypackagerelease import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
50
    IBinaryPackageRelease,
51
    IBinaryPackageReleaseDownloadCount,
52
    )
8294.6.9 by Julian Edwards
migrate files modules to lp.soyuz
53
from lp.soyuz.model.files import BinaryPackageFile
1517 by Canonical.com Patch Queue Manager
Using EnumCol instead if IntCol for db columns represented by a dbschema class, code ajustment and some small distro, packages and person classes improvement.
54
1433 by Canonical.com Patch Queue Manager
Got classes related with source and binary packages into diferent files on database, interfaces and zcml directories.
55
2370 by Canonical.com Patch Queue Manager
Publishing database rework. Renames BinaryPackage and the publishing tables. Likely to cause fallout not caught in tests yet. r=stevea,stub
56
class BinaryPackageRelease(SQLBase):
57
    implements(IBinaryPackageRelease)
58
    _table = 'BinaryPackageRelease'
3147.2.62 by Celso Providelo
Applying review comments (take 1)
59
    binarypackagename = ForeignKey(dbName='binarypackagename', notNull=True,
60
                                   foreignKey='BinaryPackageName')
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
61
    version = StringCol(dbName='version', notNull=True)
1708 by Canonical.com Patch Queue Manager
shift launchpad to summary from shortdesc (r=spiv)
62
    summary = StringCol(dbName='summary', notNull=True, default="")
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
63
    description = StringCol(dbName='description', notNull=True)
10667.2.4 by Michael Nelson
Updated references to old 'Build' class.
64
    build = ForeignKey(
65
        dbName='build', foreignKey='BinaryPackageBuild', notNull=True)
1517 by Canonical.com Patch Queue Manager
Using EnumCol instead if IntCol for db columns represented by a dbschema class, code ajustment and some small distro, packages and person classes improvement.
66
    binpackageformat = EnumCol(dbName='binpackageformat', notNull=True,
5028.1.3 by David Murphy
Removed BinaryPackageFileType & BinaryPackageFormat from canonical.lp.dbschema.
67
                               schema=BinaryPackageFormat)
1288 by Canonical.com Patch Queue Manager
Soyuz Download Package feature implemented for BinaryPackages too.
68
    component = ForeignKey(dbName='component', foreignKey='Component',
3147.2.62 by Celso Providelo
Applying review comments (take 1)
69
                           notNull=True)
1288 by Canonical.com Patch Queue Manager
Soyuz Download Package feature implemented for BinaryPackages too.
70
    section = ForeignKey(dbName='section', foreignKey='Section', notNull=True)
3147.2.62 by Celso Providelo
Applying review comments (take 1)
71
    priority = EnumCol(dbName='priority', notNull=True,
5028.1.6 by David Murphy
Removed PackagePublishingPriority, PackagePublishingStatus, PackagePublishingPocket, PackageUploadStatus, & PackageUploadCustomFormat from canonical.lp.dbschema.
72
                       schema=PackagePublishingPriority)
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
73
    shlibdeps = StringCol(dbName='shlibdeps')
74
    depends = StringCol(dbName='depends')
75
    recommends = StringCol(dbName='recommends')
76
    suggests = StringCol(dbName='suggests')
77
    conflicts = StringCol(dbName='conflicts')
78
    replaces = StringCol(dbName='replaces')
79
    provides = StringCol(dbName='provides')
5433.2.1 by Celso Providelo
Fixing bug 172308 part 1, populating the new fields in SPR/BPR.
80
    pre_depends = StringCol(dbName='pre_depends')
81
    enhances = StringCol(dbName='enhances')
82
    breaks = StringCol(dbName='breaks')
2416 by Canonical.com Patch Queue Manager
standalone ShipItNG and a lot more new features. r=kiko,stub
83
    essential = BoolCol(dbName='essential', default=False)
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
84
    installedsize = IntCol(dbName='installedsize')
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
85
    architecturespecific = BoolCol(dbName='architecturespecific',
3147.2.62 by Celso Providelo
Applying review comments (take 1)
86
                                   notNull=True)
7675.795.2 by Jelmer Vernooij
Add model code for homepage fields.
87
    homepage = StringCol(dbName='homepage')
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
88
    datecreated = UtcDateTimeCol(notNull=True, default=UTC_NOW)
7675.752.13 by William Grant
s/ddeb_package/debug_package/. It's more obvious and general.
89
    debug_package = ForeignKey(dbName='debug_package',
7675.752.2 by William Grant
Add (I)BPR.ddeb_package.
90
                              foreignKey='BinaryPackageRelease')
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
91
7675.786.3 by Jelmer Vernooij
Add tests for user_defined_fields in BinaryPackageRelease.
92
    _user_defined_fields = StringCol(dbName='user_defined_fields')
93
94
    def __init__(self, *args, **kwargs):
95
        if 'user_defined_fields' in kwargs:
96
            kwargs['_user_defined_fields'] = simplejson.dumps(
97
                kwargs['user_defined_fields'])
98
            del kwargs['user_defined_fields']
7675.786.8 by Jelmer Vernooij
Review feedback from Michael.
99
        super(BinaryPackageRelease, self).__init__(*args, **kwargs)
7675.786.3 by Jelmer Vernooij
Add tests for user_defined_fields in BinaryPackageRelease.
100
101
    @property
102
    def user_defined_fields(self):
103
        """See `IBinaryPackageRelease`."""
104
        if self._user_defined_fields is None:
105
            return []
106
        return simplejson.loads(self._user_defined_fields)
107
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
108
    @property
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
109
    def title(self):
4622.2.3 by Celso Providelo
applying review comments [r=barry].
110
        """See `IBinaryPackageRelease`."""
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
111
        return '%s-%s' % (self.binarypackagename.name, self.version)
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
112
113
    @property
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
114
    def name(self):
4622.2.3 by Celso Providelo
applying review comments [r=barry].
115
        """See `IBinaryPackageRelease`."""
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
116
        return self.binarypackagename.name
117
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
118
    @property
119
    def distributionsourcepackagerelease(self):
4622.2.3 by Celso Providelo
applying review comments [r=barry].
120
        """See `IBinaryPackageRelease`."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
121
        # import here to avoid circular import problems
8294.6.1 by Julian Edwards
First stab at code-reorg. Still got a discrepancy on stuff I assigned to registry but not migrated yet.
122
        from lp.soyuz.model.distributionsourcepackagerelease \
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
123
            import DistributionSourcePackageRelease
124
        return DistributionSourcePackageRelease(
125
            distribution=self.build.distribution,
7675.687.82 by Michael Nelson
Fixed for doc/binarypackagerelease.txt.
126
            sourcepackagerelease=self.build.source_package_release)
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
127
2908.4.9 by Guilherme Salgado
Implementation of the mirror prober and a bunch other things
128
    @property
129
    def sourcepackagename(self):
4622.2.3 by Celso Providelo
applying review comments [r=barry].
130
        """See `IBinaryPackageRelease`."""
7675.687.82 by Michael Nelson
Fixed for doc/binarypackagerelease.txt.
131
        return self.build.source_package_release.sourcepackagename.name
2908.4.9 by Guilherme Salgado
Implementation of the mirror prober and a bunch other things
132
4622.2.2 by Celso Providelo
Including 'newness' flag on queue item filelist. Getting code a little bit more organized with the addition of IBPR.is_new with good reflects in scripts/queue.py.
133
    @property
134
    def is_new(self):
4622.2.3 by Celso Providelo
applying review comments [r=barry].
135
        """See `IBinaryPackageRelease`."""
7675.687.82 by Michael Nelson
Fixed for doc/binarypackagerelease.txt.
136
        distroarchseries = self.build.distro_arch_series
4622.2.3 by Celso Providelo
applying review comments [r=barry].
137
        distroarchseries_binary_package = distroarchseries.getBinaryPackage(
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
138
            self.binarypackagename)
4622.2.3 by Celso Providelo
applying review comments [r=barry].
139
        return distroarchseries_binary_package.currentrelease is None
4622.2.2 by Celso Providelo
Including 'newness' flag on queue item filelist. Getting code a little bit more organized with the addition of IBPR.is_new with good reflects in scripts/queue.py.
140
12301.2.1 by William Grant
Turn BPR.files into a cachedproperty.
141
    @cachedproperty
142
    def files(self):
143
        return list(
144
            Store.of(self).find(BinaryPackageFile, binarypackagerelease=self))
145
2713 by Canonical.com Patch Queue Manager
Various fixes to queue, build etc. add zcml for queue, DB patch included. r=stevea,stub. Also fix dbschema security proxy bug (bug 1971) r=stevea
146
    def addFile(self, file):
4622.2.3 by Celso Providelo
applying review comments [r=barry].
147
        """See `IBinaryPackageRelease`."""
2713 by Canonical.com Patch Queue Manager
Various fixes to queue, build etc. add zcml for queue, DB patch included. r=stevea,stub. Also fix dbschema security proxy bug (bug 1971) r=stevea
148
        determined_filetype = None
149
        if file.filename.endswith(".deb"):
5028.1.3 by David Murphy
Removed BinaryPackageFileType & BinaryPackageFormat from canonical.lp.dbschema.
150
            determined_filetype = BinaryPackageFileType.DEB
2713 by Canonical.com Patch Queue Manager
Various fixes to queue, build etc. add zcml for queue, DB patch included. r=stevea,stub. Also fix dbschema security proxy bug (bug 1971) r=stevea
151
        elif file.filename.endswith(".rpm"):
5028.1.3 by David Murphy
Removed BinaryPackageFileType & BinaryPackageFormat from canonical.lp.dbschema.
152
            determined_filetype = BinaryPackageFileType.RPM
2713 by Canonical.com Patch Queue Manager
Various fixes to queue, build etc. add zcml for queue, DB patch included. r=stevea,stub. Also fix dbschema security proxy bug (bug 1971) r=stevea
153
        elif file.filename.endswith(".udeb"):
5028.1.3 by David Murphy
Removed BinaryPackageFileType & BinaryPackageFormat from canonical.lp.dbschema.
154
            determined_filetype = BinaryPackageFileType.UDEB
8213.5.1 by Celso Providelo
First take for supporting DDEBs uploads in Soyuz. Bug #285205.
155
        elif file.filename.endswith(".ddeb"):
156
            determined_filetype = BinaryPackageFileType.DDEB
157
        else:
158
            raise AssertionError(
159
                'Unsupported file type: %s' % file.filename)
2713 by Canonical.com Patch Queue Manager
Various fixes to queue, build etc. add zcml for queue, DB patch included. r=stevea,stub. Also fix dbschema security proxy bug (bug 1971) r=stevea
160
12301.2.1 by William Grant
Turn BPR.files into a cachedproperty.
161
        del get_property_cache(self).files
3691.62.21 by kiko
Clean up the use of ID/.id in select*By and constructors
162
        return BinaryPackageFile(binarypackagerelease=self,
2713 by Canonical.com Patch Queue Manager
Various fixes to queue, build etc. add zcml for queue, DB patch included. r=stevea,stub. Also fix dbschema security proxy bug (bug 1971) r=stevea
163
                                 filetype=determined_filetype,
3691.62.21 by kiko
Clean up the use of ID/.id in select*By and constructors
164
                                 libraryfile=file)
2713 by Canonical.com Patch Queue Manager
Various fixes to queue, build etc. add zcml for queue, DB patch included. r=stevea,stub. Also fix dbschema security proxy bug (bug 1971) r=stevea
165
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
166
    def override(self, component=None, section=None, priority=None):
4622.2.3 by Celso Providelo
applying review comments [r=barry].
167
        """See `IBinaryPackageRelease`."""
3048.5.25 by Celso Providelo
Fix bug # 30621 (missed author's line in changelog) and statement style in SPR/BPR override method, testing not passing.
168
        if component is not None:
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
169
            self.component = component
3048.5.25 by Celso Providelo
Fix bug # 30621 (missed author's line in changelog) and statement style in SPR/BPR override method, testing not passing.
170
        if section is not None:
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
171
            self.section = section
3048.5.25 by Celso Providelo
Fix bug # 30621 (missed author's line in changelog) and statement style in SPR/BPR override method, testing not passing.
172
        if priority is not None:
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
173
            self.priority = priority
174
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
175
7675.583.1 by William Grant
Add BinaryPackageReleaseDownloadCount interface and model.
176
class BinaryPackageReleaseDownloadCount(Storm):
177
    """See `IBinaryPackageReleaseDownloadCount`."""
178
179
    implements(IBinaryPackageReleaseDownloadCount)
180
    __storm_table__ = 'BinaryPackageReleaseDownloadCount'
181
182
    id = Int(primary=True)
183
    archive_id = Int(name='archive', allow_none=False)
184
    archive = Reference(archive_id, 'Archive.id')
185
    binary_package_release_id = Int(
186
        name='binary_package_release', allow_none=False)
187
    binary_package_release = Reference(
188
        binary_package_release_id, 'BinaryPackageRelease.id')
189
    day = Date(allow_none=False)
190
    country_id = Int(name='country', allow_none=True)
191
    country = Reference(country_id, 'Country.id')
7675.583.3 by William Grant
Add BPRDC.__init__.
192
    count = Int(allow_none=False)
193
194
    def __init__(self, archive, binary_package_release, day, country, count):
7675.583.5 by William Grant
Add missing BPRDC super() call.
195
        super(BinaryPackageReleaseDownloadCount, self).__init__()
7675.583.3 by William Grant
Add BPRDC.__init__.
196
        self.archive = archive
197
        self.binary_package_release = binary_package_release
198
        self.day = day
199
        self.country = country
200
        self.count = count
7675.590.2 by William Grant
Export IBPRDC.
201
202
    @property
203
    def binary_package_name(self):
204
        """See `IBinaryPackageReleaseDownloadCount`."""
205
        return self.binary_package_release.name
206
207
    @property
208
    def binary_package_version(self):
209
        """See `IBinaryPackageReleaseDownloadCount`."""
210
        return self.binary_package_release.version
211