本文整理汇总了Python中lp.services.database.interfaces.IStore类的典型用法代码示例。如果您正苦于以下问题:Python IStore类的具体用法?Python IStore怎么用?Python IStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_contributions
def get_contributions(pofile, potmsgset_ids):
"""Map all users' most recent contributions to a `POFile`.
Returns a dict mapping `Person` id to the creation time of their most
recent `TranslationMessage` in `POFile`.
This leaves some small room for error: a contribution that is masked by
a diverged entry in this POFile will nevertheless produce a
POFileTranslator record. Fixing that would complicate the work more than
it is probably worth.
:param pofile: The `POFile` to find contributions for.
:param potmsgset_ids: The ids of the `POTMsgSet`s to look for, as returned
by `get_potmsgset_ids`.
"""
store = IStore(pofile)
language_id = pofile.language.id
template_id = pofile.potemplate.id
contribs = store.find(
(TranslationMessage.submitterID, TranslationMessage.date_created),
TranslationMessage.potmsgsetID.is_in(potmsgset_ids),
TranslationMessage.languageID == language_id,
TranslationMessage.msgstr0 != None,
Coalesce(TranslationMessage.potemplateID, template_id) ==
template_id)
contribs = contribs.config(distinct=(TranslationMessage.submitterID,))
contribs = contribs.order_by(
TranslationMessage.submitterID, Desc(TranslationMessage.date_created))
return dict(contribs)
示例2: getByName
def getByName(self, name, distroseries=None):
"""See `IPackagesetSet`."""
store = IStore(Packageset)
if not isinstance(name, unicode):
name = unicode(name, 'utf-8')
ubuntu = getUtility(IDistributionSet).getByName(u'ubuntu')
extra_args = []
if distroseries is not None:
# If the user just passed a distro series name, look it up.
if isinstance(distroseries, basestring):
try:
distroseries = ubuntu[distroseries]
except NotFoundError:
raise NoSuchPackageSet(distroseries)
extra_args.append(Packageset.distroseries == distroseries)
else:
extra_args.append(Packageset.distroseries == ubuntu.currentseries)
package_set = store.find(
Packageset, Packageset.name == name, *extra_args).one()
if package_set is None:
raise NoSuchPackageSet(name)
return package_set
示例3: calculateSourceOverrides
def calculateSourceOverrides(self, archive, distroseries, pocket, spns,
source_component=None, include_deleted=False):
def eager_load(rows):
bulk.load(Component, (row[1] for row in rows))
bulk.load(Section, (row[2] for row in rows))
store = IStore(SourcePackagePublishingHistory)
already_published = DecoratedResultSet(
store.find(
(SourcePackagePublishingHistory.sourcepackagenameID,
SourcePackagePublishingHistory.componentID,
SourcePackagePublishingHistory.sectionID),
SourcePackagePublishingHistory.archiveID == archive.id,
SourcePackagePublishingHistory.distroseriesID ==
distroseries.id,
SourcePackagePublishingHistory.status.is_in(
self.getExistingPublishingStatuses(include_deleted)),
SourcePackagePublishingHistory.sourcepackagenameID.is_in(
spn.id for spn in spns)).order_by(
SourcePackagePublishingHistory.sourcepackagenameID,
Desc(SourcePackagePublishingHistory.datecreated),
Desc(SourcePackagePublishingHistory.id),
).config(
distinct=(
SourcePackagePublishingHistory.sourcepackagenameID,)),
id_resolver((SourcePackageName, Component, Section)),
pre_iter_hook=eager_load)
return [
SourceOverride(name, component, section)
for (name, component, section) in already_published]
示例4: getByDerivedAndParentSeries
def getByDerivedAndParentSeries(self, derived_series, parent_series):
"""See `IDistroSeriesParentSet`."""
store = IStore(DistroSeriesParent)
return store.find(
DistroSeriesParent,
DistroSeriesParent.parent_series_id == parent_series.id,
DistroSeriesParent.derived_series_id == derived_series.id).one()
示例5: get
def get(ujob_id):
"""Return the named job database class.
:param ujob_id: A tuple of Job.id, module name, class name for the
class to retrieve.
Return derived job class.
"""
job_id, module_name, class_name = ujob_id
bc_module = __import__(module_name, fromlist=[class_name])
db_class = getattr(bc_module, class_name)
factory = getattr(db_class, "makeInstance", None)
if factory is not None:
return factory(job_id)
# This method can be called with two distinct types of Jobs:
# - Jobs that are backed by a DB table with a foreign key onto Job.
# - Jobs that have no backing, and are only represented by a row in
# the Job table, but the class name we are given is the abstract
# job class.
# If there is no __storm_table__, it is the second type, and we have
# to look it up via the Job table.
if getattr(db_class, "__storm_table__", None) is None:
db_job = IStore(Job).find(Job, Job.id == job_id).one()
# Job.makeDerived() would be a mess of circular imports, so it is
# cleaner to just return the bare Job wrapped in the class.
return db_class(db_job)
# Otherwise, we have the concrete DB class, so use its FK.
db_job = IStore(db_class).find(db_class, db_class.job == job_id).one()
if db_job is None:
return None
return db_job.makeDerived()
示例6: most_recent_comments
def most_recent_comments(dsds):
"""The most recent comments for the given `DistroSeriesDifference`s.
Returns an `IResultSet` that yields a single column of
`DistroSeriesDifferenceComment`.
:param dsds: An iterable of `DistroSeriesDifference` instances.
"""
columns = (
DistroSeriesDifferenceComment,
Message,
)
conditions = And(
DistroSeriesDifferenceComment
.distro_series_difference_id.is_in(dsd.id for dsd in dsds),
Message.id == DistroSeriesDifferenceComment.message_id)
order_by = (
DistroSeriesDifferenceComment.distro_series_difference_id,
Desc(DistroSeriesDifferenceComment.id),
)
distinct_on = (
DistroSeriesDifferenceComment.distro_series_difference_id,
)
store = IStore(DistroSeriesDifferenceComment)
comments = store.find(
columns, conditions).order_by(*order_by).config(distinct=distinct_on)
return DecoratedResultSet(comments, itemgetter(0))
示例7: packagesetsForSource
def packagesetsForSource(
self, archive, sourcepackagename, direct_permissions=True):
"""See `IArchivePermissionSet`."""
sourcepackagename = self._nameToSourcePackageName(sourcepackagename)
store = IStore(ArchivePermission)
if direct_permissions:
origin = SQL('ArchivePermission, PackagesetSources')
rset = store.using(origin).find(ArchivePermission, SQL('''
ArchivePermission.packageset = PackagesetSources.packageset
AND PackagesetSources.sourcepackagename = ?
AND ArchivePermission.archive = ?
''', (sourcepackagename.id, archive.id)))
else:
origin = SQL(
'ArchivePermission, PackagesetSources, '
'FlatPackagesetInclusion')
rset = store.using(origin).find(ArchivePermission, SQL('''
ArchivePermission.packageset = FlatPackagesetInclusion.parent
AND PackagesetSources.packageset =
FlatPackagesetInclusion.child
AND PackagesetSources.sourcepackagename = ?
AND ArchivePermission.archive = ?
''', (sourcepackagename.id, archive.id)))
return rset
示例8: getDiffsToReleases
def getDiffsToReleases(self, sprs, preload_for_display=False):
"""See `IPackageDiffSet`."""
from lp.registry.model.distribution import Distribution
from lp.soyuz.model.archive import Archive
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
if len(sprs) == 0:
return EmptyResultSet()
spr_ids = [spr.id for spr in sprs]
result = IStore(PackageDiff).find(
PackageDiff, PackageDiff.to_sourceID.is_in(spr_ids))
result.order_by(PackageDiff.to_sourceID,
Desc(PackageDiff.date_requested))
def preload_hook(rows):
lfas = load(LibraryFileAlias, (pd.diff_contentID for pd in rows))
load(LibraryFileContent, (lfa.contentID for lfa in lfas))
sprs = load(
SourcePackageRelease,
itertools.chain.from_iterable(
(pd.from_sourceID, pd.to_sourceID) for pd in rows))
archives = load(Archive, (spr.upload_archiveID for spr in sprs))
load(Distribution, (a.distributionID for a in archives))
if preload_for_display:
return DecoratedResultSet(result, pre_iter_hook=preload_hook)
else:
return result
示例9: create_multiple_jobs
def create_multiple_jobs(derived_series, parent_series):
"""Create `DistroSeriesDifferenceJob`s between parent and derived series.
:param derived_series: A `DistroSeries` that is assumed to be derived
from another one.
:param parent_series: A `DistroSeries` that is a parent of
`derived_series`.
:return: A list of newly-created `DistributionJob` ids.
"""
store = IStore(SourcePackagePublishingHistory)
spn_ids = store.find(
SourcePackagePublishingHistory.sourcepackagenameID,
SourcePackagePublishingHistory.distroseries == derived_series.id,
SourcePackagePublishingHistory.status.is_in(active_publishing_status))
spn_ids = list(spn_ids)
if len(spn_ids) == 0:
return []
job_ids = Job.createMultiple(store, len(spn_ids))
return bulk.create(
(DistributionJob.distribution, DistributionJob.distroseries,
DistributionJob.job_type, DistributionJob.job_id,
DistributionJob.metadata),
[(derived_series.distribution, derived_series,
DistributionJobType.DISTROSERIESDIFFERENCE, job_id,
make_metadata(spn_id, parent_series.id))
for job_id, spn_id in zip(job_ids, spn_ids)],
get_primary_keys=True)
示例10: load_referencing
def load_referencing(object_type, owning_objects, reference_keys,
extra_conditions=[]):
"""Load objects of object_type that reference owning_objects.
Note that complex types like Person are best loaded through dedicated
helpers that can eager load other related things (e.g. validity for
Person).
:param object_type: The object type to load - e.g. BranchSubscription.
:param owning_objects: The objects which are referenced. E.g. [Branch()]
At this point, all the objects should be of the same type, but that
constraint could be lifted in future.
:param reference_keys: A list of attributes that should be used to select
object_type keys. e.g. ['branchID']
:param extra_conditions: A list of Storm clauses that will be used in the
final query.
:return: A list of object_type where any of reference_keys refered to the
primary key of any of owning_objects.
"""
store = IStore(object_type)
if type(owning_objects) not in (list, tuple):
owning_objects = tuple(owning_objects)
if not owning_objects:
return []
exemplar = owning_objects[0]
primary_key = _primary_key(get_type(exemplar))
attribute = primary_key.name
ids = set(map(attrgetter(attribute), owning_objects))
conditions = []
# Note to future self doing perf tuning: may want to make ids a WITH
# clause.
for column in map(partial(getattr, object_type), reference_keys):
conditions.append(column.is_in(ids))
return list(store.find(object_type, Or(conditions), *extra_conditions))
示例11: create_build
def create_build():
jobset = getUtility(ITranslationTemplatesBuildJobSource)
branch = self.factory.makeBranch()
specific_job = jobset.create(branch)
queue = IStore(BuildQueue).find(
BuildQueue, job=specific_job.job).one()
queue.markAsBuilding(self.factory.makeBuilder())
示例12: all_package_names
def all_package_names(self):
"""See `IHWDriverSet`."""
# XXX Abel Deuring 2009-06-19 The clause package_name != None
# can be removed once bug #306265 is fixed.
result = IStore(HWDriverPackageName).find(HWDriverPackageName, HWDriverPackageName.package_name != None)
result.order_by(HWDriverPackageName.package_name)
return result
示例13: get_files_to_parse
def get_files_to_parse(file_paths):
"""Return an iterator of file and position where reading should start.
The lines read from that position onwards will be the ones that have not
been parsed yet.
:param file_paths: The paths to the files.
"""
store = IStore(ParsedApacheLog)
for file_path in file_paths:
fd, file_size = get_fd_and_file_size(file_path)
first_line = unicode(fd.readline())
parsed_file = store.find(ParsedApacheLog, first_line=first_line).one()
position = 0
if parsed_file is not None:
# This file has been parsed already; we'll now check if there's
# anything in it that hasn't been parsed yet.
if parsed_file.bytes_read >= file_size:
# There's nothing new in it for us to parse, so just skip it.
fd.close()
continue
else:
# This one has stuff we haven't parsed yet, so we'll just
# parse what's new.
position = parsed_file.bytes_read
yield fd, position
示例14: query_pofiletranslator
def query_pofiletranslator(self, pofile, person):
"""Query `POFileTranslator` for a specific record.
:return: Storm result set.
"""
store = IStore(pofile)
return store.find(POFileTranslator, pofile=pofile, person=person)
示例15: getForDistroSeries
def getForDistroSeries(distroseries, since=None,
source_package_name=None):
"""See `IDistroSeriesDifferenceCommentSource`."""
# Avoid circular imports.
from lp.registry.model.distroseriesdifference import (
DistroSeriesDifference,
)
store = IStore(DistroSeriesDifferenceComment)
DSD = DistroSeriesDifference
DSDComment = DistroSeriesDifferenceComment
conditions = [
DSDComment.distro_series_difference_id == DSD.id,
DSD.derived_series_id == distroseries.id,
]
if source_package_name is not None:
conditions += [
SourcePackageName.id == DSD.source_package_name_id,
SourcePackageName.name == source_package_name,
]
if since is not None:
older_messages = store.find(
Message.id, Message.datecreated < since).order_by(
Desc(Message.datecreated))
preceding_message = older_messages.first()
if preceding_message is not None:
conditions.append(DSDComment.message_id > preceding_message)
return store.find(DSDComment, *conditions).order_by(
DSDComment.message_id)