<commit_before>import rospy
import genpy
from std_srvs.srv import Empty
import yaml
from bson import json_util, Binary
import json

import copy
import StringIO
from mongodb_store_msgs.msg import SerialisedMessage
from mongodb_store_msgs.srv import MongoQueryMsgRequest

import importlib
from datetime import datetime

def check_connection_to_mongod(db_host, db_port):
    """
    Check connection to mongod server

    :Returns:
        | bool : True on success, False if connection is not established.
    """
    if check_for_pymongo():
        try:
            from pymongo import Connection
            Connection(db_host, db_port)
            return True
        except Exception as e:
            print("Error: %s" % str(e))
            print("Could not connect to mongo server %s:%d" % (db_host, db_port))
            print("Make sure mongod is launched on your specified host/port")
            return False
    else:
        return False


def wait_for_mongo(timeout):
    """
    Waits for the mongo server, as started through the mongodb_store/mongodb_server.py wrapper

    :Returns:
        | bool : True on success, False if server not even started.
    """
    # Check that mongo is live, create connection
    try:
        rospy.wait_for_service("/datacentre/wait_ready", timeout)
    except rospy.exceptions.ROSException, e:
        rospy.logerr("Can't connect to MongoDB server. Make sure mongodb_store/mongodb_server.py node is started.")
        return False
    wait = rospy.ServiceProxy('/datacentre/wait_ready', Empty)
    wait()
    return True

def check_for_pymongo():
    """
    Checks for required version of pymongo python library.

    :Returns:
        | bool : True if found, otherwise Fale<commit_msg>fixing error with launching mongodb_store<commit_after>import rospy
import genpy
from std_srvs.srv import Empty
import yaml
from bson import json_util, Binary
import json

import copy
import StringIO
from mongodb_store_msgs.msg import SerialisedMessage
from mongodb_store_msgs.srv import MongoQueryMsgRequest

import importlib
from datetime import datetime

def check_connection_to_mongod(db_host, db_port):
    """
    Check connection to mongod server

    :Returns:
        | bool : True on success, False if connection is not established.
    """
    if check_for_pymongo():
        try:
            from pymongo import Connection
            Connection(db_host, db_port)
            return True
        except Exception as e:
            print("Error: %s" % str(e))
            print("Could not connect to mongo server %s:%d" % (db_host, db_port))
            print("Make sure mongod is launched on your specified host/port")
            return False
    else:
        return False


def wait_for_mongo(timeout=60):
    """
    Waits for the mongo server, as started through the mongodb_store/mongodb_server.py wrapper

    :Returns:
        | bool : True on success, False if server not even started.
    """
    # Check that mongo is live, create connection
    try:
        rospy.wait_for_service("/datacentre/wait_ready", timeout)
    except rospy.exceptions.ROSException, e:
        rospy.logerr("Can't connect to MongoDB server. Make sure mongodb_store/mongodb_server.py node is started.")
        return False
    wait = rospy.ServiceProxy('/datacentre/wait_ready', Empty)
    wait()
    return True

def check_for_pymongo():
    """
    Checks for required version of pymongo python library.

    :Returns:
        | bool : True if found, otherwise Fale
{'fraction_non_alphanumeric': 0.07055127106540988, 'fraction_numerical': 0.0005712653527563553, 'mean_word_length': 2.9128491620111734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3210669', 'n_tokens_mistral': 1038, 'n_tokens_neox': 996, 'n_words': 339}