summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/setup_xml.py
blob: d61d1fbb7d42ae644b1846022f1b16e7508b91a9 (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
63
64
65
66
67
68
69
70
71
72
import xml.etree.ElementTree as XMLParser

class XMLSetup (object):
    """XML Setup Parser"""
    __tree = None                   # Parser
    __dbType = None                 # database connection required: PgSQLConnection
    __dbConnectionRaw = None        # Connection string in raw
    __dbConnectionStr = None        # Connection string to use in sql object connection

    def __init__(self, filename):
        """Parse the file in the constructor"""
        self.__tree = XMLParser.parse(filename)

    def __del__(self):
        """Destructor do nothing"""
        pass

    def getdbConnectionStr(self):
        """XML to database connection string"""
        if self.__dbConnectionRaw is not None:
            return self.__dbConnectionRaw

        for element in self.__tree.iter('db'):
            self.__dbConnectionRaw = element.attrib
            self.__dbType = self.__dbConnectionRaw['type']
            if self.__dbType == "PgSQLConnection":
                self.__dbConnectionStr = self.getPostgresConnectionStr()
            return self.__dbConnectionStr

        return None

    def getPostgresConnectionStr(self):
        """Get Connection string """
        str = self.__dbConnectionRaw
        del str['type']
        return str

    def getBoard(self, key, default):
        for element in self.__tree.iter('board'):
            if key in element.attrib:
                return element.attrib[key]
        return default

    def getTempPath(self, key, default):
        for element in self.__tree.iter('tmpPath'):
            if key in element.attrib:
                return element.attrib[key]
        return default

    def getKeyVal(self, tag, key, default):
        for element in self.__tree.iter(tag):
            if key in element.attrib:
                return element.attrib[key]
        return default

    def gettagKey (self, xmltag, xmlkey):
        """aaaaa"""
        for element in self.__tree.iter(xmltag):
            return element.attrib[xmlkey]

        return None

    def getUSBlist(self):
        list = {}
        count = 0
        for elements in self.__tree.iter("usbdev"):
            sublist = {}
            for key,val in elements.items():
                sublist[key] = val
            list[count] = sublist
            count += 1
        return list