diff --git a/kodi_addon_checker/check_addon.py b/kodi_addon_checker/check_addon.py index 7078f171..d5c0b2c0 100644 --- a/kodi_addon_checker/check_addon.py +++ b/kodi_addon_checker/check_addon.py @@ -72,6 +72,8 @@ def start(addon_path, args, all_repo_addons, config=None): check_entrypoint.check_complex_addon_entrypoint( addon_report, addon_path, parsed_xml, max_entrypoint_count) + check_files.check_print_statement(addon_report, file_index) + check_py3_compatibility.check_py3_compatibility(addon_report, addon_path, args.branch) if config.is_enabled("check_license_file_exists"): diff --git a/kodi_addon_checker/check_files.py b/kodi_addon_checker/check_files.py index fcadc9b6..30bc3fe9 100644 --- a/kodi_addon_checker/check_files.py +++ b/kodi_addon_checker/check_files.py @@ -6,6 +6,7 @@ See LICENSES/README.md for more information. """ +import ast import json import os import re @@ -139,3 +140,27 @@ 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_print_statement(report: Report, file_index: list): + """Check whether any addon files have a print statement in them + or not + :file_index: list having names and path of all the files present in addon + """ + for file in file_index: + if os.path.splitext(file["name"])[1] == '.py': + file = os.path.join(file["path"], file["name"]) + + with open(file) as f: + source = f.read() + + try: + for node in ast.walk(ast.parse(source)): + if (isinstance(node, ast.Expr) and + isinstance(node.value, ast.Call) and + isinstance(node.value.func, ast.Name)): + + if node.value.func.id == "print": + report.add(Record(WARNING, "%s has a print statement" % relative_path(str(file)))) + except SyntaxError: + report.add(Record(PROBLEM, "Invalid code present in file %s" % (relative_path(file))))