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
#-*- coding: GBK -*-
#¶ÁÈ¡Óû§ÅäÖÃÎļþ
#×÷Õߣºifo
 
from Utils.DataFileReader import DataFileReader
import logging
import traceback
 
class RobotsConfig( DataFileReader ):
    _SKIP_LINES = 2
    _SKIP_COLUMNS = 0
 
    def __init__(self,filename):
        DataFileReader.__init__( self )
        self.configList = []
        # Óû§ÅäÖÃÎļþµÄËùÔÚ·¾¶
        try:
            if not self.Open(filename):                # ´ò¿ªÎļþ
                logging.fatal( "Robot Config File[%s] no found" % filename )
                return
        except Exception, e:
            print str(e)
            print traceback.print_exc()
            logging.error( str(e) )
            logging.error( traceback.print_exc() )
        logging.info( "Robot Config File[%s] open successfully" % filename )
        
    def _ProcessData( self, datalist ):
        from ProjectBinding.ProjectRobotConfigParam import ProjectRobotConfigParams
        self.configList.append( ProjectRobotConfigParams(datalist) )
     
    #·µ»ØÓÐЧÄÚÈÝÌõÊý
    def GetRecordCount(self):
        return len(self.configList)
    
    #ͨ¹ýË÷Òý·µ»ØÄÚÈÝ
    def GetRecordByIndex(self,index):
        return self.configList[index]
    
    def __str__(self):
        strRet = ""
        for param in self.configList:
            strRet += str(param) + "\n"
        return strRet
 
 
__gRobotsConfig = None
 
def ReadConfig( filename ):
    global __gRobotsConfig
    if not __gRobotsConfig:
        __gRobotsConfig =  RobotsConfig( filename )
        
        
def GetConfig():
    global __gRobotsConfig
    return __gRobotsConfig
 
 
if __name__ == '__main__':
    ReadConfig("..\Configuration\User.txt")
    newConfig = GetConfig()
    print newConfig.GetRecordCount()
    print newConfig.GetRecordByIndex( 0 )
    record = newConfig.GetRecordByIndex( 1 )
    print record