<commit_before># -*- coding: utf-8 -*-
# This file is part of pdc-updater.
#
# pdc-updater is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# pdc-updater is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pdc-updater.  If not, see <http://www.gnu.org/licenses/>.
""" Fedmsg consumer that updates PDC.

Authors:    <NAME> <<EMAIL>>

"""

import fedmsg.consumers

import pdcupdater.handlers

import logging
log = logging.getLogger(__name__)


import pdc_client


class PDCUpdater(fedmsg.consumers.FedmsgConsumer):
    config_key = 'pdcupdater.enabled'

    def __init__(self, hub):
        config = hub.config

        # Ensure this is present, it should be a dict with a url and creds
        self.pdc_config = config['pdcupdater.pdc']

        # Load all our worker bits.
        self.handlers = list(pdcupdater.handlers.load_handlers(config))

        # Tell fedmsg to only notify us about topics that our handlers want.
        self.topic = [
            '.'.join([config['topic_prefix'], config['environment'], topic])
            for handler in self.handlers for topic in handler.topic_suffixes
        ]

        super(PDCUpdater, self).__init__(hub)

    def consume(self, msg):
        # Remove the envelope
        headers = msg.get('headers', {})  # https://github.com/mokshaproject/moksha/pull/35
        topic, msg = msg['topic'], msg['body']

        # Stuff topic and headers back into the message body, for convenience.
        msg['topic'] = topic
        msg['headers'] = headers

        idx = msg.get('msg_id', None)
        self.log.debug("Received %r, %r" % (idx, topic))

        pdc = pdc_client.PDCClient(**self.pdc_config)
        pdcupdater.utils.handle_message(pdc, self.handlers, msg)<commit_msg>Avoid renaming variables, to be less confusing.<commit_after># -*- coding: utf-8 -*-
# This file is part of pdc-updater.
#
# pdc-updater is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# pdc-updater is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pdc-updater.  If not, see <http://www.gnu.org/licenses/>.
""" Fedmsg consumer that updates PDC.

Authors:    <NAME> <<EMAIL>>

"""

import fedmsg.consumers

import pdcupdater.handlers

import logging
log = logging.getLogger(__name__)


import pdc_client


class PDCUpdater(fedmsg.consumers.FedmsgConsumer):
    config_key = 'pdcupdater.enabled'

    def __init__(self, hub):
        config = hub.config

        # Ensure this is present, it should be a dict with a url and creds
        self.pdc_config = config['pdcupdater.pdc']

        # Load all our worker bits.
        self.handlers = list(pdcupdater.handlers.load_handlers(config))

        # Tell fedmsg to only notify us about topics that our handlers want.
        self.topic = [
            '.'.join([config['topic_prefix'], config['environment'], topic])
            for handler in self.handlers for topic in handler.topic_suffixes
        ]

        super(PDCUpdater, self).__init__(hub)

    def consume(self, envelope):
        # Remove the envelope
        headers = envelope.get('headers', {})  # https://github.com/mokshaproject/moksha/pull/35
        topic, msg = envelope['topic'], envelope['body']

        # Stuff topic and headers back into the message body, for convenience.
        msg['topic'] = topic
        msg['headers'] = headers

        idx = msg.get('msg_id', None)
        self.log.debug("Received %r, %r" % (idx, topic))

        pdc = pdc_client.PDCClient(**self.pdc_config)
        pdcupdater.utils.handle_message(pdc, self.handlers, msg)
{'fraction_non_alphanumeric': 0.10113895216400912, 'fraction_numerical': 0.0018223234624145787, 'mean_word_length': 3.0884543761638734, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5683426', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1278, 'n_words': 449}