aboutsummaryrefslogtreecommitdiff
blob: adf7a79b72f9d55b6ed5cbdd01b53db621454e0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

import os

class PropertiesParser:
    """
    Parse eclipse projects build.properties file.
    """

    def __init__( self, file ):
        self.file = file
        self.config = {}
        self.parse( file )

    def parse( self, file ):
        if not os.path.isfile(file):
            return
        if not os.access(file, os.R_OK):
            return

        stream = open( file, 'r' )
        line = stream.readline()
        while line != '':
            line = line.strip('\n')
            line = line.strip()
            #print 'line="'+line+'"'
            if line.isspace() or line == '' or line.startswith('#'):
                line = stream.readline()
                continue

            index = line.find('=')
            name = line[:index]
            name = name.strip()
            value = line[index+1:]

            #print 'name="'+name+'"; value="'+value+'"'

            while line.endswith('\\'):
                #stream.next()
                line = stream.readline()
                line = line.strip('\n')
                line = line.strip()
                #print 'line="'+line+'"'
                if line.isspace() or line == '' or line.startswith('#'):
                    line = stream.readline()
                    break
                value +=line

            value = value.strip('\\')

            if value == '':
                line = stream.readline()
                continue
            value = value.strip('\\\'\"').strip('\\').strip()
            value = value.replace('\\', '')
            self.config[name] = value.split(',')
            line = stream.readline()


# vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap :