def _getFilteredFileContent(self, path, fileDate, filters): # local vars for readability fromDateTime = filters['fromDateTime'] toDateTime = filters['toDateTime'] levels = filters['levels'] result = [] dateStr = fileDate.toString('yyyy-MM-dd ') with open(path, 'r') as f: # store if last line was added, # this is used to filter tracebacks etc properly lastLineAdded = False lastLevel = '' for line in f: # split line into: # time, level, service, msg parts = [part.strip() for part in line.split(' : ')] # append line continuations if len(parts) < 2: if lastLineAdded: result.append(self._colorizeLevel(line, lastLevel)) continue dateTime = QDateTime.fromString(parts[0], 'HH:mm:ss,zzz') dateTime.setDate(fileDate.date()) level = parts[1] # check time if fromDateTime.secsTo(dateTime) < 0 or toDateTime.secsTo( dateTime) > 0: lastLineAdded = False continue # check level if level not in levels: lastLineAdded = False continue # add current day to the line line = dateStr + line result.append(self._colorizeLevel(line, level)) lastLineAdded = True lastLevel = level result = reversed(result) return ''.join(result)
def set_QDateTimeEdit(self, ctl, val): ctl.setDateTime(QDateTime.fromString(val))