当前位置: 首页>>代码示例>>Python>>正文


Python ndb.put_multi方法代码示例

本文整理汇总了Python中google.appengine.ext.ndb.put_multi方法的典型用法代码示例。如果您正苦于以下问题:Python ndb.put_multi方法的具体用法?Python ndb.put_multi怎么用?Python ndb.put_multi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.ext.ndb的用法示例。


在下文中一共展示了ndb.put_multi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: account_rank

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def account_rank(organization):
  account_qry = model.Account.query().filter(model.Account.organization == organization)
  account_dbs, account_cursors = util.get_dbs(
    account_qry,
    order='-stars',
    limit=-1,
  )
  updated_dbs = []
  for index, account_db in enumerate(account_dbs, start=1):
    if index < config.MAX_DB_LIMIT:
      account_db.rank = index
    else:
      account_db.rank = 0
    updated_dbs.append(account_db)

  ndb.put_multi(updated_dbs) 
开发者ID:lipis,项目名称:github-stats,代码行数:18,代码来源:task.py

示例2: init_zoneinfo

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def init_zoneinfo():
    """
    Add each zone info to the datastore. This will overwrite existing zones.

    This must be called before the AppengineTimezoneLoader will work.
    """
    import os, logging
    from zipfile import ZipFile
    zoneobjs = []

    zoneinfo_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
      'zoneinfo.zip'))

    with ZipFile(zoneinfo_path) as zf:
        for zfi in zf.filelist:
            key = ndb.Key('Zoneinfo', zfi.filename, namespace=NDB_NAMESPACE)
            zobj = Zoneinfo(key=key, data=zf.read(zfi))
            zoneobjs.append(zobj)

    logging.info("Adding %d timezones to the pytz-appengine database" %
        len(zoneobjs)
        )

    ndb.put_multi(zoneobjs) 
开发者ID:Schibum,项目名称:sndlatr,代码行数:26,代码来源:__init__.py

示例3: testEventuallyConsistentGlobalQueryResult

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def testEventuallyConsistentGlobalQueryResult(self):
        class TestModel(ndb.Model):
            pass

        user_key = ndb.Key('User', 'ryan')

        # Put two entities
        ndb.put_multi([
            TestModel(parent=user_key),
            TestModel(parent=user_key)
        ])

        # Global query doesn't see the data.
        self.assertEqual(0, TestModel.query().count(3))
        # Ancestor query does see the data.
        self.assertEqual(2, TestModel.query(ancestor=user_key).count(3))
# [END HRD_example_1]

    # [START HRD_example_2] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:21,代码来源:datastore_test.py

示例4: post

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def post(self):
        # Force ndb to use v1 of the model by re-loading it.
        reload(models_v1)

        # Save some example data.
        ndb.put_multi([
            models_v1.Picture(author='Alice', name='Sunset'),
            models_v1.Picture(author='Bob', name='Sunrise')
        ])

        self.response.write("""
        Entities created. <a href="/">View entities</a>.
        """)
# [END add_entities]


# [START update_schema] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:19,代码来源:main.py

示例5: store_specs_from_subscription

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def store_specs_from_subscription(subscription_key, week_start, specs):
    """
    Idempotent function to store meeting specs for this week.
    """
    try:
        current_specs = MeetingSpec.query(
            MeetingSpec.meeting_subscription == subscription_key,
            MeetingSpec.datetime > week_start
        ).fetch()
    except NeedIndexError:
        current_specs = []

    if current_specs:
        return

    ndb.put_multi(specs)
    return specs 
开发者ID:Yelp,项目名称:beans,代码行数:19,代码来源:subscription.py

示例6: test_set_from_run_result

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def test_set_from_run_result(self):
    request = _gen_request()
    result_summary = task_result.new_result_summary(request)
    to_run = task_to_run.new_task_to_run(request, 0)
    run_result = task_result.new_run_result(
        request, to_run, 'localhost', 'abc', {})
    run_result.started_ts = utils.utcnow()
    self.assertTrue(result_summary.need_update_from_run_result(run_result))
    result_summary.modified_ts = utils.utcnow()
    run_result.modified_ts = utils.utcnow()
    run_result.dead_after_ts = utils.utcnow() + datetime.timedelta(
        seconds=request.bot_ping_tolerance_secs)
    ndb.transaction(lambda: ndb.put_multi((result_summary, run_result)))

    self.assertTrue(result_summary.need_update_from_run_result(run_result))
    ndb.transaction(
        lambda: result_summary.set_from_run_result(run_result, request))
    ndb.transaction(lambda: ndb.put_multi([result_summary]))

    self.assertFalse(result_summary.need_update_from_run_result(run_result)) 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:task_result_test.py

示例7: test_run_result_timeout

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def test_run_result_timeout(self):
    request = _gen_request()
    result_summary = task_result.new_result_summary(request)
    result_summary.modified_ts = utils.utcnow()
    ndb.transaction(result_summary.put)
    to_run = task_to_run.new_task_to_run(request, 0)
    run_result = task_result.new_run_result(
        request, to_run, 'localhost', 'abc', {})
    run_result.state = task_result.State.TIMED_OUT
    run_result.duration = 0.1
    run_result.exit_code = -1
    run_result.started_ts = utils.utcnow()
    run_result.completed_ts = run_result.started_ts
    run_result.modified_ts = run_result.started_ts
    ndb.transaction(
        lambda: result_summary.set_from_run_result(run_result, request))
    ndb.transaction(lambda: ndb.put_multi((run_result, result_summary)))
    run_result = run_result.key.get()
    result_summary = result_summary.key.get()
    self.assertEqual(True, run_result.failure)
    self.assertEqual(True, result_summary.failure) 
开发者ID:luci,项目名称:luci-py,代码行数:23,代码来源:task_result_test.py

示例8: test_append_output_max_chunk

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def test_append_output_max_chunk(self):
    # Ensures that data is dropped.
    # Force tedious chunking.
    self.mock(task_result.TaskOutput, 'CHUNK_SIZE', 2)
    self.mock(task_result.TaskOutput, 'PUT_MAX_CHUNKS', 16)
    self.assertEqual(2*16, task_result.TaskOutput.PUT_MAX_CONTENT())

    run_result = _gen_run_result()

    calls = []
    self.mock(logging, 'warning', lambda *args: calls.append(args))
    max_chunk = 'x' * task_result.TaskOutput.PUT_MAX_CONTENT()
    entities = run_result.append_output(max_chunk, 0)
    self.assertEqual(task_result.TaskOutput.PUT_MAX_CHUNKS, len(entities))
    ndb.put_multi(entities)
    self.assertEqual([], calls)

    # Try with PUT_MAX_CONTENT + 1 bytes, so the last byte is discarded.
    entities = run_result.append_output(max_chunk + 'x', 0)
    self.assertEqual(task_result.TaskOutput.PUT_MAX_CHUNKS, len(entities))
    ndb.put_multi(entities)
    self.assertEqual(1, len(calls))
    self.assertTrue(calls[0][0].startswith('Dropping '), calls[0][0])
    self.assertEqual(1, calls[0][1]) 
开发者ID:luci,项目名称:luci-py,代码行数:26,代码来源:task_result_test.py

示例9: test_append_output_partial_far_split

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def test_append_output_partial_far_split(self):
    # Missing, writing happens on two different TaskOutputChunk entities.
    self.mock(task_result.TaskOutput, 'CHUNK_SIZE', 16)
    run_result = _gen_run_result()
    ndb.put_multi(run_result.append_output(
        'FooBar', 2 * task_result.TaskOutput.CHUNK_SIZE - 3))
    expected_output = (
        '\x00' * (task_result.TaskOutput.CHUNK_SIZE * 2 - 3) + 'FooBar')
    self.assertEqual(expected_output, run_result.get_output(0, 0))
    expected = [
        {
            'chunk': '\x00' * (task_result.TaskOutput.CHUNK_SIZE - 3) + 'Foo',
            'gaps': [0, 13],
        },
        {
            'chunk': 'Bar',
            'gaps': []
        },
    ]
    self.assertTaskOutputChunk(expected) 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:task_result_test.py

示例10: test_append_output_overwrite

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def test_append_output_overwrite(self):
    # Overwrite previously written data.
    # Force tedious chunking.
    self.mock(task_result.TaskOutput, 'CHUNK_SIZE', 2)
    run_result = _gen_run_result()
    ndb.put_multi(run_result.append_output('FooBar', 0))
    ndb.put_multi(run_result.append_output('X', 3))
    self.assertEqual('FooXar', run_result.get_output(0, 0))
    self.assertTaskOutputChunk([
        {
            'chunk': 'Fo',
            'gaps': []
        },
        {
            'chunk': 'oX',
            'gaps': []
        },
        {
            'chunk': 'ar',
            'gaps': []
        },
    ]) 
开发者ID:luci,项目名称:luci-py,代码行数:24,代码来源:task_result_test.py

示例11: test_append_output_reverse_order_second_chunk

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def test_append_output_reverse_order_second_chunk(self):
    # Write the data in reverse order in multiple calls.
    self.mock(task_result.TaskOutput, 'CHUNK_SIZE', 16)
    run_result = _gen_run_result()
    ndb.put_multi(run_result.append_output(
        'Wow', task_result.TaskOutput.CHUNK_SIZE + 11))
    ndb.put_multi(run_result.append_output(
        'Foo', task_result.TaskOutput.CHUNK_SIZE + 8))
    ndb.put_multi(run_result.append_output(
        'Baz', task_result.TaskOutput.CHUNK_SIZE + 0))
    ndb.put_multi(
        run_result.append_output('Bar', task_result.TaskOutput.CHUNK_SIZE + 4))
    expected_output = (
        task_result.TaskOutput.CHUNK_SIZE * '\x00' + 'Baz\x00Bar\x00FooWow')
    self.assertEqual(expected_output, run_result.get_output(0, 0))
    self.assertTaskOutputChunk([{
        'chunk': 'Baz\x00Bar\x00FooWow',
        'gaps': [3, 4, 7, 8]
    }]) 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:task_result_test.py

示例12: PutResource

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def PutResource(url, etag, content):
  """Persist a resource."""
  key = ndb.Key(Resource, url, namespace=settings.PLAYGROUND_NAMESPACE)
  keys = ndb.Query(ancestor=key).fetch(keys_only=True)
  ndb.delete_multi(keys)
  resource = Resource(id=url, etag=etag,
                      namespace=settings.PLAYGROUND_NAMESPACE)
  if len(content) <= _MAX_RAW_PROPERTY_BYTES:
    resource.content = content
    resource.put()
    return
  chunks = [content[i:i + _MAX_RAW_PROPERTY_BYTES]
            for i in range(0, len(content), _MAX_RAW_PROPERTY_BYTES)]
  entities = [ResourceChunk(id=i + 1, parent=resource.key, content=chunks[i])
              for i in range(0, len(chunks))]
  entities.append(resource)
  ndb.put_multi(entities) 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:19,代码来源:model.py

示例13: AdoptProjects

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def AdoptProjects(dst_user_id, src_user_id):
  """Transfer project ownership to a new user."""

  @ndb.transactional(xg=True)
  def _AdoptProject(project_key, dst_user_key, src_user_key):
    prj, dst_user, src_user = ndb.get_multi([project_key, dst_user_key,
                                             src_user_key])
    if project_key not in src_user.projects:
      # another concurrent request and transaction beat us to it
      return
    src_user.projects.remove(project_key)
    dst_user.projects.append(project_key)
    prj.owner = dst_user_key.id()
    prj.writers.remove(src_user_key.id())
    prj.writers.append(dst_user_key.id())
    ndb.put_multi([prj, dst_user, src_user])

  src_user = GetUser(src_user_id)
  if not src_user or not src_user.projects:
    return
  dst_user = GetOrCreateUser(dst_user_id)
  for project_key in src_user.projects:
    # slow, but transactionable
    _AdoptProject(project_key, dst_user.key, src_user.key) 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:26,代码来源:model.py

示例14: testGet_Active_MultipleOverlapping

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def testGet_Active_MultipleOverlapping(self):

    # Create two active Alerts which overlap at the current time.
    alert_entity_1 = _CreateAlert(-10)
    alert_entity_2 = _CreateAlert(-5, end_hours=5)
    ndb.put_multi([alert_entity_1, alert_entity_2])
    self.assertEntityCount(alert.Alert, 2)

    with self.LoggedInUser():
      response = self.testapp.get(self.ROUTE)

    alert_dict = alert_entity_2.to_dict()

    self.assertEntityCount(alert.Alert, 2)
    self.assertMemcacheContains(
        alerts._CreateMemcacheKey('appdetail', 'windows'), alert_dict)
    self.assertEqual(httplib.OK, response.status_int)
    self.assertResponseContains(response, alert_dict) 
开发者ID:google,项目名称:upvote,代码行数:20,代码来源:alerts_test.py

示例15: testMultipleEvents_DifferentUserTxns

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import put_multi [as 别名]
def testMultipleEvents_DifferentUserTxns(self):
    self.PatchSetting(
        'EVENT_CREATION', constants.EVENT_CREATION.EXECUTING_USER)
    event1 = self._CreateEvent('the-sha256')
    event2 = event1.copy()
    event2[EVENT_UPLOAD.EXECUTING_USER] = 'anotheruser'
    event2[EVENT_UPLOAD.LOGGED_IN_USERS] = ['anotheruser']

    with mock.patch.object(sync.ndb, 'put_multi_async') as put_multi_mock:
      # It ain't pretty but it works: Wrap put_multi_async such that it behaves
      # like a synchronous version and we have the ability to track its calls.
      def fake_put_multi_async(seq):
        result = ndb.put_multi(seq)
        # Return an ndb.Future that is guaranteed to be done.
        return datastore_utils.GetNoOpFuture(result)
      put_multi_mock.side_effect = fake_put_multi_async

      request_json = {EVENT_UPLOAD.EVENTS: [event1, event2]}
      self.testapp.post_json('/my-uuid', request_json)

      # 1 from creating Certificate entities + 2 from events
      self.assertEqual(3, put_multi_mock.call_count)

    self.assertBigQueryInsertions([TABLE.BINARY] + [TABLE.EXECUTION] * 2) 
开发者ID:google,项目名称:upvote,代码行数:26,代码来源:sync_test.py


注:本文中的google.appengine.ext.ndb.put_multi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。