<commit_before>import pykka
import pylirc
import logging

from mopidy.core import CoreListener
from mopidy.utils import encoding, network, process

logger = logging.getLogger(__name__)

class IRControlFrontend(pykka.ThreadingActor, CoreListener):
    def __init__(self, config, core):
        super(IRControlFrontend, self).__init__()
        self.core = core
        self.configFile = generateLircConfigFile(config)

    def on_start(self):
        logger.info('IRControl started')

    def on_stop(self):
        logger.info('IRControl stopped')
     
    def generateLircConfig(self, config):
        '''Returns file name of generate config file for pylirc'''
        return "/tmp/123165.lircrc"<commit_msg>pylirc somehow integrated. Do logging of received commands.<commit_after>import pykka
import pylirc
import logging
import thread
import tempfile

from mopidy.core import CoreListener
from mopidy.utils import encoding, network, process

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

LIRC_PROG_NAME = "mopidyIRControl"

class IRControlFrontend(pykka.ThreadingActor, CoreListener):
    def __init__(self, config, core):
        super(IRControlFrontend, self).__init__()
        self.core = core
        self.configFile = self.generateLircConfigFile(config['IRControl'])
        logger.info(self.configFile)
        logger.debug('test debug')

    def on_start(self):
        logger.info('IRControl started')
        self.started = True
        self.startPyLirc()

    def on_stop(self):
        logger.info('IRControl stopped')
        self.started = False
     
    def generateLircConfigFile(self, config):
        '''Returns file name of generate config file for pylirc'''
        f = tempfile.NamedTemporaryFile(delete=False)
        for action in config:
            entry = 'begin\n    prog={2}\n    button={0}\n    config={1}\nend\n'.format(config[action], action, LIRC_PROG_NAME)
            f.write(entry)
        f.close()
        return f.name

    def startPyLirc(self):
        if(pylirc.init(LIRC_PROG_NAME, self.configFile, 1)):
            while(self.started):
                logger.info('get next code from pylirc')
                s = pylirc.nextcode(1)
                logger.info(s)
                self.handleNextCode(s)
            pylirc.exit()

    def handleNextCode(self, s):
        if s:
            self.handleLircCommand(s)

    def handleLircCommand(self, s):
        for code in s:
            if(code['config'] == 'playpause' and self.core.state == self.core.PlaybackState.PAUSED):
                self.core.resume()
            elif (code['config'] == 'playpause' and self.core.state == self.core.PlaybackState.PLAYING):
                self.core.pause()
            logger.info('Command: {0}'.format(code['config']))
{'fraction_non_alphanumeric': 0.10639827462257369, 'fraction_numerical': 0.004313443565780014, 'mean_word_length': 2.7608108108108107, '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': '5598035', 'n_tokens_mistral': 855, 'n_tokens_neox': 811, 'n_words': 186}