Ejemplo n.º 1
0
	def doMapping(self, pcSrc):
		pcDest = PersonCollection()
		# add headerNames to destination personCollection
		for kDest in self._mapping.values():
			pcDest.addHeader(kDest)
		# add srcPersons to destPersons with new headerNames
		for pSrc in pcSrc.getPersons():
			pDest = Person()
			for kSrc, kDest in self._mapping.items():
				attr = pSrc.getAttribute(kSrc)
				if((attr == Person.ATTR_NOT_AVAILABLE  or attr == "") and self._defaultValues[kDest] != ""):
					attr = self._defaultValues[kDest]
				pDest.setAttribute(kDest, attr)
			pcDest.addPerson(pDest)
		return pcDest
Ejemplo n.º 2
0
	def read(fName):
		Log.trace(__class__, "read()")
		pCollection = PersonCollection()
		try:
			file = open(fName, 'r')
			isHeader = True
			#SEP = ',*'
			SEP = "[\,,\s]*"
			EMB = "\""
			regEx = re.compile(EMB + '([^' + EMB + ']*)' + EMB + SEP)
			for line in file:
				i = 0
				person = Person()
				for col in regEx.findall(line):
					if(isHeader):
						pCollection.addHeader(col)
						#self._headerNames.append(col)
					else:
						person.setAttribute(pCollection.getHeaderNames()[i], col)
						i += 1 
				if(isHeader):
					isHeader = False
				else:
					pCollection.addPerson(person)
					
			file.close()
			return pCollection
		except IOError:
			Log.error(__class__, "IOError with file > " + fName)
			return None