rule-syntax-check.py revision 0b87a07761dcad31583142a3a454c42833e65a09
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# Simple udev rules syntax checker
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# (C) 2010 Canonical Ltd.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# Author: Martin Pitt <martin.pitt@ubuntu.com>
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# This program is free software; you can redistribute it and/or modify it
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# under the terms of the GNU General Public License as published by
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# the Free Software Foundation; either version 2 of the License, or
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# (at your option) any later version.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# This program is distributed in the hope that it will be useful, but
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# WITHOUT ANY WARRANTY; without even the implied warranty of
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# General Public License for more details.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# You should have received a copy of the GNU General Public License
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# along with this program; if not, write to the Free Software Foundation,
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering print >> sys.stderr, 'Usage: %s <rules file> [...]' % sys.argv[0]
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poetteringno_args_tests = re.compile('(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$')
6482f6269c87d2249e52e889a63adbdd50f2d691Ronny Chevalierargs_tests = re.compile('(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$')
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringno_args_assign = re.compile('(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|WAIT_FOR|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$')
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poetteringargs_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*=\s*"([^"]*)"$')
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering # handle line continuation
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering # filter out comments and empty lines
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering if not (no_args_tests.match(clause) or args_tests.match(clause) or
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering no_args_assign.match(clause) or args_assign.match(clause)):
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering print('Invalid line %s:%i: %s' % (path, lineno, line))