129
130
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
130
131
from lp.blueprints.interfaces.specification import ISpecification
131
132
from lp.bugs.interfaces.bugtask import IBugTask
132
from lp.registry.interfaces.distribution import IDistribution
133
from lp.registry.interfaces.distribution import (
133
137
from lp.registry.interfaces.distributionsourcepackage import (
134
138
IDistributionSourcePackage,
634
638
Person.id.is_in(public_inner_textual_select),
635
639
Person.visibility == PersonVisibility.PUBLIC,
636
640
Person.merged == None,
637
Or(# A valid person-or-team is either a team...
641
Or( # A valid person-or-team is either a team...
638
642
# Note: 'Not' due to Bug 244768.
639
643
Not(Person.teamowner == None),
640
644
# Or a person who has a preferred email address.
831
835
SQL("Person.id = MatchingPerson.id"),
833
And(# A public person or team
837
And( # A public person or team
834
838
Person.visibility == PersonVisibility.PUBLIC,
835
839
Person.merged == None,
836
Or(# A valid person-or-team is either a team...
840
Or( # A valid person-or-team is either a team...
837
841
# Note: 'Not' due to Bug 244768.
838
842
Not(Person.teamowner == None),
839
843
# Or a person who has preferred email address.
1980
1984
implements(IHugeVocabulary)
1981
1985
displayname = 'Select a package'
1982
step_title = 'Search'
1986
step_title = 'Search by name or distro/name'
1984
1988
def __init__(self, context):
1985
1989
self.context = context
1990
# Avoid circular import issues.
1991
from lp.answers.interfaces.question import IQuestion
1992
if IBugTask.providedBy(context) or IQuestion.providedBy(context):
1993
target = context.target
1997
self.distribution = IDistribution(target)
1999
self.distribution = None
1987
def __contains__(self, obj):
2001
def __contains__(self, spn_or_dsp):
2003
self.toTerm(spn_or_dsp)
1990
2008
def __iter__(self):
1993
2011
def __len__(self):
1996
def toTerm(self, spn):
2014
def getDistributionAndPackageName(self, text):
2015
"Return the distribution and package name from the parsed text."
2016
# Match the toTerm() format, but also use it to select a distribution.
2019
distro_name, text = text.split('/', 1)
2020
distribution = getUtility(IDistributionSet).getByName(distro_name)
2021
if distribution is None:
2022
distribution = self.distribution
2023
return distribution, text
2025
def toTerm(self, spn_or_dsp, distribution=None):
1997
2026
"""See `IVocabulary`."""
1998
dsp = self.context.getSourcePackage(spn)
1999
if dsp.publishing_history:
2028
if IDistributionSourcePackage.providedBy(spn_or_dsp):
2030
distribution = spn_or_dsp.distribution
2032
distribution = distribution or self.distribution
2033
if distribution is not None and spn_or_dsp is not None:
2034
dsp = distribution.getSourcePackage(spn_or_dsp)
2000
2036
binaries = dsp.publishing_history[0].getBuiltBinaries()
2001
summary = ', '.join(
2002
[binary.binary_package_name for binary in binaries])
2004
summary = "Not yet built."
2005
token = '%s/%s' % (dsp.distribution.name, dsp.name)
2006
return SimpleTerm(summary, token, dsp.name)
2037
binary_names = [binary.binary_package_name for binary in binaries]
2038
if binary_names != []:
2039
summary = ', '.join(binary_names)
2041
summary = 'Not yet built.'
2042
token = '%s/%s' % (dsp.distribution.name, dsp.name)
2043
return SimpleTerm(dsp.sourcepackagename, token, summary)
2044
except (IndexError, AttributeError):
2045
# Either the DSP was None or there is no publishing history.
2046
raise LookupError(distribution, spn_or_dsp)
2008
def getTerm(self, spn):
2048
def getTerm(self, spn_or_dsp):
2009
2049
"""See `IBaseVocabulary`."""
2010
return self.toTerm(spn)
2050
return self.toTerm(spn_or_dsp)
2012
2052
def getTermByToken(self, token):
2013
2053
"""See `IVocabularyTokenized`."""
2054
distribution, package_name = self.getDistributionAndPackageName(token)
2055
return self.toTerm(package_name, distribution)
2016
2057
def searchForTerms(self, query=None):
2017
2058
"""See `IHugeVocabulary`."""
2018
distribution = self.context
2060
return EmptyResultSet()
2061
distribution, query = self.getDistributionAndPackageName(query)
2062
if distribution is None:
2063
# This could failover to ubuntu, but that is non-obvious. The
2064
# Python widget must set the default distribution and the JS
2065
# widget must encourage the <distro>/<package> search format.
2066
return EmptyResultSet()
2021
2067
search_term = unicode(query)
2022
2068
store = IStore(SourcePackagePublishingHistory)
2023
2069
spns = store.using(