diff --git a/mongodb_store/CMakeLists.txt b/mongodb_store/CMakeLists.txt index febdaf3..2d4f454 100644 --- a/mongodb_store/CMakeLists.txt +++ b/mongodb_store/CMakeLists.txt @@ -133,9 +133,18 @@ target_link_libraries(example_multi_event_log ## Mark executable scripts (Python etc.) for installation ## in contrast to setup.py, you can choose the destination -install(DIRECTORY scripts/ - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} - USE_SOURCE_PERMISSIONS) +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} +) # 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 1f5c0f2..c752bfd 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 = map(dc_util.deserialise_message, response.messages) - metas = map(dc_util.string_pair_list_to_dictionary, response.metas) + messages = list(map(dc_util.deserialise_message, response.messages)) + metas = list(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 zip(messages,metas) + return list(zip(messages,metas)) diff --git a/mongodb_store/src/mongodb_store/util.py b/mongodb_store/src/mongodb_store/util.py index 369d62c..7d0f571 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 - import io as StringIO + from io import BytesIO as Buffer else: _PY3 = False - import StringIO + from StringIO import StringIO as Buffer from mongodb_store_msgs.msg import SerialisedMessage from mongodb_store_msgs.srv import MongoQueryMsgRequest @@ -201,16 +201,13 @@ def sanitize_value(attr, v, type): else: # ensure unicode try: - if _PY3: - v = str(v, "utf-8") - else: + if not _PY3: # All strings are unicode in Python 3 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): @@ -332,8 +329,7 @@ def fill_message(message, document): lst.append(msg) setattr(message, slot, lst) else: - if ( (not _PY3 and isinstance(value, unicode)) or - (_PY3 and isinstance(value, str)) ): + if not _PY3 and isinstance(value, unicode): # All strings are unicode in Python 3 setattr(message, slot, value.encode('utf-8')) else: setattr(message, slot, value) @@ -518,9 +514,9 @@ def serialise_message(message): :Args: | message (ROS message): The message to serialise :Returns: - | mongodb_store_msgs.msg.SerialisedMessage: A serialies copy of message + | mongodb_store_msgs.msg.SerialisedMessage: A serialised copy of message """ - buf=StringIO.StringIO() + buf = Buffer() 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 1aa0887..a406d40 100755 --- a/mongodb_store/tests/test_messagestore.py +++ b/mongodb_store/tests/test_messagestore.py @@ -63,19 +63,16 @@ 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], range(10)) + self.assertListEqual([int(doc[0].orientation.x) for doc in result_limited], list(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)