Skip to content

Commit 5815e18

Browse files
committed
add exclude file and reverse list of contents
1 parent 1928029 commit 5815e18

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

log_reader/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
# The default value is '[(?i)[0-9]{4}-[0-9]{2}-[0-9]{2}\\s(?:[0-9]{2}:){2}[0-9]{2}.+?(?=[0-9]{4}-[0-9]{2}-[0-9]{2}\\s(?:[0-9]{2}:){2}[0-9]{2}|$)'
1212
LOG_READER_REGEX_SPLIT_PATTERN = '[(?i)[0-9]{4}-[0-9]{2}-[0-9]{2}\\s(?:[0-9]{2}:){2}[0-9]{2}.+?(?=[0-9]{4}-[0-9]{2}-[0-9]{2}\\s(?:[0-9]{2}:){2}[0-9]{2}|$)'
1313
LOG_READER_MAX_READ_LINES = getattr(settings, 'LOG_READER_MAX_READ_LINES', 1000)
14+
LOG_READER_EXCLUDE_LINES = getattr(settings, 'LOG_READER_EXCLUDE_LINES', [])
15+

log_reader/templates/log_reader/admin/change_list.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ <h1>File Logs</h1>
4949
</tr>
5050
</thead>
5151
<tbody>
52-
{% for content in file_contents %}
53-
<tr>
54-
<td>{{ forloop.counter }}</td>
55-
<td class="file_content">{{ content }}</td>
56-
</tr>
52+
{% for content in file_contents reversed %}
53+
{% if content|length > 5 %}
54+
<tr>
55+
<td>{{ forloop.counter }}</td>
56+
<td class="file_content">{{ content }}</td>
57+
</tr>
58+
{% endif %}
5759
{% endfor %}
5860
</tbody>
5961
</table>

log_reader/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import unicode_literals
22

33
import os
4-
import re
4+
# import re
55
import subprocess
66
from fnmatch import fnmatch
7+
from django.utils.translation import ugettext_lazy as _
78

89
from log_reader import settings
910

@@ -12,12 +13,15 @@ def get_log_files(directory):
1213
for (dir_path, dir_names, filenames) in os.walk(directory):
1314
log_files = []
1415
all_files = list(filter(lambda x: x.find('~') == -1, filenames))
15-
log_files.extend([x for x in all_files if fnmatch(x, settings.LOG_READER_FILES_PATTERN)])
16+
log_files.extend([x for x in all_files if fnmatch(x, settings.LOG_READER_FILES_PATTERN) and x not in settings.LOG_READER_EXCLUDE_FILES])
1617
return list(set(log_files))
1718
return []
1819

1920

2021
def read_file_lines(file_name):
22+
if file_name not in get_log_files(settings.LOG_READER_DIR_PATH):
23+
return False, _("%s file, not found. Please try again." % file_name)
24+
2125
try:
2226
file_path = '%s/%s' % (settings.LOG_READER_DIR_PATH, file_name)
2327
result = subprocess.run(
@@ -34,8 +38,9 @@ def read_file_lines(file_name):
3438

3539

3640
def split_file_content(content):
37-
res = content.split(settings.LOG_READER_SPLIT_PATTERN) if content else []
41+
data = content.split(settings.LOG_READER_SPLIT_PATTERN) if content else []
3842
# if content and len(res) == 1:
3943
# res = re.findall(settings.LOG_READER_REGEX_SPLIT_PATTERN, content) if content else []
44+
res = [x for x in data if len(x) > 5]
4045
return res
4146

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name='django-log-reader',
12-
version='1.0.1',
12+
version='1.1.0',
1313
zip_safe=False,
1414
packages=find_packages(),
1515
include_package_data=True,

0 commit comments

Comments
 (0)