~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/archive.py

[r=benji][bug=795573,
 796233] On DistroSeries:+localpackagediffs ensure that the comment
 form is hidden after adding a new comment to a DistroSeriesDifference,
 prevent empty comments from being submitted,
 and add some animations and effects to make the UI less jarring and easier to
 follow.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    ISlaveStore,
69
69
    IStore,
70
70
    )
 
71
from canonical.launchpad.webapp.authorization import check_permission
71
72
from canonical.launchpad.webapp.interfaces import (
72
73
    DEFAULT_FLAVOR,
73
74
    IStoreSelector,
125
126
    CannotSwitchPrivacy,
126
127
    CannotUploadToPocket,
127
128
    CannotUploadToPPA,
 
129
    ComponentNotFound,
128
130
    default_name_by_purpose,
129
131
    DistroSeriesNotFound,
130
132
    FULL_COMPONENT_SUPPORT,
133
135
    IDistributionArchive,
134
136
    InsufficientUploadRights,
135
137
    InvalidComponent,
 
138
    InvalidExternalDependencies,
136
139
    InvalidPocketForPartnerArchive,
137
140
    InvalidPocketForPPA,
138
141
    IPPA,
143
146
    NoTokensForTeams,
144
147
    PocketNotFound,
145
148
    VersionRequiresName,
 
149
    validate_external_dependencies,
146
150
    )
147
151
from lp.soyuz.interfaces.archivearch import IArchiveArchSet
148
152
from lp.soyuz.interfaces.archiveauthtoken import IArchiveAuthTokenSet
197
201
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
198
202
 
199
203
 
 
204
def storm_validate_external_dependencies(archive, attr, value):
 
205
    assert attr == 'external_dependencies'
 
206
    errors = validate_external_dependencies(value)
 
207
    if len(errors) > 0:
 
208
        raise InvalidExternalDependencies(errors)
 
209
    return value
 
210
 
 
211
 
200
212
class Archive(SQLBase):
201
213
    implements(IArchive, IHasOwner, IHasBuildRecords)
202
214
    _table = 'Archive'
306
318
    # Launchpad and should be re-examined in October 2010 to see if it
307
319
    # is still relevant.
308
320
    external_dependencies = StringCol(
309
 
        dbName='external_dependencies', notNull=False, default=None)
 
321
        dbName='external_dependencies', notNull=False, default=None,
 
322
        storm_validator=storm_validate_external_dependencies)
310
323
 
311
324
    commercial = BoolCol(
312
325
        dbName='commercial', notNull=True, default=False)
483
496
 
484
497
        if name is not None:
485
498
            if exact_match:
486
 
                storm_clauses.append(SourcePackageName.name==name)
 
499
                storm_clauses.append(SourcePackageName.name == name)
487
500
            else:
488
501
                clauses.append(
489
502
                    "SourcePackageName.name LIKE '%%%%' || %s || '%%%%'"
494
507
                raise VersionRequiresName(
495
508
                    "The 'version' parameter can be used only together with"
496
509
                    " the 'name' parameter.")
497
 
            storm_clauses.append(SourcePackageRelease.version==version)
 
510
            storm_clauses.append(SourcePackageRelease.version == version)
498
511
        else:
499
512
            orderBy.insert(1, Desc(SourcePackageRelease.version))
500
513
 
514
527
 
515
528
        if pocket is not None:
516
529
            storm_clauses.append(
517
 
                SourcePackagePublishingHistory.pocket==pocket)
 
530
                SourcePackagePublishingHistory.pocket == pocket)
518
531
 
519
532
        if created_since_date is not None:
520
533
            clauses.append(
529
542
            *orderBy)
530
543
        if not eager_load:
531
544
            return resultset
 
545
 
532
546
        # Its not clear that this eager load is necessary or sufficient, it
533
547
        # replaces a prejoin that had pathological query plans.
534
548
        def eager_load(rows):
609
623
        clauseTables = ['SourcePackageRelease', 'SourcePackageName']
610
624
 
611
625
        order_const = "SourcePackageRelease.version"
612
 
        desc_version_order = SQLConstant(order_const+" DESC")
 
626
        desc_version_order = SQLConstant(order_const + " DESC")
613
627
        orderBy = ['SourcePackageName.name', desc_version_order,
614
628
                   '-SourcePackagePublishingHistory.id']
615
629
 
953
967
        a_dependency = self.getArchiveDependency(dependency)
954
968
        if a_dependency is not None:
955
969
            raise ArchiveDependencyError(
956
 
                "Only one dependency record per archive is supported.")
 
970
                "This dependency is already registered.")
 
971
        if not check_permission('launchpad.View', dependency):
 
972
            raise ArchiveDependencyError(
 
973
                "You don't have permission to use this dependency.")
 
974
            return
 
975
        if dependency.private and not self.private:
 
976
            raise ArchiveDependencyError(
 
977
                "Public PPAs cannot depend on private ones.")
957
978
 
958
979
        if dependency.is_ppa:
959
980
            if pocket is not PackagePublishingPocket.RELEASE:
969
990
            archive=self, dependency=dependency, pocket=pocket,
970
991
            component=component)
971
992
 
 
993
    def _addArchiveDependency(self, dependency, pocket, component=None):
 
994
        """See `IArchive`."""
 
995
        if isinstance(component, basestring):
 
996
            try:
 
997
                component = getUtility(IComponentSet)[component]
 
998
            except NotFoundError as e:
 
999
                raise ComponentNotFound(e)
 
1000
        return self.addArchiveDependency(dependency, pocket, component)
 
1001
 
972
1002
    def getPermissions(self, user, item, perm_type):
973
1003
        """See `IArchive`."""
974
1004
        permission_set = getUtility(IArchivePermissionSet)