/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:20:44 UTC
  • Revision ID: tim@ed.am-20160213132044-t5zaxhdlhjyn4t1v
moved handling of --verbose to main program; manuall parse config file (because
ConfigFileParse does not support allow_no_value in python 2.6)

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
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
77
 
                                #print "  %s.%s = %s" % ( section, name, value )
 
76
                                print "  %s.%s = %s" % ( section, name, value )
78
77
 
79
78
                # use config
80
79
                if 'stdhome.home-dir' in config:
81
80
                        the.home_dir = config[ 'stdhome.home-dir' ]
82
 
                if 'stdhome.default-vcs' in config:
83
 
                        self.default_vcs = config[ 'stdhome.default-vcs' ]
84
81
 
85
82
                # read file matcher lists
86
83
                self.symlinks = FileMatcher( config_file, 'symlink' )
89
86
 
90
87
        def to_bool( self, value ):
91
88
                value = value.lower()
92
 
                return value == 't' or value == 'true' or value == 'yes' or \
93
 
                        ( re.search( '^[0-9]+$', value ) and int( value ) != 0 )
 
89
                return value == 't' || value == 'true' || value == 'yes' || \
 
90
                        ( re.match( '[0-9]+$', value ) && int( value ) != 0 )