~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
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
7
__all__ = [
8
    'BinaryPackageFile',
9
    'BinaryPackageFileSet',
10085.1.10 by Jonathan Lange
Fix up a great number of dodgy imports.
10
    'SourceFileMixin',
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
11
    'SourcePackageReleaseFile',
12
    ]
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
13
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
14
from sqlobject import ForeignKey
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
15
from zope.interface import implements
2396 by Canonical.com Patch Queue Manager
[r=spiv] launchpad support tracker
16
14606.3.1 by William Grant
Merge canonical.database into lp.services.database.
17
from lp.registry.interfaces.sourcepackage import SourcePackageFileType
18
from lp.services.database.bulk import load_related
19
from lp.services.database.enumcol import EnumCol
20
from lp.services.database.sqlbase import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
21
    SQLBase,
22
    sqlvalues,
23
    )
14578.2.1 by William Grant
Move librarian stuff from canonical.launchpad to lp.services.librarian. canonical.librarian remains untouched.
24
from lp.services.librarian.model import (
13314.2.1 by Jeroen Vermeulen
Prejoins were skewing the query plan for IBinaryPackageFileSet.getByPackageUploadiDs.
25
    LibraryFileAlias,
26
    LibraryFileContent,
27
    )
11411.6.6 by Julian Edwards
move BinaryPackageFormat and BinaryPackageFileType
28
from lp.soyuz.enums import BinaryPackageFileType
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.
29
from lp.soyuz.interfaces.files import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
30
    IBinaryPackageFile,
31
    IBinaryPackageFileSet,
32
    ISourcePackageReleaseFile,
33
    ISourcePackageReleaseFileSet,
34
    )
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
35
36
3686.1.47 by Celso Providelo
Fix bug #53647 (remove ISoyuzFile abstration, use ILibraryFileAlias API instead) and improving pagetests for binarypackages pages.
37
class BinaryPackageFile(SQLBase):
2351 by Canonical.com Patch Queue Manager
[r=bjorn] Fix Soyuz UI bits
38
    """See IBinaryPackageFile """
3686.1.47 by Celso Providelo
Fix bug #53647 (remove ISoyuzFile abstration, use ILibraryFileAlias API instead) and improving pagetests for binarypackages pages.
39
    implements(IBinaryPackageFile)
2351 by Canonical.com Patch Queue Manager
[r=bjorn] Fix Soyuz UI bits
40
    _table = 'BinaryPackageFile'
41
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
42
    binarypackagerelease = ForeignKey(dbName='binarypackagerelease',
43
                                      foreignKey='BinaryPackageRelease',
44
                                      notNull=True)
2351 by Canonical.com Patch Queue Manager
[r=bjorn] Fix Soyuz UI bits
45
    libraryfile = ForeignKey(dbName='libraryfile',
2504 by Canonical.com Patch Queue Manager
Fix a missed table rename from long ago which was breaking binarypackagefile.url. Celso is putting a test into his soyuzfiles test suite for this. in the meantime, r=stevea
46
                             foreignKey='LibraryFileAlias', notNull=True)
2351 by Canonical.com Patch Queue Manager
[r=bjorn] Fix Soyuz UI bits
47
    filetype = EnumCol(dbName='filetype',
48
                       schema=BinaryPackageFileType)
49
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
50
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
51
class BinaryPackageFileSet:
52
    """See `IBinaryPackageFileSet`."""
53
    implements(IBinaryPackageFileSet)
54
55
    def getByPackageUploadIDs(self, package_upload_ids):
56
        """See `IBinaryPackageFileSet`."""
6557.3.5 by Julian Edwards
Fix errant tests when trying to use SQL's 'IN' with empty lists.
57
        if package_upload_ids is None or len(package_upload_ids) == 0:
58
            return []
6422.3.10 by Julian Edwards
Danilo's review comments.
59
        return BinaryPackageFile.select("""
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
60
            PackageUploadBuild.packageupload = PackageUpload.id AND
61
            PackageUpload.id IN %s AND
7675.687.118 by Michael Nelson
xx-queue-pages-delayed-copies.txt
62
            BinaryPackageBuild.id = PackageUploadBuild.build AND
63
            BinaryPackageRelease.build = BinaryPackageBuild.id AND
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
64
            BinaryPackageFile.binarypackagerelease = BinaryPackageRelease.id
65
            """ % sqlvalues(package_upload_ids),
7675.687.118 by Michael Nelson
xx-queue-pages-delayed-copies.txt
66
            clauseTables=["PackageUpload", "PackageUploadBuild",
67
                          "BinaryPackageBuild", "BinaryPackageRelease"],
6422.3.10 by Julian Edwards
Danilo's review comments.
68
            prejoins=["binarypackagerelease", "binarypackagerelease.build",
6557.3.1 by Julian Edwards
Pre-fetch package upload builds and remove a query caused by count() in
69
                      "binarypackagerelease.binarypackagename"])
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
70
13314.2.1 by Jeroen Vermeulen
Prejoins were skewing the query plan for IBinaryPackageFileSet.getByPackageUploadiDs.
71
    def loadLibraryFiles(self, binary_files):
72
        """See `IBinaryPackageFileSet`."""
13314.2.2 by Jeroen Vermeulen
Update and test.
73
        lfas = load_related(LibraryFileAlias, binary_files, ['libraryfileID'])
74
        load_related(LibraryFileContent, lfas, ['contentID'])
13314.2.1 by Jeroen Vermeulen
Prejoins were skewing the query plan for IBinaryPackageFileSet.getByPackageUploadiDs.
75
        return lfas
76
6422.3.2 by Julian Edwards
Cache binary files and packages in one query.
77
7675.424.51 by William Grant
Factor out the orig tarball check into SourceFileMixin.is_orig.
78
class SourceFileMixin:
79
    """Mix-in class for common functionality between source file classes."""
80
81
    @property
82
    def is_orig(self):
83
        return self.filetype in (
84
            SourcePackageFileType.ORIG_TARBALL,
85
            SourcePackageFileType.COMPONENT_ORIG_TARBALL
86
            )
87
88
89
class SourcePackageReleaseFile(SourceFileMixin, SQLBase):
2351 by Canonical.com Patch Queue Manager
[r=bjorn] Fix Soyuz UI bits
90
    """See ISourcePackageFile"""
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
91
3686.1.47 by Celso Providelo
Fix bug #53647 (remove ISoyuzFile abstration, use ILibraryFileAlias API instead) and improving pagetests for binarypackages pages.
92
    implements(ISourcePackageReleaseFile)
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
93
2415 by Canonical.com Patch Queue Manager
[trivial] Fix missing pagetitles, improve our basic test coverage for those pages, and add utilities/check-templates.sh which verifies if all templates are registered and properly pagetitled. Only one page title missing, but that's Salgado's fault
94
    sourcepackagerelease = ForeignKey(foreignKey='SourcePackageRelease',
95
                                      dbName='sourcepackagerelease')
96
    libraryfile = ForeignKey(foreignKey='LibraryFileAlias',
97
                             dbName='libraryfile')
98
    filetype = EnumCol(schema=SourcePackageFileType)
6557.3.3 by Julian Edwards
Add SourcePackageReleaseFileSet and its method getByPackageUploadIDs()
99
100
101
class SourcePackageReleaseFileSet:
102
    """See `ISourcePackageReleaseFileSet`."""
103
    implements(ISourcePackageReleaseFileSet)
104
105
    def getByPackageUploadIDs(self, package_upload_ids):
106
        """See `ISourcePackageReleaseFileSet`."""
6557.3.5 by Julian Edwards
Fix errant tests when trying to use SQL's 'IN' with empty lists.
107
        if package_upload_ids is None or len(package_upload_ids) == 0:
108
            return []
6557.3.3 by Julian Edwards
Add SourcePackageReleaseFileSet and its method getByPackageUploadIDs()
109
        return SourcePackageReleaseFile.select("""
110
            PackageUploadSource.packageupload = PackageUpload.id AND
111
            PackageUpload.id IN %s AND
112
            SourcePackageReleaseFile.sourcepackagerelease =
113
                PackageUploadSource.sourcepackagerelease
114
            """ % sqlvalues(package_upload_ids),
115
            clauseTables=["PackageUpload", "PackageUploadSource"],
116
            prejoins=["libraryfile", "libraryfile.content",
117
                      "sourcepackagerelease",
118
                      "sourcepackagerelease.sourcepackagename"])