Skip to content

Commit

Permalink
Check if addon version is compliant with repository generator
Browse files Browse the repository at this point in the history
  • Loading branch information
enen92 committed Apr 12, 2021
1 parent 4069de3 commit 6981272
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ It can also be used locally for detecting problems in your addons.

- Checks if addon.xml and license file exists for an addon.

- Checks if the version in addon.xml is valid (for repository generator)

- Checks if all xml files are valid.

- Check if all the json files are valid.
Expand Down
10 changes: 6 additions & 4 deletions kodi_addon_checker/check_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import os
import xml.etree.ElementTree as ET

from . import (check_artwork, check_dependencies, check_entrypoint,
check_files, check_addon_branches, check_py3_compatibility,
check_string, check_url, common, handle_files,
schema_validation, ValidKodiVersions)
from . import (check_allowed_versions, check_artwork, check_dependencies,
check_entrypoint, check_files, check_addon_branches,
check_py3_compatibility, check_string, check_url, common,
handle_files, schema_validation, ValidKodiVersions)
from .addons.Addon import Addon
from .addons.Repository import Repository
from .versions import KodiVersion
Expand Down Expand Up @@ -42,6 +42,8 @@ def start(addon_path, args, all_repo_addons, config=None):
addon_xml_path = os.path.join(addon_path, "addon.xml")
parsed_xml = ET.parse(addon_xml_path).getroot()

# check if provided version for the addon is allowed
check_allowed_versions.check_version(addon_report, parsed_xml)
# Extract common path from addon paths
# All paths will be printed relative to this path
common.REL_PATH = os.path.split(addon_path[:-1])[0]
Expand Down
43 changes: 43 additions & 0 deletions kodi_addon_checker/check_allowed_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Copyright (C) 2021 Team Kodi
This file is part of Kodi - kodi.tv
SPDX-License-Identifier: GPL-3.0-only
See LICENSES/README.md for more information.
"""

import re
from .record import PROBLEM, WARNING, Record
from .report import Report


def version_is_valid(version):
"""Checks if a version is valid
Args:
version (str): The version string
Returns:
[bool]: If the version is valid
"""
return bool(re.match(r"^(\d+\.\d+(\.\d+){0,4}([+~\w]+(\.\d+)?)?)$",
version))


def check_version(report: Report, parsed_xml):
"""Checks if the version for the addon defined in addon.xml is valid
Args:
report (Report): The report object
parsed_xml (et.Element): The parsed addon.xml
"""
if "version" not in parsed_xml.attrib.keys():
report.add(Record(PROBLEM, "Missing version in addon.xml"))
return

if not version_is_valid(parsed_xml.attrib["version"]):
report.add(Record(PROBLEM, "Invalid version {} in addon.xml. " \
"Please use the major.minor.revision (e.g. 1.0.0) format or " \
"major.minor.revision+localversion_identifier (e.g. 1.0.0+matrix.1)".format(
parsed_xml.attrib["version"]
)))
19 changes: 19 additions & 0 deletions tests/test_allowed_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#

from kodi_addon_checker.check_allowed_versions import version_is_valid

def test_addonversion_simple():
assert version_is_valid("1.0.1")


def test_addonversion_localversionidentifier():
assert version_is_valid("1.0.1+matrix.1")


def test_addonversion_localversionidentifier2():
assert version_is_valid("1.0.1+matrix.2")


def test_invalidversion():
assert not version_is_valid("someinvalidversion")

0 comments on commit 6981272

Please sign in to comment.