/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/config.py

  • Committer: Tim Marston
  • Date: 2016-02-13 13:23:51 UTC
  • Revision ID: tim@ed.am-20160213132351-8ly2s0rtol5w1kpc
fixed syntax error and remove debug print

Show diffs side-by-side

added added

removed removed

43
43
                                lines = f.readlines()
44
44
                except IOError as e:
45
45
                        if e.errno != errno.ENOENT: raise
46
 
                        lines = list()
47
46
 
48
47
                # parse config
49
48
                config = dict();
55
54
                        if line[ :1 ] == '#': continue
56
55
 
57
56
                        # if section
58
 
                        matches = re.search( '^\[(.*)\]$', line );
 
57
                        matches = re.match( '\[(.*)\]$', line );
59
58
                        if matches:
60
59
                                section = matches.group( 1 )
61
60
                                continue
62
 
                        matches = re.search( '^([a-z0-9_-]+)\\s*=\\s*(.*)$', line, re.I )
 
61
                        matches = re.match( '([a-z0-9_-]+)\\s*=\\s*(.*)$', line, re.I )
63
62
                        if matches:
64
63
                                name = matches.group( 1 )
65
64
                                value = matches.group( 2 )
66
65
 
67
66
                                # parse value
68
 
                                matches = re.search(
69
 
                                        '^(["\'])((?:\\.|[^\\1])*)\\1(?:\\s*#.*)?$', value )
 
67
                                matches = re.match( '(["\'])((?:\\.|[^\\1])*)\\1(?:\\s*#.*)?$',
 
68
                                                                        value )
70
69
                                if matches:
71
70
                                        value = matches.group( 2 )
72
71
                                else:
73
 
                                        matches = re.search( '^([^#]+?)(?:\\s*#.*)?$', value )
 
72
                                        matches = re.match( '([^#]+?)(?:\\s*#.*)?$', value )
74
73
                                        if( matches ):
75
74
                                                value = matches.group( 1 )
76
75
                                config[ "%s.%s" % ( section, name ) ] = value
88
87
        def to_bool( self, value ):
89
88
                value = value.lower()
90
89
                return value == 't' or value == 'true' or value == 'yes' or \
91
 
                        ( re.search( '^[0-9]+$', value ) and int( value ) != 0 )
 
90
                        ( re.match( '[0-9]+$', value ) and int( value ) != 0 )