Ejemplo n.º 1
0
	def __parse_kvk_file(self, strict=True):

		_log.debug('parsing KVK data in [%s]', self.filename)

		kvk_file = io.open(self.filename, mode = 'rt', encoding = 'utf8')

		card_type_seen = False
		for line in kvk_file:
			line = line.replace('\n', '').replace('\r', '')
			tag, content = line.split(':', 1)
			content = content.strip()

			if tag == 'Kartentyp':
				card_type_seen = True
				if content != cDTO_KVK.kvkd_card_id_string:
					_log.error('parsing wrong card type')
					_log.error('found   : %s', content)
					_log.error('expected: %s', cDTO_KVK.kvkd_card_id_string)
				if strict:
					raise ValueError('wrong card type: %s, expected %s', content, cDTO_KVK.kvkd_card_id_string)
				else:
					_log.debug('trying to parse anyway')

			if tag == 'Geburtsdatum':
				tmp = time.strptime(content, self.dob_format)
				content = pyDT.datetime(tmp.tm_year, tmp.tm_mon, tmp.tm_mday, tzinfo = gmDateTime.gmCurrentLocalTimezone)

			try:
				setattr(self, map_kvkd_tags2dto[tag], content)
			except KeyError:
				_log.exception('unknown KVKd kvk file key [%s]' % tag)

		# valid_until -> valid_until_timestamp
		ts = time.strptime (
			'28%s20%s' % (self.valid_until[:2], self.valid_until[2:]),
			self.valid_until_format
		)

		# last_read_date and last_read_time -> last_read_timestamp
		ts = time.strptime (
			'%s %s' % (self.last_read_date, self.last_read_time),
			'%s %s' % (self.last_read_date_format, self.last_read_time_format)
		)
		self.last_read_timestamp = pyDT.datetime(ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, tzinfo = gmDateTime.gmCurrentLocalTimezone)

		# guess gender from firstname
		self.gender = gmTools.coalesce(gmPerson.map_firstnames2gender(firstnames=self.firstnames), 'f')

		if not card_type_seen:
			_log.warning('no line with card type found, unable to verify')
Ejemplo n.º 2
0
	def _on_leaving_firstname(self):
		"""Set the gender according to entered firstname.

		Matches are fetched from existing records in backend.
		"""
		wx.CallAfter(self._refresh_dupe_warning)

		# only set if not already set so as to not
		# overwrite a change by the user
		if self._PRW_gender.GetData() is not None:
			return True

		firstname = self._PRW_firstnames.GetValue().strip()
		if firstname == '':
			return True

		gender = gmPerson.map_firstnames2gender(firstnames = firstname)
		if gender is None:
			return True

		wx.CallAfter(self._PRW_gender.SetData, gender)

		return True
Ejemplo n.º 3
0
    def _on_leaving_firstname(self):
        """Set the gender according to entered firstname.

		Matches are fetched from existing records in backend.
		"""
        wx.CallAfter(self._refresh_dupe_warning)

        # only set if not already set so as to not
        # overwrite a change by the user
        if self._PRW_gender.GetData() is not None:
            return True

        firstname = self._PRW_firstnames.GetValue().strip()
        if firstname == '':
            return True

        gender = gmPerson.map_firstnames2gender(firstnames=firstname)
        if gender is None:
            return True

        wx.CallAfter(self._PRW_gender.SetData, gender)

        return True
Ejemplo n.º 4
0
    def __parse_kvk_file(self, strict=True):

        _log.debug('parsing KVK data in [%s]', self.filename)

        kvk_file = io.open(self.filename, mode='rt', encoding='utf8')

        card_type_seen = False
        for line in kvk_file:
            line = line.replace('\n', '').replace('\r', '')
            tag, content = line.split(':', 1)
            content = content.strip()

            if tag == 'Kartentyp':
                card_type_seen = True
                if content != cDTO_KVK.kvkd_card_id_string:
                    _log.error('parsing wrong card type')
                    _log.error('found   : %s', content)
                    _log.error('expected: %s', cDTO_KVK.kvkd_card_id_string)
                if strict:
                    raise ValueError('wrong card type: %s, expected %s',
                                     content, cDTO_KVK.kvkd_card_id_string)
                else:
                    _log.debug('trying to parse anyway')

            if tag == 'Geburtsdatum':
                tmp = time.strptime(content, self.dob_format)
                content = pyDT.datetime(
                    tmp.tm_year,
                    tmp.tm_mon,
                    tmp.tm_mday,
                    tzinfo=gmDateTime.gmCurrentLocalTimezone)

            try:
                setattr(self, map_kvkd_tags2dto[tag], content)
            except KeyError:
                _log.exception('unknown KVKd kvk file key [%s]' % tag)

        # valid_until -> valid_until_timestamp
        ts = time.strptime(
            '28%s20%s' % (self.valid_until[:2], self.valid_until[2:]),
            self.valid_until_format)

        # last_read_date and last_read_time -> last_read_timestamp
        ts = time.strptime(
            '%s %s' % (self.last_read_date, self.last_read_time),
            '%s %s' % (self.last_read_date_format, self.last_read_time_format))
        self.last_read_timestamp = pyDT.datetime(
            ts.tm_year,
            ts.tm_mon,
            ts.tm_mday,
            ts.tm_hour,
            ts.tm_min,
            ts.tm_sec,
            tzinfo=gmDateTime.gmCurrentLocalTimezone)

        # guess gender from firstname
        self.gender = gmTools.coalesce(
            gmPerson.map_firstnames2gender(firstnames=self.firstnames), 'f')

        if not card_type_seen:
            _log.warning('no line with card type found, unable to verify')