/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 14:21:53 UTC
  • Revision ID: tim@ed.am-20160213142153-68g7pzq0au6bejep
fixed init command

Show diffs side-by-side

added added

removed removed

30
30
        def __init__( self ):
31
31
                self.symlinks = None
32
32
                self.ignores = None
33
 
                self.default_vcs = 'bzr'
34
33
                self.read_config( the.config_file )
35
34
 
 
35
 
36
36
        def read_config( self, config_file ):
37
37
 
38
38
                # read file
55
55
                        if line[ :1 ] == '#': continue
56
56
 
57
57
                        # if section
58
 
                        matches = re.search( '^\[(.*)\]$', line );
 
58
                        matches = re.match( '\[(.*)\]$', line );
59
59
                        if matches:
60
60
                                section = matches.group( 1 )
61
61
                                continue
62
 
                        matches = re.search( '^([a-z0-9_-]+)\\s*=\\s*(.*)$', line, re.I )
 
62
                        matches = re.match( '([a-z0-9_-]+)\\s*=\\s*(.*)$', line, re.I )
63
63
                        if matches:
64
64
                                name = matches.group( 1 )
65
65
                                value = matches.group( 2 )
66
66
 
67
67
                                # parse value
68
 
                                matches = re.search(
69
 
                                        '^(["\'])((?:\\.|[^\\1])*)\\1(?:\\s*#.*)?$', value )
 
68
                                matches = re.match( '(["\'])((?:\\.|[^\\1])*)\\1(?:\\s*#.*)?$',
 
69
                                                                        value )
70
70
                                if matches:
71
71
                                        value = matches.group( 2 )
72
72
                                else:
73
 
                                        matches = re.search( '^([^#]+?)(?:\\s*#.*)?$', value )
 
73
                                        matches = re.match( '([^#]+?)(?:\\s*#.*)?$', value )
74
74
                                        if( matches ):
75
75
                                                value = matches.group( 1 )
76
76
                                config[ "%s.%s" % ( section, name ) ] = value
79
79
                # use config
80
80
                if 'stdhome.home-dir' in config:
81
81
                        the.home_dir = config[ 'stdhome.home-dir' ]
82
 
                if 'stdhome.default-vcs' in config:
83
 
                        self.default_vcs = config[ 'stdhome.default-vcs' ]
84
82
 
85
83
                # read file matcher lists
86
84
                self.symlinks = FileMatcher( config_file, 'symlink' )
90
88
        def to_bool( self, value ):
91
89
                value = value.lower()
92
90
                return value == 't' or value == 'true' or value == 'yes' or \
93
 
                        ( re.search( '^[0-9]+$', value ) and int( value ) != 0 )
 
91
                        ( re.match( '[0-9]+$', value ) and int( value ) != 0 )