Skip to content

Commit

Permalink
Add check for SPDX license identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
mzfr committed Nov 20, 2018
1 parent 710c192 commit 419fbcb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kodi_addon_checker/check_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def start(addon_path, branch_name, all_repo_addons, pr, config=None):

check_files.check_file_permission(addon_report, file_index)

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)

check_files.check_for_invalid_json_files(addon_report, file_index)
Expand Down
19 changes: 19 additions & 0 deletions kodi_addon_checker/check_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import re
import json
import ast
import xml.etree.ElementTree as ET
from pathlib import Path
from . import handle_files
Expand Down Expand Up @@ -131,3 +132,21 @@ def check_file_permission(report: Report, file_index: list):
file = os.path.join(file["path"], file["name"])
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))))

0 comments on commit 419fbcb

Please sign in to comment.