1
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
# pylint: disable-msg=E0211,E0213
23
23
from lazr.lifecycle.snapshot import doNotSnapshot
24
24
from lazr.restful.declarations import (
26
25
collection_default_content,
27
26
export_as_webservice_collection,
28
27
export_as_webservice_entry,
29
28
export_operation_as,
30
29
export_read_operation,
32
operation_for_version,
33
31
operation_parameters,
34
32
operation_returns_collection_of,
35
33
operation_returns_entry,
36
34
rename_parameters_as,
39
36
from lazr.restful.fields import (
59
from lp.answers.interfaces.questiontarget import IQuestionTarget
55
from canonical.launchpad import _
56
from canonical.launchpad.interfaces.launchpad import (
60
60
from lp.app.errors import NameLookupFailed
61
61
from lp.app.interfaces.headings import IRootContext
62
62
from lp.app.interfaces.launchpad import (
83
83
ICanGetMilestonesDirectly,
86
from lp.registry.interfaces.oopsreferences import IHasOOPSReferences
87
86
from lp.registry.interfaces.pillar import IPillar
88
from lp.registry.interfaces.role import (
87
from lp.registry.interfaces.role import IHasOwner
93
88
from lp.services.fields import (
128
123
"""IDistribution properties requiring launchpad.Driver permission."""
130
125
def newSeries(name, displayname, title, summary, description,
131
version, previous_series, registrant):
126
version, parent_series, registrant):
132
127
"""Creates a new distroseries."""
135
130
class IDistributionPublic(
136
131
IBugTarget, ICanGetMilestonesDirectly, IHasAppointedDriver,
137
132
IHasBuildRecords, IHasDrivers, IHasMilestones,
138
IHasOOPSReferences, IHasOwner, IHasSecurityContact, IHasSprints,
139
IHasTranslationImports, ITranslationPolicy, IKarmaContext,
140
ILaunchpadUsage, IMakesAnnouncements, IOfficialBugTagTargetPublic,
141
IPillar, IServiceUsage, ISpecificationTarget):
133
IHasOwner, IHasSecurityContact, IHasSprints, IHasTranslationImports,
134
ITranslationPolicy, IKarmaContext, ILaunchpadUsage, IMakesAnnouncements,
135
IOfficialBugTagTargetPublic, IPillar, IServiceUsage,
136
ISpecificationTarget):
142
137
"""Public IDistribution properties."""
144
139
id = Attribute("The distro's unique number.")
212
207
exported_as='domain_name')
213
208
owner = exported(
214
209
PublicPersonChoice(
217
vocabulary='ValidPillarOwner',
218
description=_("The restricted team, moderated team, or person "
219
"who maintains the distribution information in "
210
title=_("Owner"), vocabulary='ValidOwner',
211
description=_("The distro's owner."), required=True))
221
212
registrant = exported(
222
213
PublicPersonChoice(
223
214
title=_("Registrant"), vocabulary='ValidPersonOrTeam',
287
278
uploaders = Attribute(_(
288
279
"ArchivePermission records for uploaders with rights to upload to "
289
280
"this distribution."))
290
package_derivatives_email = TextLine(
291
title=_("Package Derivatives Email Address"),
293
"The email address to send information about updates to packages "
294
"that are derived from another distribution. The sequence "
295
"{package_name} is replaced with the actual package name."),
299
283
currentseries = exported(
356
340
readonly=True, required=False)
358
has_published_sources = Bool(
359
title=_("Has Published Sources"),
360
description=_("True if this distribution has sources published."),
361
readonly=True, required=False)
363
342
def getArchiveIDList(archive=None):
364
343
"""Return a list of archive IDs suitable for sqlvalues() or quote().
406
385
`IDistroSeries.version`.
409
# This API is specifically for Ensemble's Principia. It does not scale
410
# well to distributions of Ubuntu's scale, and is not intended for it.
411
# Therefore, this should probably never be exposed for a webservice
412
# version other than "devel".
413
@operation_parameters(
415
title=_("Time of last change"),
417
"Return branches that have new tips since this timestamp."),
419
@call_with(user=REQUEST_USER)
420
@export_operation_as(name="getBranchTips")
421
@export_read_operation()
422
@operation_for_version('devel')
423
def getBranchTips(user=None, since=None):
424
"""Return a list of branches which have new tips since a date.
426
Each branch information is a tuple of (branch_unique_name,
427
tip_revision, (official_series*)).
429
So for each branch in the distribution, you'll get the branch unique
430
name, the revision id of tip, and if the branch is official for some
431
series, the list of series name.
433
:param: user: If specified, shows the branches visible to that user.
434
if not specified, only branches visible to the anonymous user are
437
:param since: If specified, limits results to branches modified since
441
388
@operation_parameters(
442
389
name=TextLine(title=_("Name"), required=True))
443
390
@operation_returns_entry(IDistributionMirror)
503
450
:return: list of `IDistroSeries`
453
def getSourcePackageCaches(archive=None):
454
"""The set of all source package info caches for this distribution.
456
If 'archive' is not given it will return all caches stored for the
457
distribution main archives (PRIMARY and PARTNER).
460
def removeOldCacheItems(archive, log):
461
"""Delete any cache records for removed packages.
463
Also purges all existing cache records for disabled archives.
465
:param archive: target `IArchive`.
466
:param log: the context logger object able to print DEBUG level
470
def updateCompleteSourcePackageCache(archive, log, ztm, commit_chunk=500):
471
"""Update the source package cache.
473
Consider every non-REMOVED sourcepackage and entirely skips updates
474
for disabled archives.
476
:param archive: target `IArchive`;
477
:param log: logger object for printing debug level information;
478
:param ztm: transaction used for partial commits, every chunk of
479
'commit_chunk' updates is committed;
480
:param commit_chunk: number of updates before commit, defaults to 500.
482
:return the number packages updated done
485
def updateSourcePackageCache(sourcepackagename, archive, log):
486
"""Update cached source package details.
488
Update cache details for a given ISourcePackageName, including
489
generated binarypackage names, summary and description fti.
490
'log' is required and only prints debug level information.
506
493
@rename_parameters_as(text="source_match")
507
494
@operation_parameters(
508
495
text=TextLine(title=_("Source package name substring match"),
550
537
(a substring of) their binary package names.
553
def guessPublishedSourcePackageName(pkgname):
554
"""Return the "published" SourcePackageName related to pkgname.
556
If pkgname corresponds to a source package that was published in
557
any of the distribution series, that's the SourcePackageName that is
560
If there is any official source package branch linked, then that
561
source package name is returned.
563
Otherwise, try to find a published binary package name and then return
564
the source package name from which it comes from.
566
:raises NotFoundError: when pkgname doesn't correspond to either a
567
published source or binary package name in this distribution.
540
def searchBinaryPackagesFTI(package_name):
541
"""Do an FTI search on binary packages.
543
:param package_name: The binary package name to search for.
544
:return: A result set containing DistributionSourcePackageCache
545
objects for the matching binaries found via an FTI search on
546
DistroSeriesPackageCache.
549
def getFileByName(filename, archive=None, source=True, binary=True):
550
"""Find and return a LibraryFileAlias for the filename supplied.
552
The file returned will be one of those published in the distribution.
554
If searching both source and binary, and the file is found in the
555
binary packages it'll return that over a file for a source package.
557
If 'archive' is not passed the distribution.main_archive is assumed.
559
At least one of source and binary must be true.
561
Raises NotFoundError if it fails to find the named file.
564
def guessPackageNames(pkgname):
565
"""Try and locate source and binary package name objects that
566
are related to the provided name -- which could be either a
567
source or a binary package name. Returns a tuple of
568
(sourcepackagename, binarypackagename) based on the current
569
publishing status of these binary / source packages. Raises
570
NotFoundError if it fails to find any package published with
571
that name in the distribution.
570
574
def getAllPPAs():
638
642
class IDistribution(
639
643
IDistributionEditRestricted, IDistributionPublic, IHasBugSupervisor,
640
IQuestionTarget, IRootContext, IStructuralSubscriptionTarget):
644
IRootContext, IStructuralSubscriptionTarget):
641
645
"""An operating system distribution.
643
647
Launchpadlib example: retrieving the current version of a package in a
709
713
:return: A dict as per `IDistribution.getCurrentSourceReleases`
712
def getDerivedDistributions():
713
"""Find derived distributions.
715
:return: An iterable of all derived distributions (not including
716
Ubuntu, even if it is technically derived from Debian).
720
717
class NoSuchDistribution(NameLookupFailed):
721
718
"""Raised when we try to find a distribution that doesn't exist."""