<commit_before>#!/usr/bin/env python

"""allert.py: OS independant Allert handling ..."""

__author__ = "<EMAIL>"
__license__ = "LGPL"
__version__ = "0.0.1"
__email__   = "<NAME>"
__project__ = "harpy"
__date__    = "01-10-2015"

import os
import sys
import platform
from subprocess import call, PIPE, Popen

# PiBlinker is not critical but should be imported if it exists
try:
    from piblinker import PiBlinker
except:
    pass


class AllertManager():

    def __init__(self):
        self.led_mode = False
        self.cmd = self.detectOS()

    def detectOS(self):
        """ Detect the running OS and set the notification cmd """
        systm = platform.system()

        # Detect Linux
        if systm == "Linux":
            if "Ubuntu" in platform.linux_distribution():
                cmd = "notify-send \"%s\""
            # Detect Raspberry Pi
            elif "armv7l" in platform.uname()[4]:
                try:
                    self.pb = PiBlinker()
                    self.led_mode = True
                except NameError:
                    print "Piblinker not found falling back to wall"
                except ImportError:
                    print "Piblinker shield missing falling back to wall"
                cmd = "wall \"%s\""
            else:
                cmd = "wall \"%s\""
        # Detect Windows
        elif systm == "win32":
            cmd = "cscript winallert.vbs \"%s\""
        # Requires gem install terminal notifier

        # Detect MacOS
        elif systm == "darwin":
            cmd = "terminal-notifier -message \"%s\""
        else:
            print "Did not detect known system, notifications disabled"
            raise ImportError
        return cmd

    def broadcast(self, message, color=None):
        """ Send the notification message and blink LED if color"""
        # If the sheild is attached use it as well
        if self.led_mode and color:
            try:
                pb.led_print(color, message)
                return
            except NameError:<commit_msg>allert.py: Updated to utilize the new detection method of piblinker<commit_after>#!/usr/bin/env python

"""allert.py: OS independant Allert handling ..."""

__author__ = "<EMAIL>"
__license__ = "LGPL"
__version__ = "0.0.1"
__email__   = "<NAME>"
__project__ = "harpy"
__date__    = "01-10-2015"

import os
import sys
import platform
from subprocess import call, PIPE, Popen

# PiBlinker is not critical but should be imported if it exists
try:
    from piblinker import PiBlinker
except:
    pass


class AllertManager():

    def __init__(self):
        self.led_mode = False
        self.cmd = self.detectOS()

    def detectOS(self):
        """ Detect the running OS and set the notification cmd """

        systm = platform.system()

        # Detect Linux
        if systm == "Linux":
            if "Ubuntu" in platform.linux_distribution():
                cmd = "notify-send \"%s\""
            # Detect Raspberry Pi
            elif "armv7l" in platform.uname()[4]:
                try:
                    self.pb = PiBlinker()
                    test_res = self.pb.test_hardware()
                    if test_res: self.led_mode = True
                    else: 
                        print "Piblinker shield missing,using wall"
                        del(self.pb)
                except NameError:
                    print "Piblinker not found falling back to wall"
                cmd = "wall \"%s\""
            else:
                cmd = "wall \"%s\""
        # Detect Windows
        elif systm == "win32":
            cmd = "cscript winallert.vbs \"%s\""
        # Requires gem install terminal notifier

        # Detect MacOS
        elif systm == "darwin":
            cmd = "terminal-notifier -message \"%s\""
        else:
            print "Did not detect known system, notifications disabled"
            raise ImportError
        return cmd

    def broadcast(self, message, color=None):
        """ Send the notification message and blink LED if color"""

        # If the sheild is attached use it as well
        if self.led_mode and color:
            try:
                pb.led_print(color, message)
                return
            except NameError:
{'fraction_non_alphanumeric': 0.09400094473311289, 'fraction_numerical': 0.007085498346717053, 'mean_word_length': 1.7130044843049328, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, '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': '6755601', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1145, 'n_words': 387}