Skip to content

Commit

Permalink
refactor check_addon_dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Rechi committed Nov 19, 2018
1 parent 866eee1 commit e8f7b24
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 53 deletions.
21 changes: 21 additions & 0 deletions kodi_addon_checker/addons/Addon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Copyright (C) 2018 Team Kodi
This file is part of Kodi - kodi.tv
SPDX-License-Identifier: GPL-3.0-only
See LICENSES/README.md for more information.
"""

from .AddonDependency import AddonDependency

import xml.etree.ElementTree as ET


class Addon(object):
def __init__(self, addon_xml: ET.Element):
super(Addon, self).__init__()
self.id = addon_xml.get('id')
self.version = addon_xml.get('version')
self.dependencies = []
for dependency in addon_xml.findall('./requires/import'):
self.dependencies.append(AddonDependency(dependency))
20 changes: 20 additions & 0 deletions kodi_addon_checker/addons/AddonDependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Copyright (C) 2018 Team Kodi
This file is part of Kodi - kodi.tv
SPDX-License-Identifier: GPL-3.0-only
See LICENSES/README.md for more information.
"""

from distutils.version import LooseVersion
import xml.etree.ElementTree as ET


class AddonDependency(object):
def __init__(self, import_xml: ET.Element):
super(AddonDependency, self).__init__()
self.id = import_xml.get('addon')
self.version = None
if import_xml.get('version') is not None:
self.version = LooseVersion(import_xml.get('version'))
self.optional = import_xml.get('optional', False)
7 changes: 7 additions & 0 deletions kodi_addon_checker/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Copyright (C) 2018 Team Kodi
This file is part of Kodi - kodi.tv
SPDX-License-Identifier: GPL-3.0-only
See LICENSES/README.md for more information.
"""
85 changes: 32 additions & 53 deletions kodi_addon_checker/check_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
See LICENSES/README.md for more information.
"""

from .addons.Addon import Addon

import logging
from distutils.version import LooseVersion

Expand Down Expand Up @@ -39,46 +41,38 @@ def check_addon_dependencies(report: Report, repo_addons: dict, parsed_xml, bran
:branch_name: name of the kodi branch/version
"""

optional_deps, deps = _get_users_dependencies(parsed_xml)
addon = Addon(parsed_xml)
ignore = _get_ignore_list(branch_name)

if optional_deps:
for dependency, version in optional_deps.items():
if dependency not in repo_addons:
report.add(Record(INFORMATION,
"Optional dependency %s with version %s is not present in Kodi repository" %
(dependency, version)))
else:
deps_version = repo_addons[dependency]
if deps_version is not None:
if LooseVersion(version) > LooseVersion(deps_version) and (dependency not in ignore):
report.add(INFORMATION,
"version mismatch for optional dependencies: %s. Available: %s, Required: %s" %
(dependency, deps_version, version))

for required_addon, required_version in deps.items():
if required_addon not in repo_addons:
if required_addon not in ignore:
report.add(Record(
PROBLEM, "Required addon %s not available in current repository." % required_addon))
elif required_addon in VERSION_ATTRB:
try:
version = VERSION_ATTRB[required_addon][branch_name]
if LooseVersion(version) != LooseVersion(required_version):
report.add(Record(WARNING, "For %s it is advised to set %s version to %s" %
(branch_name, required_addon, version)))
except KeyError:
LOGGER.warn("Misconfiguration in VERSION_ATTRB of check_dependencies")

else:
available_version = repo_addons[required_addon]

if required_version is None:
report.add(Record(WARNING, "Required addon %s does not require a fixed version Available: %s "
% (required_addon, available_version)))
elif LooseVersion(available_version) < LooseVersion(required_version) and (required_addon not in ignore):
report.add(Record(PROBLEM, "Version mismatch for addon %s. Required: %s, Available: %s "
% (required_addon, required_version, available_version)))
for dependency in addon.dependencies:
if dependency.id in ignore and not dependency.optional:
pass

elif dependency.id not in repo_addons:
report.add(Record(INFORMATION if dependency.optional else PROBLEM,
"{} dependency {} is not available in current repository"
.format("Optional" if dependency.optional else "Required", dependency.id)))

elif dependency.version is None:
report.add(Record(INFORMATION if dependency.optional else WARNING,
"{} dependency {} does not require a minimum version, available: {}"
.format("Optional" if dependency.optional else "Required", dependency.id,
repo_addons[dependency.id])))

elif LooseVersion(repo_addons[dependency.id]) < dependency.version:
report.add(Record(INFORMATION if dependency.optional else PROBLEM,
"Version mismatch for {} dependency {}, required: {}, Available: {}"
.format("optional" if dependency.optional else "required", dependency.id,
dependency.version, repo_addons[dependency.id])))

if dependency.id in VERSION_ATTRB:
try:
version = VERSION_ATTRB[dependency.id][branch_name]
if LooseVersion(version) != dependency.version:
report.add(Record(WARNING, "For {} it is advised to set {} version to {}"
.format(branch_name, dependency.id, version)))
except KeyError:
LOGGER.warn("Misconfiguration in VERSION_ATTRB of check_dependencies")


def _get_ignore_list(branch_name):
Expand All @@ -93,18 +87,3 @@ def _get_ignore_list(branch_name):

else:
return common_ignore_deps


def _get_users_dependencies(parsed_xml):
"""Gets all the dependencies from a given addon
:parsed_xml: parsed addon.xml
"""
user_deps = {}
optional_deps = {}
for i in parsed_xml.findall("requires/import"):
if i.get("optional"):
optional_deps[i.get("addon")] = i.get("version")
else:
user_deps[i.get("addon")] = i.get("version")

return optional_deps, user_deps

0 comments on commit e8f7b24

Please sign in to comment.