fix ldconfig.ldr parsing

Tue, 16 Jan 2018 17:29:40 +0200

author
Santeri Piippo
date
Tue, 16 Jan 2018 17:29:40 +0200
changeset 11
b42788f5d0a9
parent 10
ccc33237949e
child 12
eb74680a5e43

fix ldconfig.ldr parsing

colours.py file | annotate | diff | comparison | revisions
--- a/colours.py	Tue Jan 16 17:25:22 2018 +0200
+++ b/colours.py	Tue Jan 16 17:29:40 2018 +0200
@@ -74,12 +74,7 @@
     # parse 0 !COLOUR and get the name
     match = re.search(r'^0\s+!COLOUR\s([^ ]+)', line)
     if not match:
-        # failed, check if it's an empty line or comment:
-        if not line or line.startswith('0'):
-            return None
-        else:
-            # failed too, thus the line is bad
-            raise ValueError('Bad LDConfig.ldr line')
+        raise ValueError('Bad LDConfig.ldr line: ' + line)
     # replace underscores for readability
     name = match.group(1).replace('_', ' ')
     # parse tags
@@ -98,8 +93,9 @@
         Parses LDConfig.ldr and returns pairs
     '''
     for line in ldconfig_ldr:
-        colour = parse_ldconfig_ldr_line(line)
-        if colour:
+        line = line.strip()
+        if line.startswith('0 !COLOUR'):
+            colour = parse_ldconfig_ldr_line(line)
             yield (colour['code'], colour)
 
 class colours:
@@ -128,4 +124,4 @@
 if __name__ == '__main__':
     from sys import argv
     with open(argv[1]) as ldconfig_ldr:
-        load_colours(ldconfig_ldr)
\ No newline at end of file
+        load_colours(ldconfig_ldr)

mercurial