Utilities/__init__.py

changeset 5586
0e5421d679e7
parent 5421
ce62341e81b6
child 5587
ea526b78ee6c
--- a/Utilities/__init__.py	Tue Mar 07 18:42:41 2017 +0100
+++ b/Utilities/__init__.py	Tue Mar 07 18:46:09 2017 +0100
@@ -656,7 +656,7 @@
     return extractFlags(source)
 
 
-def extractLineFlags(line, startComment="#", endComment=""):
+def extractLineFlags(line, startComment="#", endComment="", flagsLine=False):
     """
     Function to extract flags starting and ending with '__' from a line
     comment.
@@ -664,17 +664,22 @@
     @param line line to extract flags from (string)
     @keyparam startComment string identifying the start of the comment (string)
     @keyparam endComment string identifying the end of a comment (string)
+    @keyparam flagsLine flag indicating to check for a flags only line (bool)
     @return list containing the extracted flags (list of strings)
     """
     flags = []
     
-    pos = line.rfind(startComment)
-    if pos >= 0:
-        comment = line[pos + len(startComment):].strip()
-        if endComment:
-            comment = comment.replace("endComment", "")
-        flags = [f.strip() for f in comment.split()
-                 if (f.startswith("__") and f.endswith("__"))]
+    if not flagsLine or (
+       flagsLine and line.strip().startswith(startComment)):
+        pos = line.rfind(startComment)
+        if pos >= 0:
+            comment = line[pos + len(startComment):].strip()
+            if endComment:
+                endPos = line.rfind(endComment)
+                if endPos >= 0:
+                    comment = comment[:endPos]
+            flags = [f.strip() for f in comment.split()
+                     if (f.startswith("__") and f.endswith("__"))]
     return flags
 
 

eric ide

mercurial