本文整理汇总了Python中lp.services.database.interfaces.IMasterStore.flush方法的典型用法代码示例。如果您正苦于以下问题:Python IMasterStore.flush方法的具体用法?Python IMasterStore.flush怎么用?Python IMasterStore.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lp.services.database.interfaces.IMasterStore
的用法示例。
在下文中一共展示了IMasterStore.flush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new
# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import flush [as 别名]
def new(distro_series_difference, owner, comment):
"""See `IDistroSeriesDifferenceCommentSource`."""
msgid = make_msgid('distroseriesdifference')
message = Message(
parent=None, owner=owner, rfc822msgid=msgid,
subject=distro_series_difference.title)
MessageChunk(message=message, content=comment, sequence=1)
store = IMasterStore(DistroSeriesDifferenceComment)
dsd_comment = DistroSeriesDifferenceComment()
dsd_comment.distro_series_difference = distro_series_difference
dsd_comment.message = message
comment = store.add(dsd_comment)
store.flush()
return comment
示例2: new
# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import flush [as 别名]
def new(
self, name, description, owner, distroseries=None, related_set=None):
"""See `IPackagesetSet`."""
store = IMasterStore(Packageset)
packagesetgroup = None
if related_set is not None:
# Use the packagesetgroup of the `related_set`.
packagesetgroup = related_set.packagesetgroup
else:
# We create the related internal PackagesetGroup for this
# packageset so that we can later see related package sets across
# distroseries.
packagesetgroup = PackagesetGroup()
packagesetgroup.owner = owner
store.add(packagesetgroup)
if distroseries is None:
ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
distroseries = ubuntu.currentseries
packageset = Packageset()
packageset.packagesetgroup = packagesetgroup
packageset.name = name
packageset.description = description
packageset.owner = owner
packageset.distroseries = distroseries
store.add(packageset)
# We need to ensure that the cached statements are flushed so that
# the duplicate name constraint gets triggered here.
try:
store.flush()
except IntegrityError:
raise DuplicatePackagesetName()
return packageset
示例3: empty
# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import flush [as 别名]
#.........这里部分代码省略.........
WHERE dsd.derived_series = %s
""" % sqlvalues(
self.distroseries.id,
self.distroseries.previous_series.id))
def _create_dsd_jobs(self):
job_source = getUtility(IDistroSeriesDifferenceJobSource)
job_source.massCreateForSeries(self.distroseries)
def _copy_configuration(self):
self.distroseries.backports_not_automatic = any(
parent.backports_not_automatic
for parent in self.derivation_parents)
self.distroseries.include_long_descriptions = any(
parent.include_long_descriptions
for parent in self.derivation_parents)
def _copy_architectures(self):
das_filter = ' AND distroseries IN %s ' % (
sqlvalues([p.id for p in self.derivation_parents]))
if self.arches:
das_filter += ' AND architecturetag IN %s ' % (
sqlvalues(self.arches))
self._store.execute("""
INSERT INTO DistroArchSeries
(distroseries, processor, architecturetag, owner, official,
supports_virtualized)
SELECT %s, processor, architecturetag, %s,
bool_and(official), bool_or(supports_virtualized)
FROM DistroArchSeries WHERE enabled = TRUE %s
GROUP BY processor, architecturetag
""" % (sqlvalues(self.distroseries, self.distroseries.owner)
+ (das_filter, )))
self._store.flush()
def _set_nominatedarchindep(self):
if self.archindep_archtag is None:
# Select the arch-indep builder from the intersection between
# the selected architectures and the list of the parent's
# arch-indep builders.
arch_tag = self._potential_nominated_arches(
self.derivation_parents).pop()
self.distroseries.nominatedarchindep = (
self.distroseries.getDistroArchSeries(arch_tag))
else:
self.distroseries.nominatedarchindep = (
self.distroseries.getDistroArchSeries(self.archindep_archtag))
def _potential_nominated_arches(self, parent_list):
parent_indep_archtags = set(
parent.nominatedarchindep.architecturetag
for parent in parent_list
if parent.nominatedarchindep is not None)
if len(self.arches) == 0:
return parent_indep_archtags
else:
return parent_indep_archtags.intersection(self.arches)
def _copy_packages(self):
# Perform the copies
self._copy_component_section_and_format_selections()
# Prepare the lists of distroarchseries for which binary packages
# shall be copied.
distroarchseries_lists = {}
示例4: DatabaseTransactionPolicy
# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import flush [as 别名]
class DatabaseTransactionPolicy:
"""Context manager for read-only transaction policy.
Use this to define regions of code that explicitly allow or disallow
changes to the database:
# We want to be sure that inspect_data does not inadvertently
# make any changes in the database, but we can't run it on the
# slave store because it doesn't tolerate replication lag.
with DatabaseTransactionPolicy(read_only=True):
inspect_data()
The simplest way to use this is as a special transaction:
* You must commit/abort before entering the policy.
* Exiting the policy through an exception aborts its changes.
* Before completing a read-write policy region, you must commit or abort.
You can also have multiple transactions inside one policy, however; the
policy still applies after a commit or abort.
Policies can be nested--a nested policy overrides the one it's nested in.
After the nested policy has exited, the previous policy applies again:
# This code needs to control the database changes it makes very
# carefully. Most of it is just gathering data, with one quick
# database update at the end.
with DatabaseTransactionPolicy(read_only=True):
data = gather_data()
more_data = figure_stuff_out(data)
# End the ongoing transaction so we can go into our update.
transaction.commit()
# This is the only part where we update the database!
with DatabaseTransactionPolicy(read_only=False):
update_model(data, more_data)
transaction.commit()
# We've got a bit more work to do here, but it doesn't
# affect the database.
write_logs(data)
notify_user(more_data)
"""
db_switch = "DEFAULT_TRANSACTION_READ_ONLY"
def __init__(self, store=None, read_only=False):
"""Create a policy.
Merely creating a policy has no effect. Use it with "with" to affect
writability of database transactions.
:param store: The store to set policy on. Defaults to the main master
store. You don't want to use this on a slave store!
:param read_only: Is this policy read-only?
"""
self.read_only = read_only
if store is None:
self.store = IMasterStore(Person)
else:
self.store = store
def __enter__(self):
"""Enter this policy.
Commits the ongoing transaction, and sets the selected default
read-only policy on the database.
:raise TransactionInProgress: if a transaction was already ongoing.
"""
self._checkNoTransaction("Entered DatabaseTransactionPolicy while in a transaction.")
self.previous_policy = self._getCurrentPolicy()
self._setPolicy(self.read_only)
# Commit should include the policy itself. If this breaks
# because the transaction was already in a failed state before
# we got here, too bad.
transaction.commit()
def __exit__(self, exc_type, *args):
"""Exit this policy.
Commits or aborts, depending on mode of exit, and restores the
previous default read-only policy.
:return: True -- any exception will continue to propagate.
:raise TransactionInProgress: if trying to exit normally from a
read-write policy without closing its transaction first.
"""
successful_exit = exc_type is None
if successful_exit:
# We're going to abort any ongoing transactions, but flush
# first to catch out any writes that we might still be
# caching.
# Cached writes could hide read-only violations, but also
# the start of a transaction that we shouldn't be in.
self._flushPendingWrites()
if not self.read_only:
self._checkNoTransaction(
"Failed to close transaction before leaving read-write " "DatabaseTransactionPolicy."
#.........这里部分代码省略.........