Browse Source

Meta: lint-ports: Check package files for required properties

Brendan Coles 4 years ago
parent
commit
bb6bb7bc5e
1 changed files with 45 additions and 12 deletions
  1. 45 12
      Meta/lint-ports.py

+ 45 - 12
Meta/lint-ports.py

@@ -36,7 +36,7 @@ def read_port_dirs():
     """Check Ports directory for unexpected files and check each port has a package.sh file.
 
     Returns:
-        list: all ports (set), errors encountered (bool)
+        list: all ports (set), no errors encountered (bool)
     """
 
     ports = set()
@@ -45,11 +45,11 @@ def read_port_dirs():
         if entry in IGNORE_FILES:
             continue
         if not os.path.isdir(entry):
-            print('"Ports/{}" is neither a port (not a directory) nor an ignored file?!'.format(entry))
+            print(f"Ports/{entry} is neither a port (not a directory) nor an ignored file?!")
             all_good = False
             continue
         if not os.path.exists(entry + '/package.sh'):
-            print('"Ports/{}/" is missing its package.sh?!'.format(entry))
+            print(f"Ports/{entry}/ is missing its package.sh?!")
             all_good = False
             continue
         ports.add(entry)
@@ -57,23 +57,56 @@ def read_port_dirs():
     return ports, all_good
 
 
+def check_package_files(ports):
+    """Check port package.sh file for required properties.
+
+    Args:
+        ports (set): List of all ports to check
+
+    Returns:
+        bool: no errors encountered
+    """
+
+    packages = set()
+    all_good = True
+    for port in ports:
+        package_file = f"{port}/package.sh"
+        if not os.path.exists(package_file):
+            continue
+        packages.add(package_file)
+
+    properties = ['port', 'version', 'files', 'auth_type']
+    for package in packages:
+        with open(package, 'r') as fp:
+            data = fp.read()
+            for p in properties:
+                if not re.findall(f"^{p}=", data, re.M):
+                    print(f"Ports/{package} is missing '{p}'")
+                    all_good = False
+
+    return all_good
+
+
 def run():
-    """Check Ports directory contents for errors."""
+    """Check Ports directory and package files for errors."""
 
     from_table = read_port_table(PORT_TABLE_FILE)
-    from_fs, all_good = read_port_dirs()
+    ports, all_good = read_port_dirs()
 
-    if from_table - from_fs:
+    if from_table - ports:
         all_good = False
         print('AvailablePorts.md lists ports that do not appear in the file system:')
-        for port in sorted(from_table - from_fs):
-            print('    {}'.format(port))
+        for port in sorted(from_table - ports):
+            print(f"    {port}")
 
-    if from_fs - from_table:
+    if ports - from_table:
         all_good = False
         print('AvailablePorts.md is missing the following ports:')
-        for port in sorted(from_fs - from_table):
-            print('    {}'.format(port))
+        for port in sorted(ports - from_table):
+            print(f"    {port}")
+
+    if not check_package_files(ports):
+        all_good = False
 
     if not all_good:
         sys.exit(1)
@@ -82,5 +115,5 @@ def run():
 
 
 if __name__ == '__main__':
-    os.chdir(os.path.dirname(__file__) + "/../Ports")
+    os.chdir(f"{os.path.dirname(__file__)}/../Ports")
     run()