From 50d4f3cc25f0ca107aebe3b3d60c46716ad545b2 Mon Sep 17 00:00:00 2001 From: mzfr Date: Tue, 13 Nov 2018 21:10:45 +0530 Subject: [PATCH] Add check for SPDX license identifier --- kodi_addon_checker/check_addon.py | 2 ++ kodi_addon_checker/check_files.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/kodi_addon_checker/check_addon.py b/kodi_addon_checker/check_addon.py index f5816218..377e25a6 100644 --- a/kodi_addon_checker/check_addon.py +++ b/kodi_addon_checker/check_addon.py @@ -47,6 +47,8 @@ def start(addon_path, branch_name, all_repo_addons, pr, config=None): check_dependencies.check_addon_dependencies(addon_report, repo_addons, parsed_xml, branch_name) + check_files.check_license_identifier(addon_report, addon_path) + check_files.check_file_permission(addon_report, addon_path) check_files.check_for_invalid_xml_files(addon_report, file_index) diff --git a/kodi_addon_checker/check_files.py b/kodi_addon_checker/check_files.py index b2415cbd..6c8594f7 100644 --- a/kodi_addon_checker/check_files.py +++ b/kodi_addon_checker/check_files.py @@ -1,6 +1,7 @@ import os import re import json +import ast import xml.etree.ElementTree as ET from pathlib import Path from . import handle_files @@ -124,3 +125,21 @@ def check_file_permission(report: Report, addon_path: str): for file in files: if os.path.isfile(file) and os.access(str(file), os.X_OK): report.add(Record(PROBLEM, "%s is marked as stand-alone executable" % relative_path(str(file)))) + + +def check_license_identifier(report: Report, addon_path: str): + """Check whether all the files present in the addon + contains the SPDX license header or not + :addon_path: Path of the addon + """ + + files = Path(addon_path).glob('**/*.py') + + for file in files: + with open(str(file), 'r') as f: + tree = ast.parse(f.read()) + + docstring = ast.get_docstring(tree) + if docstring and "SPDX-License-Identifier" not in docstring: + report.add(Record(WARNING, "SPDX-License-Identifier is missing from addon file %s" % + relative_path(str(file))))