Skip to content

Commit

Permalink
Add check for print statement
Browse files Browse the repository at this point in the history
  • Loading branch information
mzfr authored and mzfr committed Mar 29, 2019
1 parent 6ec379a commit 0d349eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kodi_addon_checker/check_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
25 changes: 25 additions & 0 deletions kodi_addon_checker/check_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
See LICENSES/README.md for more information.
"""

import ast
import json
import os
import re
Expand Down Expand Up @@ -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))))

0 comments on commit 0d349eb

Please sign in to comment.