Example #1
0
    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
Example #2
0
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:
                pass
        cmd = self.cmd % message
        ret, err = Popen(
            cmd, stdout=PIPE, stderr=PIPE, shell=True).communicate()