Univention Bugzilla – Attachment 10257 Details for
Bug 46553
two+ Python syntax errors in UCR conffiles
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
ucslint flake8 check for conffiles/
46553.patch (text/plain), 3.84 KB, created by
Florian Best
on 2019-12-09 23:42:03 CET
(
hide
)
Description:
ucslint flake8 check for conffiles/
Filename:
MIME Type:
Creator:
Florian Best
Created:
2019-12-09 23:42:03 CET
Size:
3.84 KB
patch
obsolete
>commit 246d13b7d95b2076b5c41444289de7ebf8f46f0d >Author: Florian Best <best@univention.de> >Date: Mon Dec 9 23:41:01 2019 +0100 > > Bug #46553: add ucslint flake8 for conffiles > >diff --git packaging/ucslint/ucslint/0020-flake8.py packaging/ucslint/ucslint/0020-flake8.py >index a9bd17b5ec..7c57d08399 100755 >--- packaging/ucslint/ucslint/0020-flake8.py >+++ packaging/ucslint/ucslint/0020-flake8.py >@@ -31,6 +31,7 @@ > from __future__ import print_function > import re > import os >+import io > import sys > import subprocess > from argparse import ArgumentParser >@@ -40,6 +41,14 @@ try: > except ImportError: > import ucslint.base as uub > >+EXECUTE_TOKEN = re.compile('@!@(.+?)@!@', re.MULTILINE | re.DOTALL) >+UCR_HEADER = '''\ >+# -*- coding: utf-8 -*- >+import univention.config_registry # noqa >+from fake import configRegistry, baseConfig # noqa >+ >+''' >+ > > class UniventionPackageCheck(uub.UniventionPackageCheckBase): > >@@ -308,25 +317,47 @@ class UniventionPackageCheck(uub.UniventionPackageCheckBase): > errors = [] > for python in self.python_versions: > for ignore, pathes in self._iter_pathes(path): >- cmd = [python, '/usr/bin/flake8', '--config=/dev/null'] >- if ignore: >- cmd.extend(['--ignore', ignore]) >- if self.DEFAULT_SELECT: >- cmd.extend(['--select', self.DEFAULT_SELECT]) >- cmd.extend(['--max-line-length', str(self.MAX_LINE_LENGTH)]) >- cmd.extend(['--format', '0020-%(code)s %(path)s %(row)s %(col)s %(text)s']) >- if self.show_statistics: >- cmd.append('--statistics') >- if self.debuglevel > 0: >- cmd.append('--show-source') >- cmd.append('--') >- cmd.extend(pathes) >- >- process = subprocess.Popen(cmd, stdout=subprocess.PIPE) >- errors.extend(process.communicate()[0].splitlines()) >+ errors.extend(self.flake8(python, pathes, ignore, False)) >+ errors.extend(self.check_conffiles(python)) > > self.format_errors(errors) > >+ def check_conffiles(self, python): >+ errors = [] >+ header_length = len(UCR_HEADER.splitlines()) + 1 >+ for conffile in uub.FilteredDirWalkGenerator('conffiles'): >+ with io.open(conffile, 'rb') as fd: >+ text = fd.read() >+ for i, match in enumerate(EXECUTE_TOKEN.findall(text)): >+ leading_lines = len(text[:text.index(match)].splitlines()) >+ for error in self.flake8(python, ['-'], self.DEFAULT_IGNORE, UCR_HEADER + match): >+ errno, filename, lineno, position, descr = error.split(' ', 4) >+ lineno = str(int(lineno) - header_length + leading_lines) >+ errors.append(' '.join((errno, conffile, lineno, position, descr))) >+ return errors >+ >+ def flake8(self, python, pathes, ignore=None, stdin=None): >+ cmd = [python, '/usr/bin/flake8', '--config=/dev/null'] >+ if ignore: >+ cmd.extend(['--ignore', ignore]) >+ if self.DEFAULT_SELECT: >+ cmd.extend(['--select', self.DEFAULT_SELECT]) >+ cmd.extend(['--max-line-length', str(self.MAX_LINE_LENGTH)]) >+ cmd.extend(['--format', '0020-%(code)s %(path)s %(row)s %(col)s %(text)s']) >+ if self.show_statistics: >+ cmd.append('--statistics') >+ if self.debuglevel > 0: >+ cmd.append('--show-source') >+ cmd.append('--') >+ cmd.extend(pathes) >+ >+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE if stdin else None) >+ if stdin: >+ process.stdin.write(stdin) >+ process.stdin.close() >+ process.wait() >+ return process.stdout.read().splitlines() >+ > def fix(self, path, *args): > for ignore, pathes in self._iter_pathes(path): > cmd = ['autopep8', '-i', '-aaa'] >@@ -356,9 +387,11 @@ class UniventionPackageCheck(uub.UniventionPackageCheckBase): > return ignored.iteritems() > > def format_errors(self, errors): >+ done = set() > for i, line in enumerate(errors, 1): >- if not line.startswith('0020-'): >+ if not line.startswith('0020-') or line in done: > continue >+ done.add(line) > code, path, row, col, text = line.split(' ', 4) > source = [] > while len(errors) > i + 1 and not errors[i].startswith('0020-'):
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 46553
:
9453
| 10257