Add support for toolchains stored in the windows registry
[bertos.git] / wizard / winreg_importer.py
index 714d0a7893aa1fa6177b56db3ce693ae1ba24426..2030934e9f163efb3df191e56f4776f816706a21 100644 (file)
 \r
 from _winreg import *\r
 \r
-DIR_KEY = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Develer\BeRTOS SDK\BeRTOS Dirs")\r
+# Open the registry keys. When the keys don't exist it do nothing\r
+try:\r
+    DIR_KEY = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Develer\BeRTOS SDK\BeRTOS Dirs")\r
+except WindowsError:\r
+    DIR_KEY = None\r
+\r
+try:\r
+    TOOLCHAIN_KEY = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Develer\BeRTOS SDK\Toolchain Executables")\r
+except WindowsError:\r
+    TOOLCHAIN_KEY = None\r
 \r
 def getBertosDirs():\r
+    """\r
+    Returns the path of the BeRTOS versions installed by the BeRTOS SDK installer.\r
+    """\r
+    return getFromRegistry(DIR_KEY)\r
+\r
+def getBertosToolchains():\r
+    """\r
+    Returns the path of the executables of the toolchains installed by the BeRTOS\r
+    SDK installer.\r
+    """\r
+    return getFromRegistry(TOOLCHAIN_KEY)\r
+\r
+def getFromRegistry(key):\r
+    """\r
+    Returns the value of all the named values of the given key.\r
+    """\r
     index = 0\r
-    dirs = []\r
-    while True:\r
-        try:\r
-            dir = EnumValue(DIR_KEY, index)[1]\r
-            dirs.append(dir)\r
-            index += 1\r
-        except WindowsError:\r
-            break\r
-    return dirs\r
-       
\ No newline at end of file
+    items = []\r
+    if key:\r
+        while True:\r
+            try:\r
+                item = EnumValue(key, index)[1]\r
+                items.append(item)\r
+                index += 1\r
+            except WindowsError:\r
+                break\r
+    return items
\ No newline at end of file