/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to diff.py

  • Committer: Adeodato Simó
  • Date: 2007-07-16 10:27:35 UTC
  • mto: This revision was merged to the branch mainline in revision 234.
  • Revision ID: dato@net.com.org.es-20070716102735-kyxamu7okv8gf88a
Add a test for parse_colordiffrc, and fix the function to handle empty lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
250
250
 
251
251
        :param lang: a "Diff" gtksourceview.SourceLanguage object.
252
252
        """
253
 
        def parse_colordiffrc(fileobj):
254
 
            """Parse fileobj as a colordiff configuration file.
255
 
            
256
 
            :return: A dict with the key -> value pairs.
257
 
            """
258
 
            colors = {}
259
 
            for line in fileobj:
260
 
                if re.match(r'^\s*#', line):
261
 
                    continue
262
 
                key, val = line.split('=')
263
 
                colors[key.strip()] = val.strip()
264
 
            return colors
265
 
 
266
253
        colors = {}
267
254
 
268
255
        for f in ('~/.colordiffrc', '~/.colordiffrc.bzr-gtk'):
273
260
                except IOError, e:
274
261
                    warning('could not open file %s: %s' % (f, str(e)))
275
262
                else:
276
 
                    colors.update(parse_colordiffrc(f))
 
263
                    colors.update(DiffWindow.parse_colordiffrc(f))
277
264
                    f.close()
278
265
 
279
266
        if not colors:
311
298
                warning('not a valid color: %s' % color)
312
299
            else:
313
300
                lang.set_tag_style(tag_id, style)
 
301
 
 
302
    @staticmethod
 
303
    def parse_colordiffrc(fileobj):
 
304
        """Parse fileobj as a colordiff configuration file.
 
305
        
 
306
        :return: A dict with the key -> value pairs.
 
307
        """
 
308
        colors = {}
 
309
        for line in fileobj:
 
310
            if re.match(r'^\s*#', line):
 
311
                continue
 
312
            if '=' not in line:
 
313
                continue
 
314
            key, val = line.split('=', 1)
 
315
            colors[key.strip()] = val.strip()
 
316
        return colors
 
317