diff --git a/requirements-dev.txt b/requirements-dev.txt index 757983f..f063647 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,6 +9,7 @@ Kodistubs==20.0.1 # docs: https://romanvm.github.io/Kodistubs pytest==7.4.4 pytest-cov==4.1.0 PyYAML==6.0.1 +requests==2.31.0 rstcheck==6.2.0 Sphinx==7.1.2 sphinx-copybutton==0.5.2 diff --git a/scripts/addon_yaml_to_xml.py b/scripts/addon_yaml_to_xml.py index 7735b87..311cb72 100644 --- a/scripts/addon_yaml_to_xml.py +++ b/scripts/addon_yaml_to_xml.py @@ -5,8 +5,12 @@ # lib imports from kodi_addon_checker.check_dependencies import VERSION_ATTRB as xbmc_versions from lxml import etree +import requests import yaml +# global vars +kodi_branch = os.getenv('KODI_BRANCH', 'Nexus').lower() + def handle_asset_elements( parent: etree.ElementBase, @@ -21,6 +25,16 @@ def handle_asset_elements( etree.SubElement(parent, key).text = value +def get_branch_plugins(): + url = f'http://mirrors.kodi.tv/addons/{kodi_branch}/addons.xml' + response = requests.get(url) + + if response.status_code != 200: + raise Exception(f'Failed to get {url}') + + return etree.fromstring(response.content) + + def yaml_to_xml_lxml(yaml_file: str) -> str: # Load YAML file with open(yaml_file, 'r') as file: @@ -30,18 +44,32 @@ def yaml_to_xml_lxml(yaml_file: str) -> str: build_version = os.getenv('BUILD_VERSION') if build_version: # update version if building from CI data['addon']['version'] = build_version + + branch_addons_xml = None + for requirement in data['addon']['requires']['import']: if requirement.get('version'): # if the version is specified in yaml, don't look it up # this allows pinning a requirement to a specific version continue + + requirement_xml = None + if requirement['addon'].startswith('xbmc.'): - requirement['version'] = xbmc_versions[requirement['addon']][os.getenv( - 'KODI_BRANCH', 'Nexus').lower()]['advised'] + requirement['version'] = xbmc_versions[requirement['addon']][kodi_branch]['advised'] elif requirement['addon'].startswith('script.module.'): requirement_xml = os.path.join( os.getcwd(), 'third-party', 'repo-scripts', requirement['addon'], 'addon.xml') + else: + if not branch_addons_xml: + branch_addons_xml = get_branch_plugins() # only get the branch addons.xml if we need it + + # get the requirement version from the branch addons.xml + addon = branch_addons_xml.xpath(f'//addon[@id="{requirement["addon"]}"]') + version = addon[0].attrib['version'] + requirement['version'] = version + if requirement_xml: # get the version property out of the addon tag with open(requirement_xml, 'r', encoding='utf-8') as file: requirement_data = etree.parse(file)