예제 #1
0
파일: notify.py 프로젝트: xtrementl/focus
    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
예제 #2
0
파일: notify.py 프로젝트: xtrementl/focus
    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
예제 #3
0
파일: test_common.py 프로젝트: nyimbi/focus
 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'])
예제 #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'])
예제 #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)
예제 #6
0
파일: apps.py 프로젝트: 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))
예제 #7
0
파일: test_common.py 프로젝트: nyimbi/focus
    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)
예제 #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))
예제 #9
0
파일: apps.py 프로젝트: 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))
예제 #10
0
파일: notify.py 프로젝트: xtrementl/focus
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])
예제 #11
0
파일: notify.py 프로젝트: xtrementl/focus
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])
예제 #12
0
파일: notify.py 프로젝트: xtrementl/focus
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])
예제 #13
0
파일: notify.py 프로젝트: xtrementl/focus
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])
예제 #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))
예제 #15
0
파일: test_common.py 프로젝트: nyimbi/focus
 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'])
예제 #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'])
예제 #17
0
파일: test_common.py 프로젝트: nyimbi/focus
 def testDedupeValue__extract_app_paths(self):
     """ common.extract_app_paths: removes duplicate values.
         """
     self.assertEqual(common.extract_app_paths(['cat', 'cat']),
                      ['/bin/cat'])
예제 #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'])