|
31 |
from __future__ import print_function |
31 |
from __future__ import print_function |
32 |
import re |
32 |
import re |
33 |
import os |
33 |
import os |
|
|
34 |
import io |
34 |
import sys |
35 |
import sys |
35 |
import subprocess |
36 |
import subprocess |
36 |
from argparse import ArgumentParser |
37 |
from argparse import ArgumentParser |
|
40 |
except ImportError: |
41 |
except ImportError: |
41 |
import ucslint.base as uub |
42 |
import ucslint.base as uub |
42 |
|
43 |
|
|
|
44 |
EXECUTE_TOKEN = re.compile('@!@(.+?)@!@', re.MULTILINE | re.DOTALL) |
45 |
UCR_HEADER = '''\ |
46 |
# -*- coding: utf-8 -*- |
47 |
import univention.config_registry # noqa |
48 |
from fake import configRegistry, baseConfig # noqa |
49 |
|
50 |
''' |
51 |
|
43 |
|
52 |
|
44 |
class UniventionPackageCheck(uub.UniventionPackageCheckBase): |
53 |
class UniventionPackageCheck(uub.UniventionPackageCheckBase): |
45 |
|
54 |
|
Lines 308-332
class UniventionPackageCheck(uub.UniventionPackageCheckBase):
|
Link Here
|
---|
|
308 |
errors = [] |
317 |
errors = [] |
309 |
for python in self.python_versions: |
318 |
for python in self.python_versions: |
310 |
for ignore, pathes in self._iter_pathes(path): |
319 |
for ignore, pathes in self._iter_pathes(path): |
311 |
cmd = [python, '/usr/bin/flake8', '--config=/dev/null'] |
320 |
errors.extend(self.flake8(python, pathes, ignore, False)) |
312 |
if ignore: |
321 |
errors.extend(self.check_conffiles(python)) |
313 |
cmd.extend(['--ignore', ignore]) |
|
|
314 |
if self.DEFAULT_SELECT: |
315 |
cmd.extend(['--select', self.DEFAULT_SELECT]) |
316 |
cmd.extend(['--max-line-length', str(self.MAX_LINE_LENGTH)]) |
317 |
cmd.extend(['--format', '0020-%(code)s %(path)s %(row)s %(col)s %(text)s']) |
318 |
if self.show_statistics: |
319 |
cmd.append('--statistics') |
320 |
if self.debuglevel > 0: |
321 |
cmd.append('--show-source') |
322 |
cmd.append('--') |
323 |
cmd.extend(pathes) |
324 |
|
325 |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
326 |
errors.extend(process.communicate()[0].splitlines()) |
327 |
|
322 |
|
328 |
self.format_errors(errors) |
323 |
self.format_errors(errors) |
329 |
|
324 |
|
|
|
325 |
def check_conffiles(self, python): |
326 |
errors = [] |
327 |
header_length = len(UCR_HEADER.splitlines()) + 1 |
328 |
for conffile in uub.FilteredDirWalkGenerator('conffiles'): |
329 |
with io.open(conffile, 'rb') as fd: |
330 |
text = fd.read() |
331 |
for i, match in enumerate(EXECUTE_TOKEN.findall(text)): |
332 |
leading_lines = len(text[:text.index(match)].splitlines()) |
333 |
for error in self.flake8(python, ['-'], self.DEFAULT_IGNORE, UCR_HEADER + match): |
334 |
errno, filename, lineno, position, descr = error.split(' ', 4) |
335 |
lineno = str(int(lineno) - header_length + leading_lines) |
336 |
errors.append(' '.join((errno, conffile, lineno, position, descr))) |
337 |
return errors |
338 |
|
339 |
def flake8(self, python, pathes, ignore=None, stdin=None): |
340 |
cmd = [python, '/usr/bin/flake8', '--config=/dev/null'] |
341 |
if ignore: |
342 |
cmd.extend(['--ignore', ignore]) |
343 |
if self.DEFAULT_SELECT: |
344 |
cmd.extend(['--select', self.DEFAULT_SELECT]) |
345 |
cmd.extend(['--max-line-length', str(self.MAX_LINE_LENGTH)]) |
346 |
cmd.extend(['--format', '0020-%(code)s %(path)s %(row)s %(col)s %(text)s']) |
347 |
if self.show_statistics: |
348 |
cmd.append('--statistics') |
349 |
if self.debuglevel > 0: |
350 |
cmd.append('--show-source') |
351 |
cmd.append('--') |
352 |
cmd.extend(pathes) |
353 |
|
354 |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE if stdin else None) |
355 |
if stdin: |
356 |
process.stdin.write(stdin) |
357 |
process.stdin.close() |
358 |
process.wait() |
359 |
return process.stdout.read().splitlines() |
360 |
|
330 |
def fix(self, path, *args): |
361 |
def fix(self, path, *args): |
331 |
for ignore, pathes in self._iter_pathes(path): |
362 |
for ignore, pathes in self._iter_pathes(path): |
332 |
cmd = ['autopep8', '-i', '-aaa'] |
363 |
cmd = ['autopep8', '-i', '-aaa'] |
Lines 356-364
class UniventionPackageCheck(uub.UniventionPackageCheckBase):
|
Link Here
|
---|
|
356 |
return ignored.iteritems() |
387 |
return ignored.iteritems() |
357 |
|
388 |
|
358 |
def format_errors(self, errors): |
389 |
def format_errors(self, errors): |
|
|
390 |
done = set() |
359 |
for i, line in enumerate(errors, 1): |
391 |
for i, line in enumerate(errors, 1): |
360 |
if not line.startswith('0020-'): |
392 |
if not line.startswith('0020-') or line in done: |
361 |
continue |
393 |
continue |
|
|
394 |
done.add(line) |
362 |
code, path, row, col, text = line.split(' ', 4) |
395 |
code, path, row, col, text = line.split(' ', 4) |
363 |
source = [] |
396 |
source = [] |
364 |
while len(errors) > i + 1 and not errors[i].startswith('0020-'): |
397 |
while len(errors) > i + 1 and not errors[i].startswith('0020-'): |