Skip to content

Commit

Permalink
Meta: lint-ports: Check package files for required properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles authored and linusg committed Apr 16, 2021
1 parent a206ab2 commit bb6bb7b
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions Meta/lint-ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -45,35 +45,68 @@ 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)

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)
Expand All @@ -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()

0 comments on commit bb6bb7b

Please sign in to comment.