chiark / gitweb /
test: simplify rules-test.sh wrapper
authorMartin Pitt <martin.pitt@ubuntu.com>
Tue, 20 Jan 2015 19:50:35 +0000 (20:50 +0100)
committerMartin Pitt <martin.pitt@ubuntu.com>
Tue, 20 Jan 2015 19:52:25 +0000 (20:52 +0100)
Drop globbing of rules/*.rules in the rules-test.sh wrapper and move that logic
into the actual test rule-syntax-check.py. This can still be called with
individual rules files, but when being called without arguments it will now
process all top_builddir/rules/*.rules.

Preparation for dropping the shell wrappers altogether.

test/rule-syntax-check.py
test/rules-test.sh

index 8c0180bd3ca62aac74ef663e176d504fe2d0196d..80bbe65bea0d763542f2c3585175fe09141a43ac 100644 (file)
 
 import re
 import sys
 
 import re
 import sys
+import os
+from glob import glob
 
 
-if len(sys.argv) < 2:
-    sys.stderr.write('Usage: %s <rules file> [...]\n' % 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_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*"([^"]*)"$')
@@ -30,7 +40,7 @@ args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\
 
 result = 0
 buffer = ''
 
 result = 0
 buffer = ''
-for path in sys.argv[1:]:
+for path in rules_files:
     lineno = 0
     for line in open(path):
         lineno += 1
     lineno = 0
     for line in open(path):
         lineno += 1
index 219575360e49a198776eb05a617b09dd19a1eb80..50b83a3e9165ef9ac9bd86f709e93eb583ac01d7 100755 (executable)
 # You should have received a copy of the GNU Lesser General Public License
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 # You should have received a copy of the GNU Lesser General Public License
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
-[ -n "$srcdir" ] || srcdir=`dirname $0`/..
-
 # skip if we don't have python
 type ${PYTHON:-python} >/dev/null 2>&1 || {
         echo "$0: No $PYTHON installed, skipping udev rule syntax check"
         exit 0
 }
 
 # skip if we don't have python
 type ${PYTHON:-python} >/dev/null 2>&1 || {
         echo "$0: No $PYTHON installed, skipping udev rule syntax check"
         exit 0
 }
 
-$PYTHON $srcdir/test/rule-syntax-check.py `find $srcdir/rules -name '*.rules'`
+$PYTHON $srcdir/test/rule-syntax-check.py