Esempio n. 1
0
 def next(self):
     'Get the next message to be processed or return that sources are dry'
     if self.nbMsg == 0:
         reticLog.logInfo(self.logList, '( ' + self.name + ' ) ' +  "Sources dry on source ")
         return 0
     else:
         try:
             reticLog.logInfo(self.logList, '( ' + self.name + ' ) ' +  "Messages Left on queue of adaptor : " + str(self.nbMsg))
             reticLog.logInfo(self.logList, '( ' + self.name + ' ) ' +  "Retrieving file : " + self.msgList[0])
             self.msgName = self.msgList[0]
             dotIndex = string.find(self.msgName,'.')
             if dotIndex > 0:
                 if(not self.metadata.has_key('filename')):
                     self.metadata['filename'] = []
                 self.metadata['filename'].append(string.split(self.msgName,'.')[0])
                 self.metadata['extension'] = string.split(self.msgName,'.')[1]
             else:
                 if(not self.metadata.has_key('filename')):
                     self.metadata['filename'] = []
                 self.metadata['filename'] = self.msgName
                 self.metadata['extension'] = ''
             #file reading happend here
             fp = open(os.path.join(self.filePath,self.msgList[0]))
             if reticUtils.istext(fp):
                 fp.close()
                 fp = open(os.path.join(self.filePath,self.msgList[0]),'r')
             else:
                 fp.close()
                 fp = open(os.path.join(self.filePath,self.msgList[0]),'rb')                    
             self.msg = fp.read()
             fp.close()
             return 1
         except:
             errorMessage = traceback.format_exception_only(sys.exc_info()[0],sys.exc_info()[1])[0]
             reticLog.logError(self.logList, '( ' + self.name + ' ) ' + "Error on message retrieval on source : " + self.name)                        
             reticLog.logError(self.logList, '( ' + self.name + ' ) ' + errorMessage)
             if self.exitOnError.lower() == 'y':
                 return 0
             else:
                 return 1
Esempio n. 2
0
File: toXML.py Progetto: twdb/txhis
#    pipe_args['fieldNames'][11]='DO'
#    pipe_args['fieldNames'][12]='EC_Norm'
#    pipe_args['fieldNames'][13]='Salinity'
#    pipe_args['fieldNames'][14]='Temperature'
#    pipe_args['fieldNames'][15]='Turbidity'
#    pipe_args['fieldNames'][16]='WaterLevel_Non_Vented'
#    pipe_args['fieldNames'][17]='WaterLevel_Vented'
#    pipe_args['fieldNames'][18]='pH'
    pipe_args['name'] = 'TPWD_Emat_Test'
    #print pipe_args['fieldNames']
    #print raw_input("conitue...")
    testPipe = pipe(pipe_args,logList)
    #get os type
    if sys.platform == 'win32':        
        testPath = '..\\file_source_exp\\'
    else:
        testPath = '/home/ttan/file_source_exp/'
    testFileName = testPath + 'EMat_201003181523.csv'
    fp = open(testFileName)
    if reticUtils.istext(fp):
        fp.close()
        fp = open(testFileName,'r')
    else:
        fp.close()
        fp = open(testFileName,'rb')
    testPipe.getMsg(fp.read())
    testPipe.process()
    for i in range(len(testPipe.msgList)):
        print >> open("test_TPWD_Emat_out.xml",'w'),testPipe.msgList[i]