Anonymous avatar Anonymous committed 7f698a0

bugtraq: Fallback to old interface

If IBugtrackProvider2 interface is not working. Don't fail on badly registered
plugins.

Closes #1474

Comments (0)

Files changed (1)

tortoisehg/hgtk/bugtraq.py

         pathlist = bstrarray.from_param(())
 
         bugtr = self._get_bugtraq_object()
-        (bugid, revPropNames, revPropValues, newmessage) = bugtr.GetCommitMessage2(
-                0, parameters, commonurl, commonurl, pathlist, logmessage, bugid)
+        if self.supports_bugtraq2_interface():
+            (bugid, revPropNames, revPropValues, newmessage) = bugtr.GetCommitMessage2(
+                    0, parameters, commonurl, commonroot, pathlist, logmessage, bugid)
+        else:
+            newmessage = bugtr.GetCommitMessage(
+                    0, parameters, commonroot, pathlist, logmessage)
+
         return newmessage
 
     def on_commit_finished(self, logmessage):
+        if not self.supports_bugtraq2_interface():
+            return ""
+
         commonroot = ""
         bstrarray = _midlSAFEARRAY(comtypes.BSTR)
         pathlist = bstrarray.from_param(())
         return options
     
     def has_options(self):
+        if not self.supports_bugtraq2_interface():
+            return False
+
         bugtr = self._get_bugtraq_object()
         return bugtr.HasOptions() != 0
-        
+
     def get_link_text(self, parameters):
         bugtr = self._get_bugtraq_object()
         return bugtr.GetLinkText(0, parameters)
 
+    def supports_bugtraq2_interface(self):
+        bugtr = self._get_bugtraq_object()
+        try:
+            bugtr.HasOptions()
+            return True
+        except ValueError:
+            return False
+
+
 def get_issue_plugins():
     cm = pythoncom.CoCreateInstance(pythoncom.CLSID_StdComponentCategoriesMgr,
             None, pythoncom.CLSCTX_INPROC,pythoncom.IID_ICatInformation)
 
 def get_plugin_name(clsid):
     key = OpenKey(HKEY_CLASSES_ROOT, r"CLSID\%s" % clsid)
-    keyvalue = QueryValueEx(key, None) 
+    try:
+        keyvalue = QueryValueEx(key, None)[0]
+    except WindowsError:
+        keyvalue = None
     key.Close()
-    return keyvalue[0]
+    return keyvalue
 
 def get_issue_plugins_with_names():
     pluginclsids = get_issue_plugins()
-    return [(key, get_plugin_name(key)) for key in pluginclsids]
+    keyandnames = [(key, get_plugin_name(key)) for key in pluginclsids]
+    return [kn for kn in keyandnames if kn[1] is not None]
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.