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


Python db.put方法代码示例

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


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

示例1: run

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def run(self):
    if model.MissingDataUsersSecondary.all().count() > 0:
      raise Error('Must clear MissingDataUsersSecondary before refreshing')

    # Load the whole data model. As of 2014-05-20, this takes around
    # 30 seconds, out of our allotted 10 minutes.
    logging.info('Load all users')
    users = [u.email for u in model.User.all()
             if not (u.occupation and u.employer)]

    logging.info('Load all Pledges')
    pledges = list(model.Pledge.all())
    logging.info('Load all WpPledges')
    wp_pledges = list(model.WpPledge.all())
    logging.info('Done loading')

    pledge_sum = defaultdict(int)
    for p in pledges + wp_pledges:
      pledge_sum[p.email] += p.amountCents

    users = [u for u in users if pledge_sum[u] >= 20000]
    users = [model.MissingDataUsersSecondary(email=u, amountCents=pledge_sum[u])
             for u in users]
    db.put(users)
    logging.info('Done') 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:27,代码来源:commands.py

示例2: _drop_gracefully

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def _drop_gracefully(self):
    """Drop worker task gracefully.

    Set current shard_state to failed. Controller logic will take care of
    other shards and the entire MR.
    """
    shard_id = self.request.headers[util._MR_SHARD_ID_TASK_HEADER]
    mr_id = self.request.headers[util._MR_ID_TASK_HEADER]
    shard_state, mr_state = db.get([
        model.ShardState.get_key_by_shard_id(shard_id),
        model.MapreduceState.get_key_by_job_id(mr_id)])

    if shard_state and shard_state.active:
      shard_state.set_for_failure()
      config = util.create_datastore_write_config(mr_state.mapreduce_spec)
      shard_state.put(config=config) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:18,代码来源:handlers.py

示例3: _save_states

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def _save_states(self, state, serialized_readers_entity):
    """Run transaction to save state.

    Args:
      state: a model.MapreduceState entity.
      serialized_readers_entity: a model._HugeTaskPayload entity containing
        json serialized input readers.

    Returns:
      False if a fatal error is encountered and this task should be dropped
    immediately. True if transaction is successful. None if a previous
    attempt of this same transaction has already succeeded.
    """
    mr_id = state.key().id_or_name()
    fresh_state = model.MapreduceState.get_by_job_id(mr_id)
    if not self._check_mr_state(fresh_state, mr_id):
      return False
    if fresh_state.active_shards != 0:
      logging.warning(
          "Mapreduce %s already has active shards. Looks like spurious task "
          "execution.", mr_id)
      return None
    config = util.create_datastore_write_config(state.mapreduce_spec)
    db.put([state, serialized_readers_entity], config=config)
    return True 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:27,代码来源:handlers.py

示例4: _import_backup

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def _import_backup(gs_handle):
  """Import backup from `gs_handle` to the current project."""
  bucket_name, path = parse_gs_handle(gs_handle)
  file_content = get_gs_object(bucket_name, path)
  entities = parse_backup_info_file(file_content)
  original_backup_info = entities.next()
  entity = datastore.Entity(BackupInformation.kind())
  entity.update(original_backup_info)
  backup_info = BackupInformation.from_entity(entity)
  if original_backup_info.key().app() != os.getenv('APPLICATION_ID'):
    backup_info.original_app = original_backup_info.key().app()

  def tx():
    backup_info.put(force_writes=True)
    kind_files_models = []
    for entity in entities:
      kind_files = backup_info.create_kind_backup_files(
          entity.key().name(), entity['files'])
      kind_files_models.append(kind_files)
    db.put(kind_files_models, force_writes=True)
  db.run_in_transaction(tx)
  return str(backup_info.key()) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:24,代码来源:backup_handler.py

示例5: _perform_backup_complete

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def _perform_backup_complete(
    operation, job_id, kind, backup_info_pk, gcs_path_prefix, filenames, queue):
  backup_info = BackupInformation.get(backup_info_pk)
  if backup_info:
    if job_id in backup_info.active_jobs:
      backup_info.active_jobs.remove(job_id)
      backup_info.completed_jobs = list(
          set(backup_info.completed_jobs + [job_id]))


    filenames = [GCSUtil.add_gs_prefix_if_missing(name) for name in filenames]
    kind_backup_files = backup_info.get_kind_backup_files([kind])[0]
    if kind_backup_files:
      kind_backup_files.files = list(set(kind_backup_files.files + filenames))
    else:
      kind_backup_files = backup_info.create_kind_backup_files(kind, filenames)
    db.put((backup_info, kind_backup_files), force_writes=True)
    if operation.status == utils.DatastoreAdminOperation.STATUS_COMPLETED:
      deferred.defer(finalize_backup_info, backup_info.key(),
                     gcs_path_prefix,
                     _url=config.DEFERRED_PATH,
                     _queue=queue,
                     _transactional=True)
  else:
    logging.warn('BackupInfo was not found for %s', backup_info_pk) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:27,代码来源:backup_handler.py

示例6: _create_and_save_state

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def _create_and_save_state(cls, mapreduce_spec, _app):
    """Save mapreduce state to datastore.

    Save state to datastore so that UI can see it immediately.

    Args:
      mapreduce_spec: model.MapreduceSpec,
      _app: app id if specified. None otherwise.

    Returns:
      The saved Mapreduce state.
    """
    state = model.MapreduceState.create_new(mapreduce_spec.mapreduce_id)
    state.mapreduce_spec = mapreduce_spec
    state.active = True
    state.active_shards = 0
    if _app:
      state.app_id = _app
    config = util.create_datastore_write_config(mapreduce_spec)
    state.put(config=config)
    return state 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:23,代码来源:handlers.py

示例7: put

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def put(self):
        """
        Extend put so that it writes vaules to memcache as well as the datastore,
        and keeps them in sync, even when datastore writes fails.
        """
        if self.session_key:
            memcache.set("_AppEngineUtilities_Session_" + str(self.session_key), self)
        else:
            # new session, generate a new key, which will handle the put and set the memcache
            self.create_key()

        self.last_activity = datetime.datetime.now()

        try:
            self.dirty = False
            logging.info("doing a put")
            db.put(self)
            memcache.set("_AppEngineUtilities_Session_" + str(self.session_key), self)
        except:
            self.dirty = True
            memcache.set("_AppEngineUtilities_Session_" + str(self.session_key), self)

        return self 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:sessions.py

示例8: create_key

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def create_key(self):
        """
        Creates a unique key for the session.
        """
        self.session_key = time.time()
        valid = False
        while valid == False:
            # verify session_key is unique
            if memcache.get("_AppEngineUtilities_Session_" + str(self.session_key)):
                self.session_key = self.session_key + 0.001
            else:
                query = _AppEngineUtilities_Session.all()
                query.filter("session_key = ", self.session_key)
                results = query.fetch(1)
                if len(results) > 0:
                    self.session_key = self.session_key + 0.001
                else:
                    try:
                        self.put()
                        memcache.set("_AppEngineUtilities_Session_" + str(self.session_key), self)
                    except:
                        self.dirty = True
                        memcache.set("_AppEngineUtilities_Session_" + str(self.session_key), self)
                    valid = True 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:sessions.py

示例9: __setitem__

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def __setitem__(self, keyname, value):
        """
        Set item in session data.

        Args:
            keyname: They keyname of the mapping.
            value: The value of mapping.
        """

        if self.integrate_flash and (keyname == 'flash'):
            self.flash.msg = value
        else:
            keyname = self._validate_key(keyname)
            self.cache[keyname] = value
            # self._set_memcache() # commented out because this is done in the datestore put
            return self._put(keyname, value) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:sessions.py

示例10: testRequiredParams

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def testRequiredParams(self):
    """Tests that required parameters are enforced."""
    TestEntity().put()
    self.handler.post()

    self.handler.request.set("name", None)
    self.assertRaises(errors.NotEnoughArgumentsError, self.handler.handle)

    self.handler.request.set("name", "my job")
    self.handler.request.set("mapper_input_reader", None)
    self.assertRaises(errors.NotEnoughArgumentsError, self.handler.handle)

    self.handler.request.set(
        "mapper_input_reader",
        "mapreduce.input_readers.DatastoreInputReader")
    self.handler.request.set("mapper_handler", None)
    self.assertRaises(errors.NotEnoughArgumentsError, self.handler.handle)

    self.handler.request.set("mapper_handler", MAPPER_HANDLER_SPEC)
    self.handler.request.set("mapper_params.entity_kind", None)
    self.assertRaises(input_readers.BadReaderParamsError, self.handler.handle)

    self.handler.request.set("mapper_params.entity_kind",
                             (__name__ + "." + TestEntity.__name__))
    self.handler.post() 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:27,代码来源:handlers_test.py

示例11: testParameterValidationSuccess

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def testParameterValidationSuccess(self):
    """Tests validating user-supplied parameters."""
    TestEntity().put()
    self.handler.request.set("mapper_params.one", ["red", "blue"])
    self.handler.request.set("mapper_params.two", "green")
    self.handler.request.set("mapper_params_validator",
                             __name__ + ".test_param_validator_success")
    self.handler.post()

    state = model.MapreduceState.get_by_job_id(
        self.handler.json_response["mapreduce_id"])
    params = state.mapreduce_spec.mapper.params

    self.assertEquals(["red", "blue"], params["one"])
    self.assertEquals("green", params["two"])

    # From the validator function
    self.assertEquals("good", params["test"]) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:20,代码来源:handlers_test.py

示例12: testMapreduceParameters

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def testMapreduceParameters(self):
    """Tests propagation of user-supplied mapreduce parameters."""
    TestEntity().put()
    self.handler.request.set("params.one", ["red", "blue"])
    self.handler.request.set("params.two", "green")
    self.handler.request.set("params_validator",
                             __name__ + ".test_param_validator_success")
    self.handler.post()

    state = model.MapreduceState.get_by_job_id(
        self.handler.json_response["mapreduce_id"])
    params = state.mapreduce_spec.params
    self.assertEquals(["red", "blue"], params["one"])
    self.assertEquals("green", params["two"])

    # From the validator function
    self.assertEquals("good", params["test"]) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:19,代码来源:handlers_test.py

示例13: setUpValidState

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def setUpValidState(self, hooks_class_name=None):
    self.mapper_spec = model.MapperSpec(
        handler_spec=self.HANLDER_SPEC,
        input_reader_spec=self.INPUT_READER_SPEC,
        params={"entity_kind": self.ENTITY_KIND},
        shard_count=self.SHARD_COUNT,
        output_writer_spec=self.OUTPUT_WRITER_SPEC)

    for _ in range(10):
      TestEntity().put()

    # Use StartJobHandler for setup.
    self.mr_id = handlers.StartJobHandler._start_map(
        self.NAME, self.mapper_spec,
        mapreduce_params=self.MAPREDUCE_SPEC_PARAMS,
        queue_name=self.QUEUE,
        hooks_class_name=hooks_class_name) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:19,代码来源:handlers_test.py

示例14: testRequestHasNotEnd

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def testRequestHasNotEnd(self):
    # Previous request's lease has timed out but the request has not.
    now = datetime.datetime.now()
    old = (now -
           datetime.timedelta(seconds=parameters._LEASE_DURATION_SEC + 1))
    self.shard_state.slice_start_time = old
    self.shard_state.slice_request_id = self.PREVIOUS_REQUEST_ID
    self.shard_state.put()
    handler, _ = self._create_handler()
    # Lease has ended.
    self.assertEqual(0,
                     handler._wait_time(self.shard_state,
                                        parameters._LEASE_DURATION_SEC),
                     lambda: now)
    # Logs API doesn't think the request has ended.
    self.assertFalse(handler._has_old_request_ended(self.shard_state))
    # Request has not timed out.
    self.assertTrue(handler._wait_time(
        self.shard_state,
        parameters._MAX_LEASE_DURATION_SEC,
        lambda: now))
    handler.post()
    self.assertEqual(httplib.SERVICE_UNAVAILABLE, handler.response.status) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:25,代码来源:handlers_test.py

示例15: testRequestHasTimedOut

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import put [as 别名]
def testRequestHasTimedOut(self):
    slice_start_time = datetime.datetime(2000, 1, 1)
    self.shard_state.slice_start_time = slice_start_time
    self.shard_state.slice_request_id = self.PREVIOUS_REQUEST_ID
    self.shard_state.put()
    handler, tstate = self._create_handler()
    # Lease has ended.
    self.assertEqual(0,
                     handler._wait_time(self.shard_state,
                                        parameters._LEASE_DURATION_SEC))
    # Logs API doesn't think the request has ended.
    self.assertFalse(handler._has_old_request_ended(self.shard_state))
    # But request has timed out.
    self.assertEqual(0, handler._wait_time(
        self.shard_state, parameters._MAX_LEASE_DURATION_SEC))

    # acquire lease should succeed.
    handler._try_acquire_lease(self.shard_state, tstate)

    shard_state = model.ShardState.get_by_shard_id(self.shard_id)
    self.assertTrue(shard_state.active)
    self.assertEqual(self.CURRENT_SLICE_ID, shard_state.slice_id)
    self.assertEqual(self.CURRENT_REQUEST_ID, shard_state.slice_request_id)
    self.assertTrue(shard_state.slice_start_time > slice_start_time) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:26,代码来源:handlers_test.py


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