termux-packages/scripts/lint-packages.py

34 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
def main():
package_dir = 'packages'
for pkgdir_name in sorted(os.listdir(package_dir)):
dir_path = package_dir + '/' + pkgdir_name
build_sh_path = dir_path + '/build.sh'
if not os.path.isfile(build_sh_path):
sys.exit('No build.sh file in: ' + pkgdir_name)
with open(build_sh_path) as build_sh:
lines = build_sh.readlines()
validate_package(pkgdir_name, lines)
def validate_package(package_name, lines):
if len(lines) < 3:
print('Too few lines in package: ' + package_name)
return
if not lines[0].startswith('TERMUX_PKG_HOMEPAGE='):
print('The first line is not TERMUX_PKG_HOMEPAGE: ' + package_name)
if not lines[1].startswith('TERMUX_PKG_DESCRIPTION='):
print('The second line is not TERMUX_PKG_DESCRIPTION: ' + package_name)
line_number = 1
for line in lines:
if line.endswith(' \n'):
print('Line ' + str(line_number) + ' has trailing whitespace: ' + package_name)
line_number += 1
if __name__ == '__main__':
main()