2021-02-13 13:51:52 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
2021-04-02 09:26:37 +00:00
|
|
|
import sys
|
2021-02-13 13:51:52 +01:00
|
|
|
|
|
|
|
# Matches e.g. "| [`bash`]..." and captures "bash" in group 1
|
|
|
|
PORT_TABLE_REGEX = re.compile(r'^\| \[`([^`]+)`\][^`]+$', re.MULTILINE)
|
|
|
|
|
|
|
|
PORT_TABLE_FILE = 'AvailablePorts.md'
|
2021-04-02 09:26:37 +00:00
|
|
|
IGNORE_FILES = {
|
|
|
|
'.gitignore',
|
|
|
|
'.port_include.sh',
|
|
|
|
PORT_TABLE_FILE,
|
|
|
|
'build_all.sh',
|
|
|
|
'build_installed.sh',
|
2021-04-02 21:53:41 -06:00
|
|
|
'README.md',
|
|
|
|
'.hosted_defs.sh'
|
2021-04-02 09:26:37 +00:00
|
|
|
}
|
2021-02-13 13:51:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
def read_port_table(filename):
|
2021-04-02 09:26:37 +00:00
|
|
|
"""Open a file and find all PORT_TABLE_REGEX matches.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
filename (str): file name
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
set: all PORT_TABLE_REGEX matches
|
|
|
|
"""
|
2021-02-13 13:51:52 +01:00
|
|
|
with open(filename, 'r') as fp:
|
|
|
|
return set(PORT_TABLE_REGEX.findall(fp.read()))
|
|
|
|
|
|
|
|
|
|
|
|
def read_port_dirs():
|
2021-04-02 09:26:37 +00:00
|
|
|
"""Check Ports directory for unexpected files and check each port has a package.sh file.
|
|
|
|
|
|
|
|
Returns:
|
2021-04-16 17:40:23 +00:00
|
|
|
list: all ports (set), no errors encountered (bool)
|
2021-04-02 09:26:37 +00:00
|
|
|
"""
|
|
|
|
|
2021-02-13 13:51:52 +01:00
|
|
|
ports = set()
|
|
|
|
all_good = True
|
|
|
|
for entry in os.listdir():
|
|
|
|
if entry in IGNORE_FILES:
|
|
|
|
continue
|
|
|
|
if not os.path.isdir(entry):
|
2021-04-16 17:40:23 +00:00
|
|
|
print(f"Ports/{entry} is neither a port (not a directory) nor an ignored file?!")
|
2021-02-13 13:51:52 +01:00
|
|
|
all_good = False
|
|
|
|
continue
|
|
|
|
if not os.path.exists(entry + '/package.sh'):
|
2021-04-16 17:40:23 +00:00
|
|
|
print(f"Ports/{entry}/ is missing its package.sh?!")
|
2021-02-13 13:51:52 +01:00
|
|
|
all_good = False
|
|
|
|
continue
|
|
|
|
ports.add(entry)
|
|
|
|
|
|
|
|
return ports, all_good
|
|
|
|
|
|
|
|
|
2021-04-16 17:40:23 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2021-02-13 13:51:52 +01:00
|
|
|
def run():
|
2021-04-16 17:40:23 +00:00
|
|
|
"""Check Ports directory and package files for errors."""
|
2021-04-02 09:26:37 +00:00
|
|
|
|
2021-02-13 13:51:52 +01:00
|
|
|
from_table = read_port_table(PORT_TABLE_FILE)
|
2021-04-16 17:40:23 +00:00
|
|
|
ports, all_good = read_port_dirs()
|
2021-02-13 13:51:52 +01:00
|
|
|
|
2021-04-16 17:40:23 +00:00
|
|
|
if from_table - ports:
|
2021-02-13 13:51:52 +01:00
|
|
|
all_good = False
|
|
|
|
print('AvailablePorts.md lists ports that do not appear in the file system:')
|
2021-04-16 17:40:23 +00:00
|
|
|
for port in sorted(from_table - ports):
|
|
|
|
print(f" {port}")
|
2021-02-13 13:51:52 +01:00
|
|
|
|
2021-04-16 17:40:23 +00:00
|
|
|
if ports - from_table:
|
2021-02-13 13:51:52 +01:00
|
|
|
all_good = False
|
|
|
|
print('AvailablePorts.md is missing the following ports:')
|
2021-04-16 17:40:23 +00:00
|
|
|
for port in sorted(ports - from_table):
|
|
|
|
print(f" {port}")
|
|
|
|
|
|
|
|
if not check_package_files(ports):
|
|
|
|
all_good = False
|
2021-02-13 13:51:52 +01:00
|
|
|
|
|
|
|
if not all_good:
|
2021-04-02 09:26:37 +00:00
|
|
|
sys.exit(1)
|
2021-02-13 13:51:52 +01:00
|
|
|
|
|
|
|
print('No issues found.')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-04-16 17:40:23 +00:00
|
|
|
os.chdir(f"{os.path.dirname(__file__)}/../Ports")
|
2021-02-13 13:51:52 +01:00
|
|
|
run()
|