Skip to content

Commit

Permalink
wip: parsing of metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AnizR committed Dec 13, 2024
1 parent ab9b6e8 commit bbe3c23
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/odoo_sort_manifest_depends/sort_manifest_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
#
# SPDX-License-Identifier: MIT

import re
from pathlib import Path
from re import DOTALL, search, sub

import click
import requests
from click import command, option
from diskcache import Cache
from manifestoo_core.addon import Addon, is_addon_dir
from manifestoo_core.core_addons import is_core_ce_addon, is_core_ee_addon
from manifestoo_core.metadata import addon_name_to_distribution_name
from manifestoo_core.odoo_series import OdooSeries
from mousebender import simple
from packaging.metadata import parse_email
from packaging.specifiers import SpecifierSet
from packaging.utils import parse_wheel_filename
from platformdirs import user_cache_dir
from requests import get, head

NAME_DEFAULT_CATEGORY = "Default"
OCA_ADDONS_INDEX_URL = "https://wheelhouse.odoo-community.org/oca-simple/"
Expand Down Expand Up @@ -63,7 +64,7 @@ def _identify_oca_addons(addon_names: list[str], odoo_series: OdooSeries) -> tup

if not category:
distribution_name = addon_name_to_distribution_name(addon_name, odoo_series).replace("_", "-")
res = head(f"{OCA_ADDONS_INDEX_URL}{distribution_name}", timeout=REQUEST_TIMEOUT)
res = requests.head(f"{OCA_ADDONS_INDEX_URL}{distribution_name}", timeout=REQUEST_TIMEOUT)
if res:
category = get_oca_repository_name(addon_name, odoo_series) or oca_category_repo_not_found
else:
Expand All @@ -83,7 +84,7 @@ def get_oca_repository_name(addon_name: str, odoo_series: OdooSeries) -> str | N
distribution_name = addon_name_to_distribution_name(addon_name, odoo_series)
# get avaialble releases
project_url = simple.create_project_url(PYPI_SIMPLE_INDEX_URL, distribution_name)
response = get(project_url, headers={"Accept": simple.ACCEPT_JSON_V1}, timeout=REQUEST_TIMEOUT)
response = requests.get(project_url, headers={"Accept": simple.ACCEPT_JSON_V1}, timeout=REQUEST_TIMEOUT)
if response.status_code == PAGE_NOT_FOUND:
# project not found
return None
Expand All @@ -107,14 +108,14 @@ def get_oca_repository_name(addon_name: str, odoo_series: OdooSeries) -> str | N
# no release found that matches the requested Odoo version
return None

pypi_json_url = _get_pypi_url(distribution_name, version)
response = get(pypi_json_url, timeout=REQUEST_TIMEOUT)
if not file.get("data-dist-info-metadata"):
return "UNKNOWN"
metadata_url = file["url"] + ".metadata"
response = requests.get(metadata_url, timeout=REQUEST_TIMEOUT)
response.raise_for_status()
repo_url = response.json().get("info").get("home_page")
home_page = re.search("OCA/.*", parse_email(response.text)[0].get("home_page"))

if not repo_url:
return None
return search("OCA/.*", repo_url).group()
return home_page.group() if home_page else ""


def _add_oca_categories(
Expand Down Expand Up @@ -193,7 +194,7 @@ def do_sorting(addons_dir: Path, odoo_version: str, project_name: str, *, oca_ca
new_depends = _generate_depends_sections(categories)

pattern = r'"depends":\s*\[([^]]*)\]'
content = sub(pattern, new_depends, content, flags=DOTALL)
content = re.sub(pattern, new_depends, content, flags=re.DOTALL)
manifest_path.write_text(content)


Expand Down

0 comments on commit bbe3c23

Please sign in to comment.