Skip to content

Commit

Permalink
add reverse dependencies check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rechi committed Nov 19, 2018
1 parent 0929831 commit 099d385
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ It can also be used locally for detecting problems in your addons.

- Check if files in addon are marked as executable or not.

- Check for unused script.module addons

All of the validation and checks are done according to the kodi [addon rules](https://kodi.wiki/view/Add-on_rules)

## Installation
Expand Down
9 changes: 9 additions & 0 deletions kodi_addon_checker/addons/Addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ def __init__(self, addon_xml: ET.Element):
self.dependencies = []
for dependency in addon_xml.findall('./requires/import'):
self.dependencies.append(AddonDependency(dependency))

def __eq__(self, other):
return self.id == other.id and self.version == other.version

def dependsOn(self, addonId):
for dependency in self.dependencies:
if dependency.id == addonId:
return True
return False
7 changes: 7 additions & 0 deletions kodi_addon_checker/addons/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ def find(self, addonId):
if addon.id == addonId:
return addon
return None

def rdepends(self, addonId):
rdepends = []
for addon in self.addons:
if addon.dependsOn(addonId):
rdepends.append(addon)
return rdepends
2 changes: 2 additions & 0 deletions kodi_addon_checker/check_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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_dependencies.check_reverse_dependencies(addon_report, addon_id, branch_name, all_repo_addons)

check_files.check_file_permission(addon_report, file_index)

check_files.check_for_invalid_xml_files(addon_report, file_index)
Expand Down
35 changes: 35 additions & 0 deletions kodi_addon_checker/check_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,41 @@ def check_addon_dependencies(report: Report, repo_addons: dict, parsed_xml, bran
LOGGER.warn("Misconfiguration in VERSION_ATTRB of check_dependencies")


def check_reverse_dependencies(report: Report, addon: str, branch_name: str, all_repo_addons: dict):
addonInRepo = None
rdepends = []
rdependsLowerBranch = []
branchFound = False

for branch, repo in sorted(all_repo_addons.items()):
if not branchFound and branch != branch_name:
for rdepend in repo.rdepends(addon):
if rdepend not in rdependsLowerBranch:
rdependsLowerBranch.append(rdepend)
continue
branchFound = True

addonFind = repo.find(addon)
if addonFind and addonInRepo and addonFind != addonInRepo:
break

addonInRepo = addonFind

for rdepend in repo.rdepends(addon):
if rdepend not in rdependsLowerBranch and rdepend not in rdepends:
rdepends.append(rdepend)
if addon.startswith("script.module.") and len(rdepends) + len(rdependsLowerBranch) == 0:
report.add(Record(WARNING, "This module isn't required by any add-on."))

if len(rdepends) > 0:
report.add(Record(INFORMATION, "Reverse dependencies: {} ({})"
.format(", ".join(sorted([r.id for r in rdepends])), len(rdepends))))

if len(rdependsLowerBranch) > 0:
report.add(Record(INFORMATION, "Reverse dependencies (in lower branches): {} ({})"
.format(", ".join(sorted([r.id for r in rdependsLowerBranch])), len(rdependsLowerBranch))))


def _get_ignore_list(branch_name):

if branch_name == "leia":
Expand Down

0 comments on commit 099d385

Please sign in to comment.