]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - test/rule-syntax-check.py
core: use id unit when retrieving unit file state (#8038)
[thirdparty/systemd.git] / test / rule-syntax-check.py
index 4f27fb015b4b3b4df13815d743cdf381de1cc533..e053b027ca1ef005a00eb5fa060cfb9fbbda5766 100755 (executable)
@@ -24,17 +24,9 @@ import sys
 import os
 from glob import glob
 
-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'))
+rules_files = sys.argv[1:]
+if not rules_files:
+    sys.exit('Specify files to test as arguments')
 
 no_args_tests = re.compile(r'(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$')
 args_tests = re.compile(r'(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$')
@@ -44,6 +36,7 @@ args_assign = re.compile(r'(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)
 result = 0
 buffer = ''
 for path in rules_files:
+    print('# looking at {}'.format(path))
     lineno = 0
     for line in open(path):
         lineno += 1
@@ -66,9 +59,9 @@ for path in rules_files:
             if not (no_args_tests.match(clause) or args_tests.match(clause) or
                     no_args_assign.match(clause) or args_assign.match(clause)):
 
-                print('Invalid line %s:%i: %s' % (path, lineno, line))
-                print('  clause: %s' % clause)
-                print('')
+                print('Invalid line {}:{}: {}'.format(path, lineno, line))
+                print('  clause:', clause)
+                print()
                 result = 1
                 break