1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

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

This commit is contained in:
Brendan Coles 2021-04-16 17:40:23 +00:00 committed by Linus Groh
parent a206ab2211
commit bb6bb7bc5e

View file

@ -36,7 +36,7 @@ def read_port_dirs():
"""Check Ports directory for unexpected files and check each port has a package.sh file. """Check Ports directory for unexpected files and check each port has a package.sh file.
Returns: Returns:
list: all ports (set), errors encountered (bool) list: all ports (set), no errors encountered (bool)
""" """
ports = set() ports = set()
@ -45,11 +45,11 @@ def read_port_dirs():
if entry in IGNORE_FILES: if entry in IGNORE_FILES:
continue continue
if not os.path.isdir(entry): 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 all_good = False
continue continue
if not os.path.exists(entry + '/package.sh'): 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 all_good = False
continue continue
ports.add(entry) ports.add(entry)
@ -57,23 +57,56 @@ def read_port_dirs():
return ports, all_good 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(): 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_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 all_good = False
print('AvailablePorts.md lists ports that do not appear in the file system:') print('AvailablePorts.md lists ports that do not appear in the file system:')
for port in sorted(from_table - from_fs): for port in sorted(from_table - ports):
print(' {}'.format(port)) print(f" {port}")
if from_fs - from_table: if ports - from_table:
all_good = False all_good = False
print('AvailablePorts.md is missing the following ports:') print('AvailablePorts.md is missing the following ports:')
for port in sorted(from_fs - from_table): for port in sorted(ports - from_table):
print(' {}'.format(port)) print(f" {port}")
if not check_package_files(ports):
all_good = False
if not all_good: if not all_good:
sys.exit(1) sys.exit(1)
@ -82,5 +115,5 @@ def run():
if __name__ == '__main__': if __name__ == '__main__':
os.chdir(os.path.dirname(__file__) + "/../Ports") os.chdir(f"{os.path.dirname(__file__)}/../Ports")
run() run()