~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-03 01:24:37 UTC
  • mfrom: (13137.1.11 ppa-api)
  • Revision ID: launchpad@pqm.canonical.com-20110603012437-1hy2195abrbycdtk
[r=allenap][bug=776444,776449] Export PPA dependency APIs

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
    CannotSwitchPrivacy,
126
126
    CannotUploadToPocket,
127
127
    CannotUploadToPPA,
 
128
    ComponentNotFound,
128
129
    default_name_by_purpose,
129
130
    DistroSeriesNotFound,
130
131
    FULL_COMPONENT_SUPPORT,
133
134
    IDistributionArchive,
134
135
    InsufficientUploadRights,
135
136
    InvalidComponent,
 
137
    InvalidExternalDependencies,
136
138
    InvalidPocketForPartnerArchive,
137
139
    InvalidPocketForPPA,
138
140
    IPPA,
143
145
    NoTokensForTeams,
144
146
    PocketNotFound,
145
147
    VersionRequiresName,
 
148
    validate_external_dependencies,
146
149
    )
147
150
from lp.soyuz.interfaces.archivearch import IArchiveArchSet
148
151
from lp.soyuz.interfaces.archiveauthtoken import IArchiveAuthTokenSet
197
200
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
198
201
 
199
202
 
 
203
def storm_validate_external_dependencies(archive, attr, value):
 
204
    assert attr == 'external_dependencies'
 
205
    errors = validate_external_dependencies(value)
 
206
    if len(errors) > 0:
 
207
        raise InvalidExternalDependencies(errors)
 
208
    return value
 
209
 
 
210
 
200
211
class Archive(SQLBase):
201
212
    implements(IArchive, IHasOwner, IHasBuildRecords)
202
213
    _table = 'Archive'
306
317
    # Launchpad and should be re-examined in October 2010 to see if it
307
318
    # is still relevant.
308
319
    external_dependencies = StringCol(
309
 
        dbName='external_dependencies', notNull=False, default=None)
 
320
        dbName='external_dependencies', notNull=False, default=None,
 
321
        storm_validator=storm_validate_external_dependencies)
310
322
 
311
323
    commercial = BoolCol(
312
324
        dbName='commercial', notNull=True, default=False)
483
495
 
484
496
        if name is not None:
485
497
            if exact_match:
486
 
                storm_clauses.append(SourcePackageName.name==name)
 
498
                storm_clauses.append(SourcePackageName.name == name)
487
499
            else:
488
500
                clauses.append(
489
501
                    "SourcePackageName.name LIKE '%%%%' || %s || '%%%%'"
494
506
                raise VersionRequiresName(
495
507
                    "The 'version' parameter can be used only together with"
496
508
                    " the 'name' parameter.")
497
 
            storm_clauses.append(SourcePackageRelease.version==version)
 
509
            storm_clauses.append(SourcePackageRelease.version == version)
498
510
        else:
499
511
            orderBy.insert(1, Desc(SourcePackageRelease.version))
500
512
 
514
526
 
515
527
        if pocket is not None:
516
528
            storm_clauses.append(
517
 
                SourcePackagePublishingHistory.pocket==pocket)
 
529
                SourcePackagePublishingHistory.pocket == pocket)
518
530
 
519
531
        if created_since_date is not None:
520
532
            clauses.append(
529
541
            *orderBy)
530
542
        if not eager_load:
531
543
            return resultset
 
544
 
532
545
        # Its not clear that this eager load is necessary or sufficient, it
533
546
        # replaces a prejoin that had pathological query plans.
534
547
        def eager_load(rows):
609
622
        clauseTables = ['SourcePackageRelease', 'SourcePackageName']
610
623
 
611
624
        order_const = "SourcePackageRelease.version"
612
 
        desc_version_order = SQLConstant(order_const+" DESC")
 
625
        desc_version_order = SQLConstant(order_const + " DESC")
613
626
        orderBy = ['SourcePackageName.name', desc_version_order,
614
627
                   '-SourcePackagePublishingHistory.id']
615
628
 
970
983
            archive=self, dependency=dependency, pocket=pocket,
971
984
            component=component)
972
985
 
 
986
    def _addArchiveDependency(self, dependency, pocket, component=None):
 
987
        """See `IArchive`."""
 
988
        if isinstance(component, basestring):
 
989
            try:
 
990
                component = getUtility(IComponentSet)[component]
 
991
            except NotFoundError as e:
 
992
                raise ComponentNotFound(e)
 
993
        return self.addArchiveDependency(dependency, pocket, component)
 
994
 
973
995
    def getPermissions(self, user, item, perm_type):
974
996
        """See `IArchive`."""
975
997
        permission_set = getUtility(IArchivePermissionSet)