-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if addon version is compliant with repository generator
- Loading branch information
Showing
4 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |