Example #1
0
    def __init__(self):
        super(Notify, self).__init__()
        self.messages = {}
        self.notify_func = None

        if common.IS_MACOSX:
            commands = ["terminal-notifier", "growlnotify"]

            while commands:
                try:
                    command = commands.pop()
                    common.extract_app_paths(command)
                except ValueError:
                    continue

                if command == "terminal-notifier":
                    self.notify_func = _terminal_notifier
                else:
                    self.notify_func = _growlnotify
                break  # found one

            # fallback to popup dialog
            if not self.notify_func:
                self.notify_func = _osx_popup

        else:
            self.notify_func = _dbus_notify
Example #2
0
    def __init__(self):
        super(Notify, self).__init__()
        self.messages = {}
        self.notify_func = None

        if common.IS_MACOSX:
            commands = ['terminal-notifier', 'growlnotify']

            while commands:
                try:
                    command = commands.pop()
                    common.extract_app_paths(command)
                except ValueError:
                    continue

                if command == 'terminal-notifier':
                    self.notify_func = _terminal_notifier
                else:
                    self.notify_func = _growlnotify
                break  # found one

            # fallback to popup dialog
            if not self.notify_func:
                self.notify_func = _osx_popup

        else:
            self.notify_func = _dbus_notify
Example #3
0
 def testCommandsExist__extract_app_paths(self):
     """ common.extract_app_paths: extracts values that are existing
         commands.
         """
     with self.assertRaises(ValueError):
         common.extract_app_paths(['non-existent-cmd'])
     with self.assertRaises(ValueError):
         common.extract_app_paths(['/bin/non-existent-cmd'])
Example #4
0
 def testCommandsExist__extract_app_paths(self):
     """ common.extract_app_paths: extracts values that are existing
         commands.
         """
     with self.assertRaises(ValueError):
         common.extract_app_paths(['non-existent-cmd'])
     with self.assertRaises(ValueError):
         common.extract_app_paths(['/bin/non-existent-cmd'])
Example #5
0
    def testMultiValue__extract_app_paths(self):
        """ common.extract_app_paths: supports multiple values.
            """
        vals = common.extract_app_paths(['cat', 'chmod'])
        expected = ['/bin/cat', '/bin/chmod']

        for val in vals:
            self.assertIn(val, expected)
Example #6
0
File: apps.py Project: nyimbi/focus
    def parse_option(self, option, block_name, *values):
        """ Parse app path values for option.
            """
        if option == 'run':
            option = 'start_' + option

        key = option.split('_', 1)[0]
        self.paths[key] = set(common.extract_app_paths(values))
Example #7
0
    def testMultiValue__extract_app_paths(self):
        """ common.extract_app_paths: supports multiple values.
            """
        vals = common.extract_app_paths(['cat', 'chmod'])
        expected = ['/bin/cat', '/bin/chmod']

        for val in vals:
            self.assertIn(val, expected)
Example #8
0
    def parse_option(self, option, block_name, *values):
        """ Parse app path values for option.
            """
        if option == 'run':
            option = 'start_' + option

        key = option.split('_', 1)[0]
        self.paths[key] = set(common.extract_app_paths(values))
Example #9
0
File: apps.py Project: nyimbi/focus
    def parse_option(self, option, block_name, *values):
        """ Parse app path values for option.
            """

        # treat arguments as part of the program name (support spaces in name)
        values = [x.replace(' ', '\\ ') if not x.startswith(os.sep) else x
                  for x in [str(v) for v in values]]

        if option == 'close':
            option = 'start_' + option

        key = option.split('_', 1)[0]
        self.paths[key] = set(common.extract_app_paths(values))
Example #10
0
def _terminal_notifier(title, message):
    """ Shows user notification message via `terminal-notifier` command.

        `title`
            Notification title.
        `message`
            Notification message.
        """

    try:
        paths = common.extract_app_paths(['terminal-notifier'])
    except ValueError:
        pass

    common.shell_process([paths[0], '-title', title, '-message', message])
Example #11
0
def _growlnotify(title, message):
    """ Shows growl notification message via `growlnotify` command.

        `title`
            Notification title.
        `message`
            Notification message.
        """

    try:
        paths = common.extract_app_paths(["growlnotify"])
    except ValueError:
        return

    common.shell_process([paths[0], "-t", title, "-m", message])
Example #12
0
def _terminal_notifier(title, message):
    """ Shows user notification message via `terminal-notifier` command.

        `title`
            Notification title.
        `message`
            Notification message.
        """

    try:
        paths = common.extract_app_paths(["terminal-notifier"])
    except ValueError:
        pass

    common.shell_process([paths[0], "-title", title, "-message", message])
Example #13
0
def _growlnotify(title, message):
    """ Shows growl notification message via `growlnotify` command.

        `title`
            Notification title.
        `message`
            Notification message.
        """

    try:
        paths = common.extract_app_paths(['growlnotify'])
    except ValueError:
        return

    common.shell_process([paths[0], '-t', title, '-m', message])
Example #14
0
    def parse_option(self, option, block_name, *values):
        """ Parse app path values for option.
            """

        # treat arguments as part of the program name (support spaces in name)
        values = [
            x.replace(' ', '\\ ') if not x.startswith(os.sep) else x
            for x in [str(v) for v in values]
        ]

        if option == 'close':
            option = 'start_' + option

        key = option.split('_', 1)[0]
        self.paths[key] = set(common.extract_app_paths(values))
Example #15
0
 def testSupportArguments__extract_app_paths(self):
     """ common.extract_app_paths: supports arguments for values.
         """
     self.assertEqual(common.extract_app_paths(['cp notexist nowhere']),
                      ['/bin/cp notexist nowhere'])
Example #16
0
 def testSupportArguments__extract_app_paths(self):
     """ common.extract_app_paths: supports arguments for values.
         """
     self.assertEqual(common.extract_app_paths(['cp notexist nowhere']),
                      ['/bin/cp notexist nowhere'])
Example #17
0
 def testDedupeValue__extract_app_paths(self):
     """ common.extract_app_paths: removes duplicate values.
         """
     self.assertEqual(common.extract_app_paths(['cat', 'cat']),
                      ['/bin/cat'])
Example #18
0
 def testDedupeValue__extract_app_paths(self):
     """ common.extract_app_paths: removes duplicate values.
         """
     self.assertEqual(common.extract_app_paths(['cat', 'cat']),
                      ['/bin/cat'])