def getDate(self, line): date = None dateMatch = self.matchDate(line) if dateMatch: try: # Try first with 'C' locale date = list(time.strptime(dateMatch.group(), self.getPattern())) except ValueError: # Try to convert date string to 'C' locale conv = self.convertLocale(dateMatch.group()) try: date = list(time.strptime(conv, self.getPattern())) except ValueError, e: # Try to add the current year to the pattern. Should fix # the "Feb 29" issue. conv += " %s" % MyTime.gmtime()[0] pattern = "%s %%Y" % self.getPattern() date = list(time.strptime(conv, pattern)) if date[0] < 2000: # There is probably no year field in the logs date[0] = MyTime.gmtime()[0] # Bug fix for #1241756 # If the date is greater than the current time, we suppose # that the log is not from this year but from the year before if time.mktime(date) > MyTime.time(): logSys.debug( u"Correcting deduced year from %d to %d since %f > %f" % (date[0], date[0]-1, time.mktime(date), MyTime.time())) date[0] -= 1 elif date[1] == 1 and date[2] == 1: # If it is Jan 1st, it is either really Jan 1st or there # is neither month nor day in the log. date[1] = MyTime.gmtime()[1] date[2] = MyTime.gmtime()[2]
def getDate(self, line): date = None dateMatch = self.matchDate(line) if dateMatch: try: date = list(time.strptime(dateMatch.group(), self.getPattern())) except ValueError: conv = self.convertLocale(dateMatch.group()) try: date = list(time.strptime(conv, self.getPattern())) except ValueError, e: conv += " %s" % MyTime.gmtime()[0] pattern = "%s %%Y" % self.getPattern() date = list(time.strptime(conv, pattern)) if date[0] < 2000: date[0] = MyTime.gmtime()[0] if time.mktime(date) > MyTime.time(): date[0] -= 1 elif date[1] == 1 and date[2] == 1: date[1] = MyTime.gmtime()[1] date[2] = MyTime.gmtime()[2]
def getDate(self, line): date = None dateMatch = self.matchDate(line) if dateMatch: try: # Try first with 'C' locale date = list(time.strptime(dateMatch.group(), self.getPattern())) except ValueError: # Try to convert date string to 'C' locale conv = self.convertLocale(dateMatch.group()) try: date = list(time.strptime(conv, self.getPattern())) except ValueError: # Try to add the current year to the pattern. Should fix # the "Feb 29" issue. conv += " %s" % MyTime.gmtime()[0] pattern = "%s %%Y" % self.getPattern() date = list(time.strptime(conv, pattern)) if date[0] < 2000: # There is probably no year field in the logs date[0] = MyTime.gmtime()[0] # Bug fix for #1241756 # If the date is greater than the current time, we suppose # that the log is not from this year but from the year before if time.mktime(date) > MyTime.time(): date[0] -= 1 return date
def getDate(self, line): date = None dateMatch = self.matchDate(line) if dateMatch: try: # Try first with 'C' locale date = list(time.strptime(dateMatch.group(), self.getPattern())) except ValueError: # Try to convert date string to 'C' locale conv = self.convertLocale(dateMatch.group()) try: date = list(time.strptime(conv, self.getPattern())) except (ValueError, re.error), e: # Try to add the current year to the pattern. Should fix # the "Feb 29" issue. opattern = self.getPattern() # makes sense only if %Y is not in already: if not '%Y' in opattern: pattern = "%s %%Y" % opattern conv += " %s" % MyTime.gmtime()[0] date = list(time.strptime(conv, pattern)) else: # we are helpless here raise ValueError( "Given pattern %r does not match. Original " "exception was %r and Feb 29 workaround could not " "be tested due to already present year mark in the " "pattern" % (opattern, e)) if date[0] < 2000: # There is probably no year field in the logs # NOTE: Possibly makes week/year day incorrect date[0] = MyTime.gmtime()[0] # Bug fix for #1241756 # If the date is greater than the current time, we suppose # that the log is not from this year but from the year before if time.mktime(date) > MyTime.time(): logSys.debug( u"Correcting deduced year from %d to %d since %f > %f" % (date[0], date[0] - 1, time.mktime(date), MyTime.time())) # NOTE: Possibly makes week/year day incorrect date[0] -= 1 elif date[1] == 1 and date[2] == 1: # If it is Jan 1st, it is either really Jan 1st or there # is neither month nor day in the log. # NOTE: Possibly makes week/year day incorrect date[1] = MyTime.gmtime()[1] date[2] = MyTime.gmtime()[2]
def getDate(self, line): date = None dateMatch = self.matchDate(line) if dateMatch: try: # Try first with 'C' locale date = list(time.strptime(dateMatch.group(), self.getPattern())) except ValueError: # Try to convert date string to 'C' locale conv = self.convertLocale(dateMatch.group()) try: date = list(time.strptime(conv, self.getPattern())) except (ValueError, re.error), e: # Try to add the current year to the pattern. Should fix # the "Feb 29" issue. opattern = self.getPattern() # makes sense only if %Y is not in already: if not '%Y' in opattern: pattern = "%s %%Y" % opattern conv += " %s" % MyTime.gmtime()[0] date = list(time.strptime(conv, pattern)) else: # we are helpless here raise ValueError( "Given pattern %r does not match. Original " "exception was %r and Feb 29 workaround could not " "be tested due to already present year mark in the " "pattern" % (opattern, e)) if date[0] < 2000: # There is probably no year field in the logs # NOTE: Possibly makes week/year day incorrect date[0] = MyTime.gmtime()[0] # Bug fix for #1241756 # If the date is greater than the current time, we suppose # that the log is not from this year but from the year before if time.mktime(date) > MyTime.time(): logSys.debug( u"Correcting deduced year from %d to %d since %f > %f" % (date[0], date[0]-1, time.mktime(date), MyTime.time())) # NOTE: Possibly makes week/year day incorrect date[0] -= 1 elif date[1] == 1 and date[2] == 1: # If it is Jan 1st, it is either really Jan 1st or there # is neither month nor day in the log. # NOTE: Possibly makes week/year day incorrect date[1] = MyTime.gmtime()[1] date[2] = MyTime.gmtime()[2]
def getTime(self, line): try: date = list(time.strptime(line, self.getPattern())) except ValueError: conv = self.convertLocale(line) try: date = list(time.strptime(conv, self.getPattern())) except ValueError: conv += " %s" % MyTime.gmtime()[0] pattern = "%s %%Y" % self.getPattern() date = list(time.strptime(conv, pattern)) if date[0] < 2000: date[0] = MyTime.gmtime()[0] if time.mktime(date) > MyTime.time(): date[0] -= 1 return date
def getTime(self, line): try: # Try first with 'C' locale date = list(time.strptime(line, self.getPattern())) except ValueError: # Try to convert date string to 'C' locale conv = self.convertLocale(line) try: date = list(time.strptime(conv, self.getPattern())) except ValueError: # Try to add the current year to the pattern. Should fix # the "Feb 29" issue. conv += " %s" % MyTime.gmtime()[0] pattern = "%s %%Y" % self.getPattern() date = list(time.strptime(conv, pattern)) if date[0] < 2000: # There is probably no year field in the logs date[0] = MyTime.gmtime()[0] # Bug fix for #1241756 # If the date is greater than the current time, we suppose # that the log is not from this year but from the year before if time.mktime(date) > MyTime.time(): date[0] -= 1 return date
def getDate(self, line): date = None dateMatch = self.matchDate(line) if dateMatch: try: date = list(time.strptime(dateMatch.group(), self.getPattern())) except ValueError: conv = self.convertLocale(dateMatch.group()) date = list(time.strptime(conv, self.getPattern())) if date[0] < 2000: date[0] = MyTime.gmtime()[0] if time.mktime(date) > MyTime.time(): date[0] -= 1 return date