def next(self): if self.nbMsg == 0: return 0 else: try: reticLog.logInfo(self.logList, '( ' + self.name + ' ) ' + "Starting processing phase of source " + self.name) self.updateAttributesFromMetadata() print "updateMetTermine" SOAPMessage = self.SOAPMessage for key in self.params.keys(): print "key : " + key SOAPMessage = string.replace(SOAPMessage,'**' + key[1:] + '**',self.params[key]) print "SOAPMsg : " + SOAPMessage reticLog.logInfo(self.logList, '( ' + self.name + ' ) ' + "Executing SOAP request") reticLog.logDebug(self.logList, '( ' + self.name + ' ) ' + "SOAP Request : " + SOAPMessage) if self.proxyUrl <> '': urlopener = urllib.FancyURLopener( {'http' : self.proxyUrl } ) else: urlopener = urllib.URLopener() urlopener.addheaders.append(('Content-Length', str(len(SOAPMessage)))) urlopener.addheaders.append(('Content-type', 'text/xml; charset="utf-8"')) urlopener.addheaders.append(('SOAPAction', self.SOAPAction)) resp = urlopener.open(self.url, SOAPMessage) response = resp.read() reticLog.logDebug(self.logList, '( ' + self.name + ' ) ' + "SOAP Response : " + response) self.msg = response reticLog.logInfo(self.logList, '( ' + self.name + ' ) ' + "source " + self.name + " executed ok") return 1 except: errorMessage = traceback.format_exception_only(sys.exc_info()[0],sys.exc_info()[1])[0] reticLog.logError(self.logList, '( ' + self.name + ' ) ' + "Error during process phase of source : " + self.name) reticLog.logError(self.logList, '( ' + self.name + ' ) ' + errorMessage) return 0
def process (self): try: msg = StringIO.StringIO() msg.write(self.msg) msg.seek(0) self.updateAttributesFromMetadata() reticLog.logInfo(self.logList, "( " + self.name + " ) Processing file in sink " + self.name) if self.addTimestamp == 'y': index = 0 i = 0 while index >= 0: i = index index = string.find(self.fileName,'.',index+1) now = time.time() timestamp = str(time.localtime()[0])+reticUtils.completeWithZero(str(time.localtime()[1]))+reticUtils.completeWithZero(str(time.localtime()[2]))+reticUtils.completeWithZero(str(time.localtime()[3]))+reticUtils.completeWithZero(str(time.localtime()[4]))+reticUtils.completeWithZero(str(time.localtime()[5]))+str(int(random.random()*10000)) reticLog.logDebug(self.logList, "Timestamp added to filename : " + timestamp) new_filename = self.fileName[:i] + timestamp + self.fileName[i:] else: new_filename = self.fileName if self.writeMethod == 'overwrite': if self.zip == 'y': reticLog.logDebug(self.logList, "Message is being zipped") tmpFpName = '_tmp' + str(int(random.random()*100000000)) + '.dat' tmpFpName2 = '_tmp' + str(int(random.random()*100000000)) + '.dat' tmpFpMsg = open(tmpFpName2,'w+b') tmpFpMsg.write(self.msg) tmpFpMsg.close() tmpZipFile = zipfile.ZipFile(os.path.join(os.getcwd(),tmpFpName),'w',zipfile.ZIP_DEFLATED) tmpZipFile.write(tmpFpName2,self.fileName) tmpZipFile.close() tmpZipFile = open(os.path.join(os.getcwd(),tmpFpName),'r+b') self.msg = tmpZipFile.read() tmpZipFile.close() os.remove(tmpFpName) os.remove(tmpFpName2) new_filename = new_filename + '.zip' self.fp = open(os.path.join(self.filePath,new_filename),'wb') elif reticUtils.istext(msg): reticLog.logDebug(self.logList, "Message identified as being text") self.fp = open(os.path.join(self.filePath,new_filename),'w') else: reticLog.logDebug(self.logList, "Message identified as being binary data") self.fp = open(os.path.join(self.filePath,new_filename),'wb') self.fp.truncate() self.fp.write(self.msg) self.fp.close() reticLog.logInfo(self.logList, "( " + self.name + " ) New file created by sink " + self.name + " : " + self.filePath + new_filename) else: if self.fileType == 'flat': file_content = self.msg self.fp.write(file_content) else: msg.seek(0) addLines = msg.readlines() if len(self.lastLine) > 0: self.fp.seek(-(len(self.lastLine)+1),2) self.fp.truncate() del addLines[0:2] self.fp.writelines(addLines) self.fp.flush() self.lastLine = addLines[-1] reticLog.logInfo(self.logList, "( " + self.name + " ) Data appended to file in sink " + self.name + " - file : " + self.filePath + new_filename) return 0 except: errorMessage = traceback.format_exception_only(sys.exc_info()[0],sys.exc_info()[1])[0] reticLog.logError(self.logList, "( " + self.name + " ) Error during message processing in sink : " + self.name) reticLog.logError(self.logList, "( " + self.name + " ) " + errorMessage) return 1