From 219ea251208f4ffa1e7eca9fd815c8c66c3499f5 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 10 Nov 2007 03:12:09 +0000 Subject: Convert all the checks in repoman.checks to use a new LineCheck interface that takes a single line as an argument. This has at least a few of benefits: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Eliminates lots of redundant code * Error messages are ordered by line number across all checks The performance is slightly worse due to the increased number of method calls, but it's not really noticeable in comparison to the time consumed by dependency checks. Thanks to Petteri Räty for the initial patch which I only made a few minor modifications to. svn path=/main/trunk/; revision=8483 --- bin/repoman | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'bin') diff --git a/bin/repoman b/bin/repoman index 85d27d20a..ca7530b9f 100755 --- a/bin/repoman +++ b/bin/repoman @@ -24,7 +24,7 @@ from commands import getstatusoutput from fileinput import input from grp import getgrnam from itertools import izip -from stat import S_ISDIR, ST_CTIME, ST_GID, ST_MTIME +from stat import S_ISDIR, ST_CTIME try: import cPickle as pickle @@ -44,13 +44,11 @@ except ImportError: del os.environ["PORTAGE_LEGACY_GLOBALS"] try: - from repoman.checks import EbuildWhitespace, EbuildHeader, EbuildQuote, \ - EbuildAssignment, EbuildNestedDie, EbuildUselessDodoc, EbuildUselessCdS + from repoman.checks import run_checks except ImportError: from os import path as osp sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), 'pym')) - from repoman.checks import EbuildWhitespace, EbuildHeader, EbuildQuote, \ - EbuildAssignment, EbuildNestedDie, EbuildUselessDodoc, EbuildUselessCdS + from repoman.checks import run_checks import portage.checksum import portage.const @@ -1364,35 +1362,16 @@ for x in scanlist: for mybad in mybadrestrict: fails["RESTRICT.invalid"].append(x+"/"+y+".ebuild: %s" % mybad) # Syntax Checks - path = checkdir + '/' + y + '.ebuild' - myear = time.gmtime(os.stat(path)[ST_MTIME])[0] - f = open(path, 'rb') + relative_path = os.path.join(x, y + ".ebuild") + full_path = os.path.join(repodir, relative_path) + f = open(full_path, 'rb') try: - contents = f.readlines() + for check_name, e in run_checks(f, os.stat(full_path).st_mtime): + stats[check_name] += 1 + fails[check_name].append(relative_path + ': %s' % e) finally: f.close() del f - for check in (EbuildWhitespace, EbuildQuote, - EbuildAssignment, EbuildUselessDodoc, EbuildUselessCdS): - c = check(contents) - errors = c.Run() - for e in errors: - stats[c.repoman_check_name] += 1 - fails[c.repoman_check_name].append(x + '/' + y + '.ebuild: %s' % e[1] % e[0]) - del check - check = EbuildHeader(contents, str(myear)) - errors = check.Run() - for e in errors: - stats[check.repoman_check_name] += 1 - fails[check.repoman_check_name].append(x + '/' + y + '.ebuild: %s' % e[1] % e[0]) - del check - check = EbuildNestedDie(contents) - errors = check.Run() - for e in errors: - stats[check.repoman_check_name] += 1 - fails[check.repoman_check_name].append( - x + '/' + y + '.ebuild: %s' % e[1] % e[0]) - del check, errors, path, contents, myear if options.force: # The dep_check() calls are the most expensive QA test. If --force -- cgit v1.2.3-1-g7c22