Esempio n. 1
0
def searchNprint(path, forSeek, regex=False):
    curTime = tools.getDesiredDate(0)

    path = path.replace('${shortdate}', curTime)  # todo кажется лишний теперь

    a = 0
    result = []
    if os.path.exists(path):
        try:
            logFile = open(path, 'r')  # , -1, 'utf-8')
            if regex:
                regexObj = re.compile(forSeek)
                for line in logFile:
                    if regexObj.match(line) != None:
                        result.append(line)
            else:
                if forSeek == '*':
                    for line in logFile:
                        result.append(line)
                else:
                    for line in logFile:
                        if forSeek in line:
                            result.append(line)
                            a += 1

            logFile.close()
            # print(a)
        except Exception as e:
            print(e)
    # else:
        # print(path + ' не существует')
    return '<br>'.join(result)
Esempio n. 2
0
def getCountInLogs(path, forSeek):  # todo реализовать силами основной читалки

    if '${shortdate}' in path:
        print('Почему ' + path + ' содержит ${shortdate} ?')
        curTime = tools.getDesiredDate(0)
        path = path.replace('${shortdate}', curTime)

    result = 0
    if os.path.exists(path):
        try:
            logFile = open(path, 'r')  # , -1, 'utf-8')
            for line in logFile:
                if forSeek in line:
                    result += 1
            logFile.close()
            # print(result)
            # return result
        except Exception as e:
            print(e)
    # else:
    #     print(path + ' не существует')
    return result
Esempio n. 3
0
def searchNprintSmrt(path, forSeek, date=0):
    curTime = tools.getDesiredDate(date)
    path = path.replace('${shortdate}', curTime) # todo = обычно тут уже дата не нужна

    # a = 0
    result = ''
    resultList = []
    if os.path.exists(path):
        try:
            logFile = open(path, 'r')  # , -1, 'utf-8')
            temp = SmartFilter(forSeek)
            for line in logFile:  # todo вынести цикл в метод или вызывать столько раз, пока не EOF. почему?
                if temp.check(line, curTime):
                    line = getColoringString(line, forSeek)
                    resultList.append(line)
            logFile.close()
            # return result
            result = '<p>'.join(resultList)
        except Exception as e:
            print(e)
    # else:
    #     print(path + ' не существует')
    return result
Esempio n. 4
0
 def getServiceLog(self, date=0):
     # curTime = strftime(cfg.get('logs.dateformat'), localtime())
     curTime = tools.getDesiredDate(date)
     return self.serviceLog.replace('${shortdate}', curTime)