<commit_before># Copyright (C) 2016 OpenMotics BV
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
The outputs module contains classes to track the current state of the outputs on
the master.
"""

from __future__ import absolute_import
from threading import Lock
import six
import logging

logger = logging.getLogger("openmotics")


class OutputStatus(object):
    """ Contains a cached version of the current output of the controller. """

    def __init__(self, on_output_change=None):
        """
        Create a status object using a list of outputs (can be None),
        and a refresh period: the refresh has to be invoked explicitly.
        """
        self._outputs = {}
        self._on_output_change = on_output_change
        self._merge_lock = Lock()

    def partial_update(self, on_outputs):  # type: (list) -> None
        """
        Update the status of the outputs using a list of tuples containing the
        light id an the dimmer value of the lights that are on.
        """
        on_dict = {}
        for on_output in on_outputs:
            on_dict[on_output[0]] = on_output[1]

        with self._merge_lock:
            for output_id, output in six.iteritems(self._outputs):
                self._update(output_id, {'status': output_id in on_dict,
                                         'dimmer': on_dict.get(output_id)})

    def full_update(self, outputs):
        """ Update the status of the outputs using a list of Outputs. """
        obsolete_ids = list(self._outputs.keys())
        for output in outputs:
            output_id = output['id']
            if output_id in obsolete_ids:
                obsolete_ids.remove(output_id)
            changed = self._create_or_update(output_id, output)
            if changed:
                self._report_change(output_id)
        for output_id in obsolete_ids:
            self._delete(output_id)

    def get_outputs(self):
        """ Return the list of Outputs. """
        return list(self._outputs.values())<commit_msg>Fixed merge lock on outputs<commit_after># Copyright (C) 2016 OpenMotics BV
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
The outputs module contains classes to track the current state of the outputs on
the master.
"""

from __future__ import absolute_import
from threading import Lock
import six
import logging

logger = logging.getLogger("openmotics")


class OutputStatus(object):
    """ Contains a cached version of the current output of the controller. """

    def __init__(self, on_output_change=None):
        """
        Create a status object using a list of outputs (can be None),
        and a refresh period: the refresh has to be invoked explicitly.
        """
        self._outputs = {}
        self._on_output_change = on_output_change
        self._merge_lock = Lock()

    def partial_update(self, on_outputs):  # type: (list) -> None
        """
        Update the status of the outputs using a list of tuples containing the
        light id an the dimmer value of the lights that are on.
        """
        on_dict = {}
        for on_output in on_outputs:
            on_dict[on_output[0]] = on_output[1]

        for output_id, output in six.iteritems(self._outputs):
            self._update(output_id, {'status': output_id in on_dict,
                                     'dimmer': on_dict.get(output_id)})

    def full_update(self, outputs):
        """ Update the status of the outputs using a list of Outputs. """
        obsolete_ids = list(self._outputs.keys())
        for output in outputs:
            output_id = output['id']
            if output_id in obsolete_ids:
                obsolete_ids.remove(output_id)
            changed = self._create_or_update(output_id, output)
            if changed:
                self._report_change(output_id)
        for output_id in obsolete_ids:
            self._delete(output_id)

    def get_outputs(self):
        """ Return the list of Outputs. """
        return list(self._outputs.values())
{'fraction_non_alphanumeric': 0.07634759255706887, 'fraction_numerical': 0.002685593708037598, 'mean_word_length': 2.671830985915493, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1855964', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1344, 'n_words': 563}