<commit_before>#
# Copyright (c) 2009 rPath, Inc.
#
# All rights reserved.
#

"""
Tools for performing RPC against nodes on the message bus.
"""

#from rmake.lib.apiutils import register, freeze, thaw
from rmake.messagebus import rpclib
from rmake.multinode import nodetypes
from rmake.multinode.server import messagebus
from mcp import dispatcher
from mcp.mcp_error import BuildSystemUnreachableError
from mcp.messagebus import nodetypes as mcp_nodetypes


def findBusNode(busClient, sessionClass):
    """
    Return the sessionId of a node on the message bus with the given
    C{sessionClass}, or C{None} if no node with that class is connected.
    """
    busProxy = messagebus.MessageBusRPCClient(busClient)
    for nodeId, nodeClass in sorted(busProxy.listSessions().items()):
        if nodeClass == sessionClass:
            return nodeId
    return None


class DispatcherRPCClient(rpclib.SessionProxy):
    def __init__(self, busClient, dispatcherId=None):
        if dispatcherId is None:
            dispatcherId = findBusNode(busClient,
                    dispatcher.Dispatcher.sessionClass)
            if dispatcherId is None:
                raise BuildSystemUnreachableError(
                        "Could not contact the dispatcher")

        rpclib.SessionProxy.__init__(self, dispatcher.Dispatcher, busClient,
                dispatcherId)<commit_msg>Catch rMake OpenError<commit_after>#
# Copyright (c) 2009 rPath, Inc.
#
# All rights reserved.
#

"""
Tools for performing RPC against nodes on the message bus.
"""
from conary.lib.util import rethrow
#from rmake.lib.apiutils import register, freeze, thaw
from rmake.errors import OpenError
from rmake.messagebus import rpclib
from rmake.multinode import nodetypes
from rmake.multinode.server import messagebus
from mcp import dispatcher
from mcp.mcp_error import BuildSystemUnreachableError
from mcp.messagebus import nodetypes as mcp_nodetypes


def findBusNode(busClient, sessionClass):
    """
    Return the sessionId of a node on the message bus with the given
    C{sessionClass}, or C{None} if no node with that class is connected.
    """
    busProxy = messagebus.MessageBusRPCClient(busClient)
    for nodeId, nodeClass in sorted(busProxy.listSessions().items()):
        if nodeClass == sessionClass:
            return nodeId
    return None


class DispatcherRPCClient(rpclib.SessionProxy):
    def __init__(self, busClient, dispatcherId=None):
        if dispatcherId is None:
            try:
                dispatcherId = findBusNode(busClient,
                        dispatcher.Dispatcher.sessionClass)
            except OpenError, err:
                rethrow(BuildSystemUnreachableError)

            if dispatcherId is None:
                raise BuildSystemUnreachableError(
                        "Could not contact the dispatcher")

        rpclib.SessionProxy.__init__(self, dispatcher.Dispatcher, busClient,
                dispatcherId)
{'fraction_non_alphanumeric': 0.06662134602311352, 'fraction_numerical': 0.002719238613188307, 'mean_word_length': 3.0931849791376913, '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': '2826600', 'n_tokens_mistral': 830, 'n_tokens_neox': 795, 'n_words': 254}