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
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
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'])
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)
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))
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))
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])
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])
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])
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])
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))
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'])
def testDedupeValue__extract_app_paths(self): """ common.extract_app_paths: removes duplicate values. """ self.assertEqual(common.extract_app_paths(['cat', 'cat']), ['/bin/cat'])