src/eric7/PluginManager/PluginInstallDialog.py

branch
eric7
changeset 10061
8bdad5699288
parent 9653
e67609152c5e
child 10080
f834e57a5b13
--- a/src/eric7/PluginManager/PluginInstallDialog.py	Wed May 24 10:31:09 2023 +0200
+++ b/src/eric7/PluginManager/PluginInstallDialog.py	Wed May 24 10:45:11 2023 +0200
@@ -335,37 +335,49 @@
         needsRestart = False
         pyqtApi = 0
         doCompile = True
+
+        separator = "="  # initialize for old-style header
+        insideHeader = False
         for line in pluginSource.splitlines():
-            if line.startswith("packageName"):
-                tokens = line.split("=")
-                if (
-                    tokens[0].strip() == "packageName"
-                    and tokens[1].strip()[1:-1] != "__core__"
-                ):
-                    if tokens[1].strip()[0] in ['"', "'"]:
-                        packageName = tokens[1].strip()[1:-1]
-                    else:
-                        if tokens[1].strip() == "None":
-                            packageName = "None"
-            elif line.startswith("internalPackages"):
-                tokens = line.split("=")
-                token = tokens[1].strip()[1:-1]
-                # it is a comma separated string
-                internalPackages = [p.strip() for p in token.split(",")]
-            elif line.startswith("needsRestart"):
-                tokens = line.split("=")
-                needsRestart = tokens[1].strip() == "True"
-            elif line.startswith("pyqtApi"):
-                tokens = line.split("=")
-                with contextlib.suppress(ValueError):
-                    pyqtApi = int(tokens[1].strip())
-            elif line.startswith("doNotCompile"):
-                tokens = line.split("=")
-                if tokens[1].strip() == "True":
-                    doCompile = False
+            line = line.strip()
+            if line.startswith("# Start-Of-Header"):
+                insideHeader = True
+                continue
+
+            if not insideHeader:
+                continue
+
+            if line.startswith("__header__"):
+                # it is a new style header
+                separator = ":"
+                continue
             elif line.startswith("# End-Of-Header"):
                 break
 
+            with contextlib.suppress(ValueError):
+                key, value = line.split(separator)
+                key = key.strip().strip("\"'")
+                value = value.strip().rstrip(",")
+                # get rid of trailing ',' in new-style header
+
+                if key == "packageName":
+                    if value[1:-1] != "__core__":
+                        if value[0] in ['"', "'"]:
+                            packageName = value[1:-1]
+                        else:
+                            if value == "None":
+                                packageName = "None"
+                elif key == "internalPackages":
+                    # it is a comma separated string
+                    internalPackages = [p.strip() for p in value[1:-1].split(",")]
+                elif key == "needsRestart":
+                    needsRestart = value == "True"
+                elif key == "pyqtApi":
+                    with contextlib.suppress(ValueError):
+                        pyqtApi = int(value)
+                elif key == "doNotCompile" and value == "True":
+                    doCompile = False
+
         if not packageName:
             return (
                 False,

eric ide

mercurial