diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | python/deskbar-handler/tracker-handler-static.py | 5 | ||||
-rw-r--r-- | python/deskbar-handler/tracker-handler.py | 71 | ||||
-rw-r--r-- | python/deskbar-handler/tracker-module.py | 72 |
4 files changed, 100 insertions, 54 deletions
@@ -1,6 +1,12 @@ +2007-10-19 Marcus Fritzsch <m at fritschy dot de> + + * deskbar handlers, Fixed gnome bugs #487444, #486733 + * added some more exception catchers, in general where actions + are executed + 2007-10-15 Patch from Halton Huo <Halton.Huo@Sun.COM> * fixed crasher on solaris diff --git a/python/deskbar-handler/tracker-handler-static.py b/python/deskbar-handler/tracker-handler-static.py index a87956c95..5f797321e 100644 --- a/python/deskbar-handler/tracker-handler-static.py +++ b/python/deskbar-handler/tracker-handler-static.py @@ -28,7 +28,10 @@ class TrackerSearchToolMatch (deskbar.Match.Match): self._icon = deskbar.Utils.load_icon ('tracker') def action(self, text=None): - gobject.spawn_async(['tracker-search-tool', self.name], flags=gobject.SPAWN_SEARCH_PATH) + try: + gobject.spawn_async(['tracker-search-tool', self.name], flags=gobject.SPAWN_SEARCH_PATH) + except gobject.GError, e: + print >> sys.stderr, "*** Error when executing tracker-search-tool:", e def get_verb(self): return _('Search for %s with Tracker Search Tool') % ('<b>%(name)s</b>') diff --git a/python/deskbar-handler/tracker-handler.py b/python/deskbar-handler/tracker-handler.py index 3c8698b0d..cf0b9b747 100644 --- a/python/deskbar-handler/tracker-handler.py +++ b/python/deskbar-handler/tracker-handler.py @@ -129,38 +129,38 @@ class TrackerLiveSearchMatch (deskbar.Match.Match): return self.result['uri'] def action(self, text=None): - if TYPES[self.result['type']].has_key('action'): - if isinstance (TYPES[self.result['type']]['action'], dict): + try: + if TYPES[self.result['type']].has_key('action'): + if isinstance (TYPES[self.result['type']]['action'], dict): + try: + key = TYPES[self.result['type']]['action']['key'] + cmd = TYPES[self.result['type']]['action'][self.result[key]] + except: + print >> sys.stderr, "Unknown action for URI %s (Error: %s)" % (self.result['uri'], sys.exc_info()[1]) + return + else: + cmd = TYPES[self.result['type']]['action'] + cmd = map(lambda arg : arg % self.result, cmd.split()) # we need this to handle spaces correctly + + print 'Opening Tracker hit with command:', cmd try: - key = TYPES[self.result['type']]['action']['key'] - cmd = TYPES[self.result['type']]['action'][self.result[key]] - except: - print >> sys.stderr, "Unknown action for URI %s (Error: %s)" % (self.result['uri'], sys.exc_info()[1]) - return - else: - cmd = TYPES[self.result['type']]['action'] - cmd = map(lambda arg : arg % self.result, cmd.split()) # we need this to handle spaces correctly - - print 'Opening Tracker hit with command:', cmd - try: - # deskbar >= 2.17 - deskbar.Utils.spawn_async(cmd) - except AttributeError: - # deskbar <= 2.16 - gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) - else: - if self.result.has_key ('desktop'): - self.result['desktop'].launch([]) + # deskbar >= 2.17 + deskbar.Utils.spawn_async(cmd) + except AttributeError: + # deskbar <= 2.16 + gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) else: - try: # catch errors on gnome.url_show() + if 'desktop' in self.result: + self.result['desktop'].launch([]) + else: try: # deskbar >= 2.17 deskbar.Utils.url_show ('file://'+self.result['uri']) except AttributeError: gnome.url_show('file://'+self.result['uri']) print 'Opening Tracker hit:', self.result['uri'] - except: - print >> sys.stderr, '*** Could not open URL %s: %s' % (self.result['uri'], sys.exc_info ()[1]) + except: + print >> sys.stderr, '*** Could not open URL %s: %s' % (self.result['uri'], sys.exc_info ()[1]) def get_category (self): try: @@ -194,11 +194,15 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler): self.conv_re = re.compile (r'^.*?/logs/([^/]+)/([^/]+)/([^/]+)/(.+?)\.(:?txt|html)$') # all, proto, account, to-whom, time def handle_email_hits (self, info, output): + if len (info) < 5: + print >> sys.stderr, "*** Hit for Service Emails had incomplete data, ignoring (%s)" % info[0] + return 0 output['title'] = cgi.escape(info[3]) output['publisher'] = cgi.escape(info[4]) output['mua'] = info[2] if output['mua'] == 'Thunderbird/Email': output['uri'] = info[0] + return 1 def handle_conversation_hits (self, info, output): m = self.conv_re.match (output['escaped_uri']) @@ -230,6 +234,9 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler): # ], # signature=dbus.Signature('s')) # Strip %U or whatever arguments in Exec field + if len (info) < 6: + print >> sys.stderr, "*** Hit for Service Applications had incomplete data, ignoring (%s)" % info[0] + return 0 output['app_name'] = re.sub(r'%\w+', '', info [4]).strip () output['app_basename'] = cgi.escape (os.path.basename (output['app_name'])) output['app_name'] = cgi.escape (output['app_name']) @@ -238,11 +245,12 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler): output['name'] = cgi.escape (info [3]) output['icon'] = info [5] # no escaping, as it is not displayed as a string - desktop = parse_desktop_file (output['uri']) + desktop = parse_desktop_file (info[0]) if not desktop: print >> sys.stderr, '*** Could not read .desktop file: %s' % info[0] else: output['desktop'] = desktop + return 1 def receive_hits (self, qstring, hits, max): matches = [] @@ -250,6 +258,10 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler): for info in hits: output = {} + if len (info) < 2: + print >> sys.stderr, "*** Hit had incomplete data, ignoring" + continue + info = [str (i) for i in info] output['escaped_uri'] = cgi.escape (info[0]) @@ -261,13 +273,16 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler): output['type'] = 'Files' if output['type'] == 'Emails': - self.handle_email_hits (info, output) + if not self.handle_email_hits (info, output): + continue elif output['type'] in ('GaimConversations', 'Conversations'): - self.handle_conversation_hits (info, output) + if not self.handle_conversation_hits (info, output): + continue elif output['type'] == 'Applications': - self.handle_application_hits (info, output) + if not self.handle_application_hits (info, output): + continue # applications are launched by .desktop file, if not readable: exclude if output['type'] != 'Applications' or output.has_key ('desktop'): diff --git a/python/deskbar-handler/tracker-module.py b/python/deskbar-handler/tracker-module.py index ebbf94469..be86fc84e 100644 --- a/python/deskbar-handler/tracker-module.py +++ b/python/deskbar-handler/tracker-module.py @@ -23,7 +23,7 @@ from deskbar.handlers.actions.OpenDesktopFileAction import \ from deskbar.handlers.actions.ShowUrlAction import \ ShowUrlAction from deskbar.handlers.actions.ActionsFactory import \ - get_actions_for_uri + get_actions_for_uri import gettext gettext.install('tracker') @@ -55,8 +55,11 @@ class TrackerSearchToolAction (deskbar.interfaces.Action): self.name = name def activate(self, text=None): - gobject.spawn_async(['tracker-search-tool', self.name], \ - flags=gobject.SPAWN_SEARCH_PATH) + try: + gobject.spawn_async(['tracker-search-tool', self.name], \ + flags=gobject.SPAWN_SEARCH_PATH) + except gobject.GError, e: + print >> sys.stderr, "*** Error when executing tracker-search-tool:", e def get_verb(self): return _('Search for %s with Tracker Search Tool') % '<b>%(name)s</b>' @@ -236,26 +239,29 @@ class TrackerLiveSearchAction (deskbar.interfaces.Action): return _('Open file %s\nin %s') % ('<b>%(base)s</b>', '<i>%(dir)s</i>') def activate (self, text=None): - if TYPES[self.result['type']].has_key('action'): - if isinstance (TYPES[self.result['type']]['action'], dict): - try: - key = TYPES[self.result['type']]['action']['key'] - cmd = TYPES[self.result['type']]['action'][self.result[key]] - except: - print >> sys.stderr, "Unknown action for URI %s (Error: %s)" % (self.result['uri'], sys.exc_info()[1]) - return - else: - cmd = TYPES[self.result['type']]['action'] - cmd = map(lambda arg : arg % self.result, cmd.split()) # we need this to handle spaces correctly - - print 'Opening Tracker hit with command:', cmd - deskbar.core.Utils.spawn_async(cmd) - else: - if self.desktop: - self.desktop.launch ([]) + try: + if TYPES[self.result['type']].has_key('action'): + if isinstance (TYPES[self.result['type']]['action'], dict): + try: + key = TYPES[self.result['type']]['action']['key'] + cmd = TYPES[self.result['type']]['action'][self.result[key]] + except: + print >> sys.stderr, "Unknown action for URI %s (Error: %s)" % (self.result['uri'], sys.exc_info()[1]) + return + else: + cmd = TYPES[self.result['type']]['action'] + cmd = map(lambda arg : arg % self.result, cmd.split()) # we need this to handle spaces correctly + + print 'Opening Tracker hit with command:', cmd + deskbar.core.Utils.spawn_async(cmd) else: - deskbar.core.Utils.url_show ('file://'+url_quote (self.result['uri'], ';?:@&=+$,./')) - print 'Opening Tracker hit:', url_quote (self.result['uri'], ';?:@&=+$,./') + if self.desktop: + self.desktop.launch ([]) + else: + deskbar.core.Utils.url_show ('file://'+url_quote (self.result['uri'], ';?:@&=+$,./')) + print 'Opening Tracker hit:', url_quote (self.result['uri'], ';?:@&=+$,./') + except: + print >> sys.stderr, "*** Could not activate Hit %s: %s" % (self.result['uri'], sys.exc_info()[1]) def init_names (self, fullpath): dirname, filename = os.path.split(fullpath) @@ -327,9 +333,13 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module): self.conv_re = re.compile (r'^.*?/logs/([^/]+)/([^/]+)/([^/]+)/(.+?)\.(:?txt|html)$') # all, proto, account, to-whom, time def handle_email_hits (self, info, output): + if len (info) < 5: + print >> sys.stderr, "*** Hit for Service Emails had incomplete data, ignoring (%s)" % info[0] + return 0 output['title'] = info[3] output['publisher'] = info[4] output['mua'] = info[2] + return 1 def handle_conversation_hits (self, info, output): output ['uri'] = info [0] @@ -348,6 +358,7 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module): nick_server = output['conv_from'].split ('@') if len (nick_server) > 1: output['conv_to'] = '%s on %s' % (output['conv_to'], nick_server[1]) + return 1 def handle_application_hits (self, info, output): # print info @@ -362,6 +373,9 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module): # ], # signature=dbus.Signature('s')) # Strip %U or whatever arguments in Exec field + if len (info) < 6: + print >> sys.stderr, "*** Hit for Service Applications had incomplete data, ignoring (%s)" % info[0] + return 0 output['app_name'] = re.sub(r'%\w+', '', info [4]).strip () output['app_basename'] = os.path.basename (output['app_name']) output['app_name'] = output['app_name'] @@ -372,6 +386,7 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module): desktop = parse_desktop_file (output['uri']) if desktop: output['desktop'] = desktop + return 1 def recieve_hits (self, qstring, hits, max): matches = [] @@ -379,6 +394,10 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module): for info in hits: output = {} + if len (info) < 2: + print >> sys.stderr, "*** Hit had incomplete data, ignoring" + continue + info = [str (i) for i in info] output['uri'] = info[0] @@ -389,13 +408,16 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module): output['type'] = 'Files' if output['type'] == 'Emails': - self.handle_email_hits (info, output) + if not self.handle_email_hits (info, output): + continue elif output['type'] == 'GaimConversations': - self.handle_conversation_hits (info, output) + if not self.handle_conversation_hits (info, output): + continue elif output['type'] == 'Applications': - self.handle_application_hits (info, output) + if not self.handle_application_hits (info, output): + continue # applications are launched by .desktop file, if not readable: exclude if output['type'] != 'Applications' or output.has_key ('desktop'): |