|
0 |
- |
1 |
#!/usr/bin/python2.7 |
|
|
2 |
# coding: utf-8 |
3 |
# |
4 |
# Univention Management Console module: |
5 |
# System Diagnosis UMC module |
6 |
# |
7 |
# Copyright 2017 Univention GmbH |
8 |
# |
9 |
# http://www.univention.de/ |
10 |
# |
11 |
# All rights reserved. |
12 |
# |
13 |
# The source code of this program is made available |
14 |
# under the terms of the GNU Affero General Public License version 3 |
15 |
# (GNU AGPL V3) as published by the Free Software Foundation. |
16 |
# |
17 |
# Binary versions of this program provided by Univention to you as |
18 |
# well as other copyrighted, protected or trademarked materials like |
19 |
# Logos, graphics, fonts, specific documentations and configurations, |
20 |
# cryptographic keys etc. are subject to a license agreement between |
21 |
# you and Univention and not subject to the GNU AGPL V3. |
22 |
# |
23 |
# In the case you use this program under the terms of the GNU AGPL V3, |
24 |
# the program is provided in the hope that it will be useful, |
25 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 |
# GNU Affero General Public License for more details. |
28 |
# |
29 |
# You should have received a copy of the GNU Affero General Public |
30 |
# License with the Debian GNU/Linux or Univention distribution in file |
31 |
# /usr/share/common-licenses/AGPL-3; if not, see |
32 |
# <http://www.gnu.org/licenses/>. |
33 |
|
34 |
import re |
35 |
import glob |
36 |
|
37 |
from univention.management.console.modules.diagnostic import Warning |
38 |
|
39 |
from univention.lib.i18n import Translation |
40 |
_ = Translation('univention-management-console-module-diagnostic').translate |
41 |
|
42 |
title = _('Check errors in sources.list files') |
43 |
description = _('All files ok.') |
44 |
|
45 |
|
46 |
TRACEBACK_REGEX = re.compile(( |
47 |
'#\s+Traceback \(most recent call last\):\n' # start of exception |
48 |
'(?:.*\n)+?' # irrelevant lines of detail |
49 |
'#\s+raise (?P<exception>\w+).*\n' # `raise` line to exctract the exception class |
50 |
'#\s+(?P=exception): (?P<message>.*)\n')) # extract exception message |
51 |
|
52 |
|
53 |
IGNORED_EXCEPTIONS = set() |
54 |
|
55 |
|
56 |
class TracebackFound(Exception): |
57 |
def __init__(self, path, exception, message): |
58 |
super(TracebackFound, self).__init__(path, exception, message) |
59 |
self.path = path |
60 |
self.exception = exception |
61 |
self.message = message |
62 |
|
63 |
def __str__(self): |
64 |
msg = _('Found exception in {path!r}: {exception} - {message}') |
65 |
return msg.format(path=self.path, exception=self.exception, message=self.message) |
66 |
|
67 |
|
68 |
def find_tracebacks(path): |
69 |
with open(path) as fob: |
70 |
content = fob.read() |
71 |
for match in TRACEBACK_REGEX.finditer(content): |
72 |
yield (match.group('exception'), match.group('message')) |
73 |
|
74 |
|
75 |
def check_for_tracebacks(): |
76 |
for path in glob.iglob('/etc/apt/sources.list.d/*'): |
77 |
for (exception, message) in find_tracebacks(path): |
78 |
yield TracebackFound(path, exception, message) |
79 |
|
80 |
|
81 |
def run(): |
82 |
exceptions = (exc for exc in check_for_tracebacks() |
83 |
if exc.exception not in IGNORED_EXCEPTIONS) |
84 |
|
85 |
error_descriptions = [str(exc) for exc in exceptions] |
86 |
if error_descriptions: |
87 |
error_descriptions.append(_('Please check the files for more details.')) |
88 |
raise Warning(description='\n'.join(error_descriptions)) |
89 |
|
90 |
|
91 |
if __name__ == '__main__': |
92 |
from univention.management.console.modules.diagnostic import main |
93 |
main() |
1 |
sources_list_check.py (po) |
94 |
sources_list_check.py (po) |
2 |
-- |
|
|
3 |
.../umc/python/diagnostic/de.po | 20 ++++++++++++++++++-- |
95 |
.../umc/python/diagnostic/de.po | 20 ++++++++++++++++++-- |
4 |
1 file changed, 18 insertions(+), 2 deletions(-) |
96 |
1 file changed, 18 insertions(+), 2 deletions(-) |