|
Line 0
Link Here
|
| 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 |
'(?P<start>#\s+)Traceback \(most recent call last\):\n' # start of exception |
| 48 |
'(?:(?P=start).*\n)+?' # irrelevant lines of detail |
| 49 |
'(?P=start)(?P<exception>[^\s].*)\n')) # extract exception |
| 50 |
|
| 51 |
|
| 52 |
class TracebackFound(Exception): |
| 53 |
def __init__(self, path, exception): |
| 54 |
super(TracebackFound, self).__init__(path, exception) |
| 55 |
self.path = path |
| 56 |
self.exception = exception |
| 57 |
|
| 58 |
def __str__(self): |
| 59 |
msg = _('Found exception in {path!r}: {exception}') |
| 60 |
return msg.format(path=self.path, exception=self.exception) |
| 61 |
|
| 62 |
|
| 63 |
def find_tracebacks(path): |
| 64 |
with open(path) as fob: |
| 65 |
content = fob.read() |
| 66 |
for match in TRACEBACK_REGEX.finditer(content): |
| 67 |
yield match.group('exception') |
| 68 |
|
| 69 |
|
| 70 |
def check_for_tracebacks(): |
| 71 |
for path in glob.iglob('/etc/apt/sources.list.d/*'): |
| 72 |
for exception in find_tracebacks(path): |
| 73 |
yield TracebackFound(path, exception) |
| 74 |
|
| 75 |
|
| 76 |
def run(): |
| 77 |
error_descriptions = [str(exc) for exc in check_for_tracebacks()] |
| 78 |
if error_descriptions: |
| 79 |
error_descriptions.append(_('Please check the files for more details.')) |
| 80 |
raise Warning(description='\n'.join(error_descriptions)) |
| 81 |
|
| 82 |
|
| 83 |
if __name__ == '__main__': |
| 84 |
from univention.management.console.modules.diagnostic import main |
| 85 |
main() |
| 1 |
sources_list_check.py (po) |
86 |
sources_list_check.py (po) |
| 2 |
-- |
|
|
| 3 |
.../umc/python/diagnostic/de.po | 20 ++++++++++++++++++-- |
87 |
.../umc/python/diagnostic/de.po | 20 ++++++++++++++++++-- |
| 4 |
1 file changed, 18 insertions(+), 2 deletions(-) |
88 |
1 file changed, 18 insertions(+), 2 deletions(-) |