Date: Wed, 17 Oct 2012 20:17:56 +0000 (UTC) From: Chris Rees <crees@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r241647 - user/crees/rclint Message-ID: <201210172017.q9HKHuPT054844@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: crees (ports committer) Date: Wed Oct 17 20:17:56 2012 New Revision: 241647 URL: http://svn.freebsd.org/changeset/base/241647 Log: Fix regex code Submitted by: eadler Check that last line of file contains check_run_rc Functions checking still edgy Modified: user/crees/rclint/errors.en user/crees/rclint/problems.en user/crees/rclint/rclint.py Modified: user/crees/rclint/errors.en ============================================================================== --- user/crees/rclint/errors.en Wed Oct 17 19:24:13 2012 (r241646) +++ user/crees/rclint/errors.en Wed Oct 17 20:17:56 2012 (r241647) @@ -39,4 +39,9 @@ rcvar_quoted rcvar is quoted Do not quot rcsid Missing FreeBSD RCSId keyword All rc scripts must contain a line beginning # $FreeBSD$. Do not include blank lines without comment markers at the beginning (#) until the script begins +run_rc_argument Incorrect argument to run_rc_command The last line of the file should be run_rc_command $1 +run_rc_cruft Order of rc file incorrect Order of the rc file should be shebang/header/$FreeBSD$/setting defaults/setting other definitions/defining functions. Do not include unassociated shell commands, and blocks must be separated by single blank lines. Single blank lines may appear inside the defaults, definitions and functions blocks. +run_rc_followed run_rc_command line is not the last line in the file Do not write anything after the run_rc_command line +run_rc_quoted Quoted argument to run_rc_command No need to quote the argument to run_rc_command + shebang Incorrect shebang used All rc scripts must start with the correct shebang; #!/bin/sh Modified: user/crees/rclint/problems.en ============================================================================== --- user/crees/rclint/problems.en Wed Oct 17 19:24:13 2012 (r241646) +++ user/crees/rclint/problems.en Wed Oct 17 20:17:56 2012 (r241647) @@ -1,2 +1,3 @@ # Format of this file: regex<TAB>short_explanation<TAB>explanation -regex explain explanation +#regex explain explanation +^[^#{}.l\s][^-=()]*[^)]$ Unassociated shell command Do not put shell commands outside functions-- it slows down rc on boot and every invocation of the rc file Modified: user/crees/rclint/rclint.py ============================================================================== --- user/crees/rclint/rclint.py Wed Oct 17 19:24:13 2012 (r241646) +++ user/crees/rclint/rclint.py Wed Oct 17 20:17:56 2012 (r241647) @@ -55,7 +55,7 @@ def explain(error): initial_indent='==> ', subsequent_indent=' ') def error(type, line_number, filename): - logging.error("[%d]%s: %s " % (line_number, filename, errors[type][0])) + logging.error("[%d]%s: %s " % (line_number + 1, filename, errors[type][0])) explain(errors[type]) def check_quoted(string): @@ -73,7 +73,7 @@ def get_value(var, line): def get_assignment(line): try: - return re.match('(\S+)=(\S+)$', line).groups() + return re.match('(\S+)=(.+)$', line).groups() except: return False @@ -246,7 +246,8 @@ def check_functions(lines, num, filename func = { } while lines[num]: - while not lines[num] or lines[num][0] == '#': num += 1 + while not lines[num] or lines[num][0] == '#': + num += 1 if lines[num][-2:] != '()': if lines[num][-1] == '{': @@ -257,16 +258,18 @@ def check_functions(lines, num, filename if ' ' in lines[num]: error('functions_spaces', num, filename) func['name'] = lines[num][:-2] + func['length'] = 0 num += 1 if lines[num] != '{': error('functions_brace_missing', num, filename) num += 1 - tmp = num + try: while lines[num] != '}': - tmp += 1 + print lines[num] + num += 1 if lines[num] and lines[num][0] != '#': func['length'] += 1 except: @@ -276,13 +279,43 @@ def check_functions(lines, num, filename if func['length'] == 1: error('functions_short', num, filename) + print lines[num] + print lines[num+1] + print lines[num+2] + + if lines[num+2] and '{' in lines[num+2]: + return check_functions(lines, num, filename) + else: + return num + +def check_run_rc(lines, num, filename): + logging.debug('Checking the last line of the file contains run_rc_command') + + while not lines[num] or lines[num][0] == '#': + num += 1 + + try: + arg = re.match('run_rc_command (.*)$', lines[num]).group(1) + if check_quoted(arg): + error('run_rc_quoted', num, filename) + elif arg != r'$1': + error('run_rc_argument', num, filename) + + if num < len(lines) - 1: + error('run_rc_followed', num, filename) + except: + error('run_rc_cruft', num, filename) + def general_checks(lines, filename): - logging.debug('Checking for unrecommended sequences') - for num in range(0, len(lines)): + logging.debug('Checking for unrecommended sequences and orphan commands') + # Don't use regex on last line, it must contain run_rc_command, which fails + # unassociated shell command test. We already hacked for load_rc_config + for num in range(0, len(lines) - 1): for regex in problems.keys(): if lines[num] and re.search(regex, lines[num]): - logging.warn("[%d]%s: %s " % (num, filename, problems[key][1])) - explain(problem) + logging.warn("[%d]%s: %s " % (num + 1, filename, + problems[regex][0])) + explain(problems[regex]) def do_rclint(filename): logging.debug('Suck in file %s' % filename) @@ -298,6 +331,7 @@ def do_rclint(filename): lineno['defaults'] = check_defaults(lines, lineno['intro'], filename) lineno['definitions'] = check_definitions(lines, lineno['defaults'], filename) lineno['functions'] = check_functions(lines, lineno['definitions'], filename) + check_run_rc(lines, lineno['functions'], filename) general_checks(lines, filename) @@ -309,7 +343,7 @@ parser.add_argument('-v', action='count' args = parser.parse_args() verbosity = args.v -logging.basicConfig(level=logging.DEBUG if verbosity > 1 else logging.ERROR) +logging.basicConfig(level=logging.DEBUG if verbosity > 1 else logging.WARN) errors = read_db('errors', args.language[0]) problems = read_db('problems', args.language[0])
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210172017.q9HKHuPT054844>