X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=test%2Frule-syntax-check.py;h=80bbe65bea0d763542f2c3585175fe09141a43ac;hp=ff1b63d075ac7a9dbf4b0e622b3059b8dad9707a;hb=eb89bc1d25086a1b4117683697f35c1398a98c02;hpb=0f52fdee378796df26021208dc684f77be1f877f diff --git a/test/rule-syntax-check.py b/test/rule-syntax-check.py old mode 100755 new mode 100644 index ff1b63d07..80bbe65be --- a/test/rule-syntax-check.py +++ b/test/rule-syntax-check.py @@ -1,38 +1,46 @@ -#!/usr/bin/python # Simple udev rules syntax checker # # (C) 2010 Canonical Ltd. # Author: Martin Pitt # -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but + +# systemd is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. +# Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see . import re import sys +import os +from glob import glob -if len(sys.argv) < 2: - print >> sys.stderr, 'Usage: %s [...]' % sys.argv[0] - sys.exit(2) +if len(sys.argv) > 1: + # explicit rule file list + rules_files = sys.argv[1:] +else: + # take them from the build dir + root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + rules_dir = os.path.join(os.environ.get('top_srcdir', root_dir), 'rules') + if not os.path.isdir(rules_dir): + sys.stderr.write('No rules files given, and %s does not exist, aborting' % rules_dir) + sys.exit(2) + rules_files = glob(os.path.join(rules_dir, '*.rules')) no_args_tests = re.compile('(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$') args_tests = re.compile('(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$') no_args_assign = re.compile('(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|WAIT_FOR|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$') -args_assign = re.compile('(ATTR|ENV|IMPORT){([a-zA-Z0-9/_.*%-]+)}\s*=\s*"([^"]*)"$') +args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*"([^"]*)"$') result = 0 buffer = '' -for path in sys.argv[1:]: +for path in rules_files: lineno = 0 for line in open(path): lineno += 1 @@ -56,8 +64,8 @@ for path in sys.argv[1:]: no_args_assign.match(clause) or args_assign.match(clause)): print('Invalid line %s:%i: %s' % (path, lineno, line)) - print(' clause:', clause) - print() + print(' clause: %s' % clause) + print('') result = 1 break