adaptivemd.StoredBundle

class adaptivemd.StoredBundle[source]

A stored bundle in a mongodb

This is a useful wrapper to turn a store of the MongoDB into a bundle of objects. Adding files will store new elements. The bundle is always in sync with the DB.

__init__()[source]

Methods

__init__()
add(item) Add an element to the bundle
c(cls) Return a view bundle on all entries that are instances of a class
close() Close the connection to the bundle.
consume_one() Picks and removes one (random) element in one step.
f(pattern) Return a view bundle on all entries that match a location pattern
find_all_by(key, value) Return all elements from the bundle where its key matches value
pick() Pick a random element
set_store(store) Set the used store
sorted(key) Return a view bundle where all entries are sorted by a given key attribute
update(iterable) Add multiple items to the bundle at once
v(fnc) Return a view bundle on all entries that are filtered by a function

Attributes

all Return a Delegator that will apply attribute and function call to all bundle elements
first Return the entry with the earliest timestamp
last Return the entry with the latest timestamp
one Return one element from the list
set_store(store)[source]

Set the used store

Parameters:store (ObjectStore) – a mongodb store that contains the elements in the bundle
close()[source]

Close the connection to the bundle.

A not connected bundle will have no entries and none can be added

add(item)[source]

Add an element to the bundle

Parameters:item (object) – the item to be added to the bundle
last

Return the entry with the latest timestamp

Returns:the latest object
Return type:object
first

Return the entry with the earliest timestamp

Returns:the earliest object
Return type:object
consume_one()[source]

Picks and removes one (random) element in one step.

Returns:The deleted object if possible otherwise None
Return type:StorableMixin or None
find_all_by(key, value)[source]

Return all elements from the bundle where its key matches value

Parameters:
  • key (str) – the attribute
  • value (object) – the value to match against using ==
Returns:

a list of objects in the bundle that match the search

Return type:

list of StorableMixin