72 else: |
72 else: |
73 raise KeyError(str.format('Tag {} not found', tag)) |
73 raise KeyError(str.format('Tag {} not found', tag)) |
74 # parse 0 !COLOUR and get the name |
74 # parse 0 !COLOUR and get the name |
75 match = re.search(r'^0\s+!COLOUR\s([^ ]+)', line) |
75 match = re.search(r'^0\s+!COLOUR\s([^ ]+)', line) |
76 if not match: |
76 if not match: |
77 # failed, check if it's an empty line or comment: |
77 raise ValueError('Bad LDConfig.ldr line: ' + line) |
78 if not line or line.startswith('0'): |
|
79 return None |
|
80 else: |
|
81 # failed too, thus the line is bad |
|
82 raise ValueError('Bad LDConfig.ldr line') |
|
83 # replace underscores for readability |
78 # replace underscores for readability |
84 name = match.group(1).replace('_', ' ') |
79 name = match.group(1).replace('_', ' ') |
85 # parse tags |
80 # parse tags |
86 code = int(parse_tag('CODE')) |
81 code = int(parse_tag('CODE')) |
87 value = parse_tag('VALUE') |
82 value = parse_tag('VALUE') |
96 def parse_ldconfig_ldr(ldconfig_ldr): |
91 def parse_ldconfig_ldr(ldconfig_ldr): |
97 ''' |
92 ''' |
98 Parses LDConfig.ldr and returns pairs |
93 Parses LDConfig.ldr and returns pairs |
99 ''' |
94 ''' |
100 for line in ldconfig_ldr: |
95 for line in ldconfig_ldr: |
101 colour = parse_ldconfig_ldr_line(line) |
96 line = line.strip() |
102 if colour: |
97 if line.startswith('0 !COLOUR'): |
|
98 colour = parse_ldconfig_ldr_line(line) |
103 yield (colour['code'], colour) |
99 yield (colour['code'], colour) |
104 |
100 |
105 class colours: |
101 class colours: |
106 ''' |
102 ''' |
107 LDConfig colour namespace, exists for interactive mode and for |
103 LDConfig colour namespace, exists for interactive mode and for |