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


Python items.Item类代码示例

本文整理汇总了Python中boto.dynamodb2.items.Item的典型用法代码示例。如果您正苦于以下问题:Python Item类的具体用法?Python Item怎么用?Python Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: put

    def put(self, key, value):
        '''Stores the object.'''
        table = self._table(key)

        value = self._wrap(table, key, value)
        item = Item(table, data=value)
        item.save(overwrite=True)
开发者ID:datastore,项目名称:datastore.dynamo,代码行数:7,代码来源:__init__.py

示例2: main

def main(args):
  conn=dynaconnect(args)
  tableName=args.table

  try:
    conn.describe_table(tableName)
  except boto.exception.JSONResponseError as details:
    if (details.error_code != "ResourceNotFoundException"):
      error("Error when connecting to DynamodDB",details.message)
    
    sys.stdout.write("Table does not exist, creating it")
    sys.stdout.flush()
    
    table = Table.create(tableName, schema=[ HashKey('name') ], global_indexes=[GlobalAllIndex('StacksByType', parts=[HashKey('type')])], connection=conn)

    while (table.describe()["Table"]["TableStatus"]!="ACTIVE"):
      time.sleep(1)
      sys.stdout.write('.')
      sys.stdout.flush()
    print("")
  else:
    table = Table(tableName,connection=conn)

  parameters = dict([x.strip() for x in line.strip().split("=")] for line in open(args.prop_file))
  additionals = dict([x.strip() for x in k.strip().split("=")] for k in args.key)

  dynamodata={'type':args.type, 'name':args.name, 'config':parameters}
  dynamodata.update(additionals)
  item=Item(table,data=dynamodata)

  item.save(overwrite=True)
开发者ID:Shaiou,项目名称:demo,代码行数:31,代码来源:setparams.py

示例3: Item

class Item(ItemEngine):

    def __init__(self, collection, raw_item):
        ItemEngine.__init__(self, collection, raw_item)
        self.__item = raw_item

    @property
    def ddb_item(self):
        return self.__item

    def update(self, patch, context, updates):
        if patch:
            for k, v in iteritems(updates):
                self.__item[k] = v
            self.__item.partial_save()
        else:
            if context is None:
                self.__item = BotoItem(self.__item.table, updates)
                self.__item.save(True)
            else:
                context.put_item(self.__table, updates)

    def delete(self, index, context):
        if context is None:
            self.__item.delete()
        else:
            context.delete_item(
                self.__table,
                **(index.make_key_dict_from_dict(self.get_dict()))
            )

    def get_dict(self):
        return self.__item._data
开发者ID:xica,项目名称:hieratic-dynamodb,代码行数:33,代码来源:__init__.py

示例4: create_tables

    def create_tables(self):
        '''
        () -> None

        Permite crear todas las tablas necesarias para el entorno de pruebas.
        Las tablas creadas seran llenadas con datos de prueba que se encuentran
        en el archivo test_data.json.
        '''

        #Creacion de las tablas para los test
        super(dbTablesTest, self).create_tables()

        import os
        from commons import jsondecoder

        #cargar los datos de prueba del archivo test_data.json
        path_file = os.path.abspath(self.config['DB_TEST_DATA_PATH'])
        json_data = open(path_file).read()
        data = jsondecoder(json_data)

        #guardar los datos contenidos en el archivo json en la base de datos.
        for key, value in data.items():
            table = self.tables[key]
            for item in value:
                if key == 'tbl_timeline':
                    if 'skills' in item:
                        item['skills'] = set(item['skills'])
                    if 'win_answers' in item:
                        item['win_answers'] = set(item['win_answers'])
                item = Item(table, data=item)
                item.save()
开发者ID:oxfishapp,项目名称:RESTful,代码行数:31,代码来源:dynamoDB.py

示例5: put_item

    def put_item(self, data, overwrite=False):
        """
        Saves an entire item to DynamoDB.

        By default, if any part of the ``Item``'s original data doesn't match
        what's currently in DynamoDB, this request will fail. This prevents
        other processes from updating the data in between when you read the
        item & when your request to update the item's data is processed, which
        would typically result in some data loss.

        Requires a ``data`` parameter, which should be a dictionary of the data
        you'd like to store in DynamoDB.

        Optionally accepts an ``overwrite`` parameter, which should be a
        boolean. If you provide ``True``, this will tell DynamoDB to blindly
        overwrite whatever data is present, if any.

        Returns ``True`` on success.

        Example::

            >>> users.put_item(data={
            ...     'username': 'jane',
            ...     'first_name': 'Jane',
            ...     'last_name': 'Doe',
            ...     'date_joined': 126478915,
            ... })
            True

        """
        item = Item(self, data=data)
        return item.save(overwrite=overwrite)
开发者ID:kolencherry,项目名称:dd-agent,代码行数:32,代码来源:table.py

示例6: delete

 def delete(self):
     """Delete the current record matching the attribute with get_key_name()
     in the table get_table_name()
     """
     table = self.get_class_table()
     item = Item(table, data=self.get_item())
     return item.delete()
开发者ID:memphis-iis,项目名称:demo-corpus,代码行数:7,代码来源:data.py

示例7: add_to_db

    def add_to_db(self):
        items_table = Table('items')

        for product in self.viable_products:
            temp_item = Item(items_table, data={
                'type':'iphone',
                'title':product[0],
                'itemId':product[1],
                'viewItemURL':product[2],
                'sellerUserName':product[3],
                'positiveFeedbackPercent':product[4],
                'feedbackRatingStar':product[5],
                'conditionId':product[6],
                'listingType':product[7],
                'currentPrice':product[8],
                'bidCount':product[9],
                'timeLeft':product[10],
                'endTime':product[11],
                'carrier':product[12],
                'storage':product[13],
                'model':product[14],
                'color':product[15],
                'pmresult':product[16],
            })

            temp_item.save(overwrite=True)

        print 'all set'
开发者ID:biddyweb,项目名称:Crimson-Bids,代码行数:28,代码来源:parse_results.py

示例8: deprecated__handle_truth

 def deprecated__handle_truth( self, rs ):
     if self._mask is None:
         self._mask = rs.get_mask()
     rs.set_mask(self._mask)
     accuracy = rs.accuracy()
     with tempfile.SpooledTemporaryFile() as temp:
         np.save(temp, accuracy)
         temp.seek(0)
         conn = boto.connect_s3(  )
         bucket = conn.create_bucket( self.s3_results )
         k = Key(bucket)
         m = hashlib.md5()
         m.update(accuracy)
         md5 =  m.hexdigest()
         k.key = md5
         k.set_contents_from_file( temp )
     run_id = rs.get_run_id()
     try:
         item = Item( self.truth_table, {'run_id':run_id,
                 'strain_id': rs.spec_string} )
         item['accuracy_file'] = md5
         item['result_files'] =  base64.b64encode( json.dumps( 
             rs.get_result_files() ) )
         item['bucket'] = self.s3_results
         item['timestamp'] = datetime.datetime.utcnow().strftime('%Y.%m.%d-%H:%M:%S')
         item.save()
     except ConditionalCheckFailedException as ccfe:
         print "*"*20
         print ccfe
         if rs is not None:
             print  {'run_id':run_id,'strain_id': rs.spec_string}
             print rs.get_result_files()
开发者ID:JohnCEarls,项目名称:DataDirac,代码行数:32,代码来源:aggregate.py

示例9: _scan

    def _scan(self, limit=None, exclusive_start_key=None, segment=None, total_segments=None, **filter_kwargs):
        """
        The internal method that performs the actual scan. Used extensively
        by ``ResultSet`` to perform each (paginated) request.
        """
        kwargs = {"limit": limit, "segment": segment, "total_segments": total_segments}

        if exclusive_start_key:
            kwargs["exclusive_start_key"] = {}

            for key, value in exclusive_start_key.items():
                kwargs["exclusive_start_key"][key] = self._dynamizer.encode(value)

        # Convert the filters into something we can actually use.
        kwargs["scan_filter"] = self._build_filters(filter_kwargs, using=FILTER_OPERATORS)

        raw_results = self.connection.scan(self.table_name, **kwargs)
        results = []
        last_key = None

        for raw_item in raw_results.get("Items", []):
            item = Item(self)
            item.load({"Item": raw_item})
            results.append(item)

        if raw_results.get("LastEvaluatedKey", None):
            last_key = {}

            for key, value in raw_results["LastEvaluatedKey"].items():
                last_key[key] = self._dynamizer.decode(value)

        return {"results": results, "last_key": last_key}
开发者ID:kolencherry,项目名称:dd-agent,代码行数:32,代码来源:table.py

示例10: flush

    def flush(self):
        batch_data = {
            self.table.table_name: [
                # We'll insert data here shortly.
            ],
        }

        for put in self._to_put:
            item = Item(self.table, data=put)
            batch_data[self.table.table_name].append({
                'PutRequest': {
                    'Item': item.prepare_full(),
                }
            })

        for delete in self._to_delete:
            batch_data[self.table.table_name].append({
                'DeleteRequest': {
                    'Key': self.table._encode_keys(delete),
                }
            })

        resp = self.table.connection.batch_write_item(batch_data)
        self.handle_unprocessed(resp)

        self._to_put = []
        self._to_delete = []
        return True
开发者ID:YongMan,项目名称:boto,代码行数:28,代码来源:table.py

示例11: put_metrics

    def put_metrics(self, build_time_metrics):
        if not build_time_metrics:
            return None

        try:
            item = self.table.get_item(instance_type=_get_instance_type(self.localrun), config=self.benchmark_config)
            self.logger.debug("Found existing entity in dynamodb")
        except ItemNotFound:
            self.logger.debug("No existing entity found in dynamodb, creating new one")
            item = Item(self.table, data={'instance_type': _get_instance_type(self.localrun),
                                          'config': self.benchmark_config})

        build_time_json = item['build_time']

        if build_time_json:
            self.logger.debug("Extending existing metric list for build_time")
            # extend existing list
            build_time = json.loads(build_time_json)
            build_time.extend(build_time_metrics)
            item['build_time'] = json.dumps(build_time)
        else:
            item['build_time'] = json.dumps(build_time_metrics)

        if item.needs_save():
            item.partial_save()
            self.logger.debug("Saved item to dynamodb")
开发者ID:marco-hoyer,项目名称:packer-aws-benchmark,代码行数:26,代码来源:timed_test_runner.py

示例12: _query

    def _query(
        self, limit=None, index=None, reverse=False, consistent=False, exclusive_start_key=None, **filter_kwargs
    ):
        """
        The internal method that performs the actual queries. Used extensively
        by ``ResultSet`` to perform each (paginated) request.
        """
        kwargs = {"limit": limit, "index_name": index, "scan_index_forward": reverse, "consistent_read": consistent}

        if exclusive_start_key:
            kwargs["exclusive_start_key"] = {}

            for key, value in exclusive_start_key.items():
                kwargs["exclusive_start_key"][key] = self._dynamizer.encode(value)

        # Convert the filters into something we can actually use.
        kwargs["key_conditions"] = self._build_filters(filter_kwargs, using=QUERY_OPERATORS)

        raw_results = self.connection.query(self.table_name, **kwargs)
        results = []
        last_key = None

        for raw_item in raw_results.get("Items", []):
            item = Item(self)
            item.load({"Item": raw_item})
            results.append(item)

        if raw_results.get("LastEvaluatedKey", None):
            last_key = {}

            for key, value in raw_results["LastEvaluatedKey"].items():
                last_key[key] = self._dynamizer.decode(value)

        return {"results": results, "last_key": last_key}
开发者ID:9seconds,项目名称:boto,代码行数:34,代码来源:table.py

示例13: save_partition

def save_partition(part):

    for record in part:
        item = Item(
            out_table,
            data={"airport": record[0][0], "carrier": record[0][1], "mean_delay": int(record[1][0] / record[1][1])},
        )
        item.save(overwrite=True)
开发者ID:gmcorral,项目名称:cloud-capstone,代码行数:8,代码来源:g2e1.py

示例14: save_partition

def save_partition(part):

    for record in part:
        item = Item(out_table, data={
            "origin": record[0][0],
            "destination": record[0][1],
            "mean_delay": int(record[1][0] / record[1][1])
        })
        item.save(overwrite=True)
开发者ID:gmcorral,项目名称:cloud-capstone,代码行数:9,代码来源:g2e4.py

示例15: get_state

def get_state(table, project):
	try:
		return table.get_item(project=project, consistent=True)
	except ItemNotFound:
		state = Item(table, data={
			'project': project,
			'state': 'idle',
		})
		state.save()
开发者ID:goabout,项目名称:docker-serialized-ansible,代码行数:9,代码来源:serialize.py


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