MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / GetNumLines

Method GetNumLines

class/logsModel/base.py:46–141  ·  view source on GitHub ↗

@name 取文件指定尾行数 @param path 文件路径 @param num 取尾行数 @param p 当前页 @param search 搜索关键字 @return list

(self,path, num, p=1,search = None)

Source from the content-addressed store, hash-verified

44 return log_list
45
46 def GetNumLines(self,path, num, p=1,search = None):
47 """
48 @name 取文件指定尾行数
49 @param path 文件路径
50 @param num 取尾行数
51 @param p 当前页
52 @param search 搜索关键字
53 @return list
54 """
55 pyVersion = sys.version_info[0]
56 max_len = 1024 * 128 * 1024
57 try:
58 from html import escape
59 if not os.path.exists(path): return ""
60 start_line = (p - 1) * num
61 count = start_line + num
62 fp = open(path, 'rb')
63
64 buf = ""
65 fp.seek(-1, 2)
66 if fp.read(1) == "\n": fp.seek(-1, 2)
67 data = []
68 total_len = 0
69 b = True
70 n = 0
71
72 for i in range(count):
73 while True:
74 newline_pos = str.rfind(str(buf), "\n")
75
76 pos = fp.tell()
77 if newline_pos != -1:
78 if n >= start_line:
79 line = buf[newline_pos + 1:]
80
81 is_res = True
82 if search:
83 is_res = False
84 if line.find(search) >= 0 or re.search(search,line):
85 is_res = True
86
87 if is_res:
88 line_len = len(line)
89 total_len += line_len
90 sp_len = total_len - max_len
91 if sp_len > 0:
92 line = line[sp_len:]
93 try:
94 data.insert(0, escape(line))
95 except:
96 pass
97 buf = buf[:newline_pos]
98 n += 1
99 break
100 else:
101 if pos == 0:
102 b = False
103 break

Callers 15

get_cron_logFunction · 0.80
print_xFunction · 0.80
get_logMethod · 0.80
get_project_logMethod · 0.80
get_setup_logMethod · 0.80
get_last_exec_timeMethod · 0.80
GetSiteLogsMethod · 0.80
_wait_start_statusMethod · 0.80
get_spring_log_dataMethod · 0.80
_move_logsMethod · 0.80
start_projectMethod · 0.80
start_projectMethod · 0.80

Calls 12

openFunction · 0.85
seekMethod · 0.80
existsMethod · 0.45
readMethod · 0.45
findMethod · 0.45
searchMethod · 0.45
insertMethod · 0.45
decodeMethod · 0.45
closeMethod · 0.45
joinMethod · 0.45
dumpsMethod · 0.45
loadsMethod · 0.45

Tested by

no test coverage detected