mongodb_store.util module¶
-
mongodb_store.util.
add_soma_fields
(msg, doc)[source]¶ For soma Object msgs adds the required fields as indexes to the mongodb object.
-
mongodb_store.util.
check_connection_to_mongod
(db_host, db_port, connection_string=None)[source]¶ Check connection to mongod server
Returns: bool : True on success, False if connection is not established.
-
mongodb_store.util.
check_for_pymongo
()[source]¶ Checks for required version of pymongo python library.
Returns: bool : True if found, otherwise Fale
-
mongodb_store.util.
deserialise_message
(serialised_message)[source]¶ Create a ROS message from a mongodb_store_msgs/SerialisedMessage
Args: serialised_message (mongodb_store_msgs.msg.SerialisedMessage): The message to deserialiseReturns: ROS message: The message deserialised
-
mongodb_store.util.
dictionary_to_message
(dictionary, cls)[source]¶ Create a ROS message from the given dictionary, using fill_message.
Args: dictionary (dict): A dictionary containing all of the atributes of the messagecls (class): The python class of the ROS message type being reconstructed.Returns: An instance of cls with the attributes filled. Example:
>>> from geometry_msgs.msg import Pose >>> d = {'orientation': {'w': 0.0, 'x': 0.0, 'y': 0.0, 'z': 0.0}, 'position': {'x': 27.0, 'y': 0.0, 'z': 0.0}} >>> dictionary_to_message(d, Pose) position: x: 27.0 y: 0.0 z: 0.0 orientation: x: 0.0 y: 0.0 z: 0.0 w: 0.0
-
mongodb_store.util.
fill_message
(message, document)[source]¶ Fill a ROS message from a dictionary, assuming the slots of the message are keys in the dictionary.
Args: message (ROS message): An instance of a ROS message that will be filled indocument (dict): A dicionary containing all of the message attributesExample:
>>> from geometry_msgs.msg import Pose >>> d = dcu.msg_to_document(Pose()) >>> d['position']['x']=27.0 >>> new_pose = Pose( >>> fill_message(new_pose, d) >>> new_pose position: x: 27.0 y: 0.0 z: 0.0 orientation: x: 0.0 y: 0.0 z: 0.0 w: 0.0
-
mongodb_store.util.
load_class
(full_class_string)[source]¶ Dynamically load a class from a string shamelessly ripped from: http://thomassileo.com/blog/2012/12/21/dynamically-load-python-modules-or-classes/
Args: full_class_string (str): The python class to dynamically loadReturns: class: the loaded python class.
-
mongodb_store.util.
msg_to_document
(msg)[source]¶ Given a ROS message, turn it into a (nested) dictionary suitable for the datacentre.
>>> from geometry_msgs.msg import Pose >>> msg_to_document(Pose()) {'orientation': {'w': 0.0, 'x': 0.0, 'y': 0.0, 'z': 0.0}, 'position': {'x': 0.0, 'y': 0.0, 'z': 0.0}}
Args: msg (ROS Message): An instance of a ROS message to convertReturns: dict : A dictionary representation of the supplied message.
-
mongodb_store.util.
query_message
(collection, query_doc, sort_query=[], projection_query={}, find_one=False, limit=0)[source]¶ Peform a query for a stored messages, returning results in list.
Args: collection (pymongo.Collection): The collection to queryquery_doc (dict): The MongoDB query to executesort_query (list of tuple): The MongoDB query to sortprojection_query (dict): The projection queryfind_one (bool): Returns one matching document if True, otherwise all matching.limit (int): Limits number of return documents. 0 means no limitReturns: dict or list of dict: the MongoDB document(s) found by the query
-
mongodb_store.util.
query_message_ids
(collection, query_doc, find_one)[source]¶ Peform a query for a stored message, returning a tuple of id strings
Args: collection (pymongo.Collection): The collection to searchquery_doc (dict): The MongoDB query to executefind_one (bool): Find one matching document if True, otherwise all matching.Returns: tuple of strings: all ObjectIds of matching documents
-
mongodb_store.util.
sanitize_value
(attr, v, type)[source]¶ De-rosify a msg.
Internal function used to convert ROS messages into dictionaries of pymongo insertable values.
Args: attr(str): the ROS message slot name the value came fromv: the value from the message’s slot to make into a MongoDB able typetype (str): The ROS type of the value passed, as given by the ressage slot_types member.Returns: A sanitized version of v.
-
mongodb_store.util.
serialise_message
(message)[source]¶ Create a mongodb_store_msgs/SerialisedMessage instance from a ROS message.
Args: message (ROS message): The message to serialiseReturns: mongodb_store_msgs.msg.SerialisedMessage: A serialies copy of message
-
mongodb_store.util.
store_message
(collection, msg, meta, oid=None)[source]¶ Update ROS message into the DB
Args: collection (pymongo.Collection): the collection to store the message inmsg (ROS message): an instance of a ROS message to storemeta (dict): Additional meta data to store with the ROS messageoid (str): An optional ObjectID for the MongoDB document created.Returns: str: ObjectId of the MongoDB document.
-
mongodb_store.util.
store_message_no_meta
(collection, msg)[source]¶ Store a ROS message sans meta data.
Args: collection (pymongo.Collection): The collection to store the message inmsg (ROS message): An instance of a ROS message to storeReturns: str: The ObjectId of the MongoDB document created.
-
mongodb_store.util.
string_pair_list_to_dictionary
(spl)[source]¶ Creates a dictionary from a mongodb_store_msgs/StringPairList which could contain JSON as a string. If the first entry in the supplied list is a JSON query then the returned dictionary is loaded from that.
Args: spl (StringPairList): The list of (key, value) pairs to convertReturns: dict: resulting dictionary
-
mongodb_store.util.
string_pair_list_to_dictionary_no_json
(spl)[source]¶ Covert a mongodb_store_msgs/StringPairList into a dictionary, ignoring content
Args: spl (StringPairList): The list of (key, value) to pairs convertReturns: dict: resulting dictionary
-
mongodb_store.util.
topic_name_to_collection_name
(topic_name)[source]¶ Converts the fully qualified name of a topic into legal mongodb collection name.
-
mongodb_store.util.
type_to_class_string
(type)[source]¶ Takes a ROS msg type and turns it into a Python module and class name.
E.g
>>> type_to_class_string("geometry_msgs/Pose") geometry_msgs.msg._Pose.Pose
Args: type (str): The ROS message type to return class stringReturns: str: A python class string for the ROS message type supplied
-
mongodb_store.util.
update_message
(collection, query_doc, msg, meta, upsert)[source]¶ Update ROS message in the DB, return updated id and true if db altered.
Args: collection (pymongo.Collection): The collection to update inquery_doc (dict): The MongoDB query to execute to select document for updatemsg (ROS message): An instance of a ROS message to update tometa (dict): New meta data to update the stored message withupsert (bool): If message does not already exits, create if upsert==True.Returns: str, bool: the OjectId of the updated document and whether it was altered by the operation