<commit_before>import os
import struct
import logging
import asyncore, socket
import sdminfoxml_parser

logger = logging.getLogger(__name__)

class McastClient(asyncore.dispatcher):
    """Generic class to receive the multicast XML docs."""

    def __init__(self, group, port, name=""):
        asyncore.dispatcher.__init__(self)
        self.name = name
        self.group = group
        self.port = port
        addrinfo = socket.getaddrinfo(group, None)[0]
        self.create_socket(addrinfo[0], socket.SOCK_DGRAM)
        self.set_reuse_addr()
        self.bind(('',port))
        mreq = socket.inet_pton(addrinfo[0],addrinfo[4][0]) \
                + struct.pack('=I', socket.INADDR_ANY)
        self.socket.setsockopt(socket.IPPROTO_IP, 
                socket.IP_ADD_MEMBERSHIP, mreq)
        self.read = None

    def handle_connect(self):
        logger.debug('connect %s group=%s port=%d' % (self.name, 
            self.group, self.port))

    def handle_close(self):
        logger.debug('close %s group=%s port=%d' % (self.name, 
            self.group, self.port))

    def writeable(self):
        return False

    def handle_read(self):
        self.read = self.recv(100000)
        logger.debug('read ' + self.name + ' ' + self.read)
        try:
            self.parse()
        except Exception as e:
            logger.exception("error handling '%s' message" % self.name)

    def handle_error(self, type, val, trace):
        logger.error('unhandled exception: ' + repr(val))


class SdminfoClient(McastClient):
    """Receives sdminfo XML, which is broadcast when the BDF is available.

    If the controller input is given, the
    controller.add_sdminfo(sdminfo) method will be called for every
    document received. Controller is defined as a class in the main
    controller script, and runs job launching.
    """

    def __init__(self,controller=None):
        McastClient.__init__(self,'192.168.3.11',55002,'sdminfo')
        self.controller = controller

    def parse(self):
        sdminfo = sdminfoxml_parser.parseString(self.read)
        logger.info("Read sdminfo datasetID='%s' scanNo=%d intents=%s" % (sdminfo.datasetID,<commit_msg>renaming datasetID to projectID after correlator change<commit_after>import os
import struct
import logging
import asyncore, socket
import sdminfoxml_parser

logger = logging.getLogger(__name__)

class McastClient(asyncore.dispatcher):
    """Generic class to receive the multicast XML docs."""

    def __init__(self, group, port, name=""):
        asyncore.dispatcher.__init__(self)
        self.name = name
        self.group = group
        self.port = port
        addrinfo = socket.getaddrinfo(group, None)[0]
        self.create_socket(addrinfo[0], socket.SOCK_DGRAM)
        self.set_reuse_addr()
        self.bind(('',port))
        mreq = socket.inet_pton(addrinfo[0],addrinfo[4][0]) \
                + struct.pack('=I', socket.INADDR_ANY)
        self.socket.setsockopt(socket.IPPROTO_IP, 
                socket.IP_ADD_MEMBERSHIP, mreq)
        self.read = None

    def handle_connect(self):
        logger.debug('connect %s group=%s port=%d' % (self.name, 
            self.group, self.port))

    def handle_close(self):
        logger.debug('close %s group=%s port=%d' % (self.name, 
            self.group, self.port))

    def writeable(self):
        return False

    def handle_read(self):
        self.read = self.recv(100000)
        logger.debug('read ' + self.name + ' ' + self.read)
        try:
            self.parse()
        except Exception as e:
            logger.exception("error handling '%s' message" % self.name)

    def handle_error(self, type, val, trace):
        logger.error('unhandled exception: ' + repr(val))


class SdminfoClient(McastClient):
    """Receives sdminfo XML, which is broadcast when the BDF is available.

    If the controller input is given, the
    controller.add_sdminfo(sdminfo) method will be called for every
    document received. Controller is defined as a class in the main
    controller script, and runs job launching.
    """

    def __init__(self,controller=None):
        McastClient.__init__(self,'192.168.3.11',55002,'sdminfo')
        self.controller = controller

    def parse(self):
        sdminfo = sdminfoxml_parser.parseString(self.read)
        logger.info("Read sdminfo projectID='%s' scanNo=%d intents=%s" % (sdminfo.projectID,
{'fraction_non_alphanumeric': 0.11424670004551661, 'fraction_numerical': 0.01137915339098771, 'mean_word_length': 2.8051948051948052, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 2, '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': '4519780', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1316, 'n_words': 321}