本文整理汇总了Python中storm.locals.Store.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Store.remove方法的具体用法?Python Store.remove怎么用?Python Store.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类storm.locals.Store
的用法示例。
在下文中一共展示了Store.remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_statspollute
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import remove [as 别名]
def do_statspollute(dbfile):
# source
gl_database = create_database("sqlite:%s" % dbfile)
source_store = Store(gl_database)
stats = source_store.find(models.Stats)
counter = 0
for s in stats:
source_store.remove(s)
counter += 1
print "removed %d entry in stats" % counter
counter = 0
# 21 days in the past
for past_hours in xrange(24 * 7 * 3):
past_hours += 4
when = utc_past_date(hours=past_hours)
newstat = models.Stats()
newstat.freemb = randint(1000, 1050)
newstat.year = when.isocalendar()[0]
newstat.week = when.isocalendar()[1]
level = round((randint(0, 1000) / 240.0), 1) - 2
def random_pollution():
return int(randint(0,11) + (5 * level))
activity_fake = {
'successfull_logins': random_pollution(),
'failed_logins': random_pollution(),
'started_submissions': random_pollution(),
'completed_submissions': random_pollution(),
'uploaded_files': int(randint(0,11) + (5 * level)),
'appended_files': random_pollution(),
'wb_comments': random_pollution(),
'wb_messages': random_pollution(),
'receiver_comments': random_pollution(),
'receiver_messages': random_pollution()
}
for k, v in activity_fake.iteritems():
if v < 0:
activity_fake[k] = 0
newstat.start = when
newstat.summary = activity_fake
counter += 1
source_store.add(newstat)
print "Committing %d stats" % counter
source_store.commit()
示例2: StormORM
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import remove [as 别名]
#.........这里部分代码省略.........
'''
@param uri: Database URI following storm rules.
@param store: Storm store.
If uri is given a new store is instanciated and it is used
to execute the statements.
If both parameters are given the early created store overrides
the store given.
'''
from storm.locals import create_database, Store
self.uri = uri
self.store = store
if self.uri:
database = create_database(self.uri)
self.store = Store(database)
if not self.store:
raise Exception('None storm store')
self.attrParser = StormAttributeParser()
def _getObject(self, csvType, csvStatement):
"""
Retrieves the object to be used at statement execution.
@param csvType: The CSVType
@param csvStatement: The CSVStatement
@return: The object early instanciated (for insert statement) or
retrieved from database (for update or delete statements).
"""
typo = csvType.type
keys = csvType.keys
attributes = csvStatement.attributes
if csvStatement.action in [DELETE, UPDATE]:
if csvType.hasPrimaryKey:
return self.store.get(typo, attributes[ csvType.primaryKey[0] ])
else:
pred = And([Eq(typo, key, attributes[i]) for i,key in keys.iteritems()])
result = self.store.find(typo, pred)
if result.count() == 0:
return None
elif result.count() == 1:
return result.one()
else:
return [r for r in result]
elif csvStatement.action is INSERT:
return typo()
def executeStatement(self, csvType, csvStatement):
"""
Executes csv statements matched by the pair csvType, csvStatement.
@param csvType: The CSVType
@param csvStatement: The CSVStatement
@return: Total statements executed or raises a ValueError if the object retrieved with
the pair csvType, csvStatement is None.
"""
obj = self._getObject(csvType, csvStatement)
if not obj:
msg = 'Statement return None in line %d: %s' % (csvStatement.lineNumber, csvStatement.lineContent)
raise ValueError(msg)
objs = []
if type(obj) is list:
objs += obj
else:
objs.append(obj)
i = 0
for _obj in objs:
self._executeStatement(_obj, csvType, csvStatement)
i += 1
return i
def _executeStatement(self, obj, csvType, csvStatement):
"""
Executes a single csv statement
@param csvType: The CSVType
@param csvStatement: The CSVStatement
"""
keys = csvType.keys
attributes = csvType.attributes
values = csvStatement.attributes
if csvStatement.action is INSERT:
pairs = [(key, values[i]) for i,key in keys.iteritems()]
pairs += [(key, values[i]) for i,key in attributes.iteritems()]
for key, value in pairs:
setattr(obj, key, value)
self.store.add(obj)
elif csvStatement.action is UPDATE:
pairs = [(key, values[i]) for i,key in attributes.iteritems()]
for key, value in pairs:
setattr(obj, key, value)
elif csvStatement.action is DELETE:
self.store.remove(obj)
self.store.commit()