|
2 | 2 | from __future__ import unicode_literals |
3 | 3 |
|
4 | 4 | import os |
| 5 | +from fnmatch import fnmatch |
5 | 6 | from itertools import islice |
6 | 7 | from django.http import HttpResponse |
7 | 8 | from django.views.generic import TemplateView |
@@ -42,17 +43,16 @@ def get_log_json(self, original_context={}): |
42 | 43 | len_logs_dir = len(settings.LOG_VIEWER_FILES_DIR) |
43 | 44 |
|
44 | 45 | for root, _, files in os.walk(settings.LOG_VIEWER_FILES_DIR): |
45 | | - tmp_names = list(filter(lambda x: x.find('~') == -1, files)) |
46 | | - # if LOG_VIEWER_FILES is not set in settings |
47 | | - # then all the files with '.log' extension are listed |
48 | | - if len(settings.LOG_VIEWER_FILES) > 0: |
49 | | - tmp_names = list(filter(lambda x: x in settings.LOG_VIEWER_FILES, tmp_names)) |
50 | | - else: |
51 | | - tmp_names = [name for name in tmp_names if (name.split('.')[-1]) == 'log'] |
52 | | - |
53 | | - file_names += tmp_names |
54 | | - file_display += [('%s/%s' % (root[len_logs_dir:], name))[1:] for name in tmp_names] |
55 | | - file_urls += list(map(lambda x: '%s/%s' % (root, x), tmp_names)) |
| 46 | + all_files = list(filter(lambda x: x.find('~') == -1, files)) |
| 47 | + |
| 48 | + log_files = [] |
| 49 | + log_files.extend(list(filter(lambda x: x in settings.LOG_VIEWER_FILES, all_files))) |
| 50 | + log_files.extend([x for x in all_files if fnmatch(x, settings.LOG_VIEWER_FILES_PATTERN)]) |
| 51 | + log_files = list(set(log_files)) |
| 52 | + |
| 53 | + file_names.extend(log_files) |
| 54 | + file_display.extend([('%s/%s' % (root[len_logs_dir:], name))[1:] for name in log_files]) |
| 55 | + file_urls.extend(list(map(lambda x: '%s/%s' % (root, x), log_files))) |
56 | 56 |
|
57 | 57 | for i, element in enumerate(file_display): |
58 | 58 | context['log_files'].append({ |
|
0 commit comments