def __parse_and_write_file(self, file, link): """ Parses the date+time and writes entry to outputfile @param file: filename @param link: path """ if TIMESTAMP_REGEX.match(file): # if we found a timestamp too,take hours,min # and optionally seconds from this timestamp timestamp = TIMESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdatetimeiso8601(timestamp) logging.debug("found timestamp: " + orgdate) else: datestamp = DATESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdate(datestamp) orgdate_time_tupel = OrgFormat.datetupeliso8601(datestamp) file_datetime = time.localtime(os.path.getmtime(link)) # check if the file - time information matches year,month,day, # then update time if file_datetime.tm_year == orgdate_time_tupel.tm_year and \ file_datetime.tm_mon == orgdate_time_tupel.tm_mon and \ file_datetime.tm_mday == orgdate_time_tupel.tm_mday: logging.debug("found a time in file.setting %s-->%s", orgdate, OrgFormat.date(file_datetime, True)) orgdate = OrgFormat.date(file_datetime, True) # write entry to org file output = OrgFormat.link(link=link, description=file) # we need optional data for hashing due it can be, that more # than one file have the same timestamp properties = OrgProperties(data_for_hashing=output) self._writer.write_org_subitem(timestamp=orgdate, output=output, properties=properties)
def __parse_file(self, file, link): """ Parses the date+time and writes entry to outputfile @param file: filename @param link: path """ if TIMESTAMP_REGEX.match(file): # if we found a timestamp too,take hours,min # and optionally seconds from this timestamp timestamp = TIMESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdatetimeiso8601(timestamp) logging.debug("found timestamp: " + orgdate) else: datestamp = DATESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdate(datestamp) orgdate_time_tupel = OrgFormat.datetupeliso8601(datestamp) if self._args.skip_filetime_extraction != True: if os.path.exists(link): file_datetime = time.localtime(os.path.getmtime(link)) # check if the file - time information matches year,month,day, # then update time if file_datetime.tm_year == orgdate_time_tupel.tm_year and \ file_datetime.tm_mon == orgdate_time_tupel.tm_mon and \ file_datetime.tm_mday == orgdate_time_tupel.tm_mday: logging.debug("found a time in file.setting %s-->%s", orgdate, OrgFormat.date(file_datetime, True)) orgdate = OrgFormat.date(file_datetime, True) else: logging.debug( "item [%s] not found and thus could not determine mtime" % link) self.__write_file(file, link, orgdate)