diff --git a/mongodb_store/CMakeLists.txt b/mongodb_store/CMakeLists.txt index 2d4f454..febdaf3 100644 --- a/mongodb_store/CMakeLists.txt +++ b/mongodb_store/CMakeLists.txt @@ -133,18 +133,9 @@ target_link_libraries(example_multi_event_log ## Mark executable scripts (Python etc.) for installation ## in contrast to setup.py, you can choose the destination -catkin_install_python(PROGRAMS - scripts/config_manager.py - scripts/example_message_store_client.py - scripts/example_multi_event_log.py - scripts/message_store_node.py - scripts/mongo_bridge.py - scripts/mongodb_play.py - scripts/mongodb_server.py - scripts/replicator_client.py - scripts/replicator_node.py - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -) +install(DIRECTORY scripts/ + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} + USE_SOURCE_PERMISSIONS) # Mark other files for installation (e.g. launch and bag files, etc.) install( diff --git a/mongodb_store/src/mongodb_store/message_store.py b/mongodb_store/src/mongodb_store/message_store.py index c752bfd..1f5c0f2 100644 --- a/mongodb_store/src/mongodb_store/message_store.py +++ b/mongodb_store/src/mongodb_store/message_store.py @@ -261,8 +261,8 @@ def query(self, type, message_query = {}, meta_query = {}, single = False, sort_ messages = [] metas = [] else: - messages = list(map(dc_util.deserialise_message, response.messages)) - metas = list(map(dc_util.string_pair_list_to_dictionary, response.metas)) + messages = map(dc_util.deserialise_message, response.messages) + metas = map(dc_util.string_pair_list_to_dictionary, response.metas) if single: if len(messages) > 0: @@ -270,4 +270,4 @@ def query(self, type, message_query = {}, meta_query = {}, single = False, sort_ else: return [None, None] else: - return list(zip(messages,metas)) + return zip(messages,metas) diff --git a/mongodb_store/src/mongodb_store/util.py b/mongodb_store/src/mongodb_store/util.py index 7d0f571..369d62c 100644 --- a/mongodb_store/src/mongodb_store/util.py +++ b/mongodb_store/src/mongodb_store/util.py @@ -10,10 +10,10 @@ import platform if float(platform.python_version()[0:2]) >= 3.0: _PY3 = True - from io import BytesIO as Buffer + import io as StringIO else: _PY3 = False - from StringIO import StringIO as Buffer + import StringIO from mongodb_store_msgs.msg import SerialisedMessage from mongodb_store_msgs.srv import MongoQueryMsgRequest @@ -201,13 +201,16 @@ def sanitize_value(attr, v, type): else: # ensure unicode try: - if not _PY3: # All strings are unicode in Python 3 + if _PY3: + v = str(v, "utf-8") + else: v = unicode(v, "utf-8") except UnicodeDecodeError as e: # at this point we can deal with the encoding, so treat it as binary v = Binary(v) # no need to carry on with the other type checks below return v + if isinstance(v, rospy.Message): return msg_to_document(v) elif isinstance(v, genpy.rostime.Time): @@ -329,7 +332,8 @@ def fill_message(message, document): lst.append(msg) setattr(message, slot, lst) else: - if not _PY3 and isinstance(value, unicode): # All strings are unicode in Python 3 + if ( (not _PY3 and isinstance(value, unicode)) or + (_PY3 and isinstance(value, str)) ): setattr(message, slot, value.encode('utf-8')) else: setattr(message, slot, value) @@ -514,9 +518,9 @@ def serialise_message(message): :Args: | message (ROS message): The message to serialise :Returns: - | mongodb_store_msgs.msg.SerialisedMessage: A serialised copy of message + | mongodb_store_msgs.msg.SerialisedMessage: A serialies copy of message """ - buf = Buffer() + buf=StringIO.StringIO() message.serialize(buf) serialised_msg = SerialisedMessage() serialised_msg.msg = buf.getvalue() diff --git a/mongodb_store/tests/test_messagestore.py b/mongodb_store/tests/test_messagestore.py index a406d40..1aa0887 100755 --- a/mongodb_store/tests/test_messagestore.py +++ b/mongodb_store/tests/test_messagestore.py @@ -63,16 +63,19 @@ def test_add_message(self): # get documents with limit result_limited = msg_store.query(Pose._type, message_query={'orientation.z': {'$gt': 10} }, sort_query=[("$natural", 1)], limit=10) self.assertEqual(len(result_limited), 10) - self.assertListEqual([int(doc[0].orientation.x) for doc in result_limited], list(range(10))) + self.assertListEqual([int(doc[0].orientation.x) for doc in result_limited], range(10)) - #get documents without "orientation" field - result_no_id = msg_store.query(Pose._type, message_query={}, projection_query={"orientation": 0}) + #get documents without "orientation" field + result_no_id = msg_store.query(Pose._type, message_query={}, projection_query={"orientation": 0}) for doc in result_no_id: - self.assertEqual(int(doc[0].orientation.z), 0) + self.assertEqual(int(doc[0].orientation.z),0 ) + + + # must remove the item or unittest only really valid once - print(meta["_id"]) - print(str(meta["_id"])) + print meta["_id"] + print str(meta["_id"]) deleted = msg_store.delete(str(meta["_id"])) self.assertTrue(deleted)