/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-04-10 21:03:07 UTC
  • Revision ID: tim@ed.am-20160410210307-6m8527mg1syvrual
updated todo

Show diffs side-by-side

added added

removed removed

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