From e5370b9c0b58ff3eba7326d694f210cfa12bbd08 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Thu, 29 Feb 2024 09:54:23 +0100 Subject: [PATCH] Add obs_api.PackageSources class for handling OBS SCM sources --- osc/obs_api/__init__.py | 1 + osc/obs_api/linkinfo.py | 41 +++++++++++++++++ osc/obs_api/package_sources.py | 68 +++++++++++++++++++++++++++++ osc/obs_api/package_sources_file.py | 28 ++++++++++++ osc/obs_api/serviceinfo.py | 21 +++++++++ 5 files changed, 159 insertions(+) create mode 100644 osc/obs_api/linkinfo.py create mode 100644 osc/obs_api/package_sources.py create mode 100644 osc/obs_api/package_sources_file.py create mode 100644 osc/obs_api/serviceinfo.py diff --git a/osc/obs_api/__init__.py b/osc/obs_api/__init__.py index 7216b78b..7746e24b 100644 --- a/osc/obs_api/__init__.py +++ b/osc/obs_api/__init__.py @@ -1,2 +1,3 @@ from .package import Package +from .package_sources import PackageSources from .project import Project diff --git a/osc/obs_api/linkinfo.py b/osc/obs_api/linkinfo.py new file mode 100644 index 00000000..64253732 --- /dev/null +++ b/osc/obs_api/linkinfo.py @@ -0,0 +1,41 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import + + +class Linkinfo(XmlModel): + XML_TAG = "linkinfo" + + project: str = Field( + xml_attribute=True, + ) + + package: str = Field( + xml_attribute=True, + ) + + lsrcmd5: Optional[str] = Field( + xml_attribute=True, + ) + + xsrcmd5: Optional[str] = Field( + xml_attribute=True, + ) + + baserev: Optional[str] = Field( + xml_attribute=True, + ) + + rev: Optional[str] = Field( + xml_attribute=True, + ) + + srcmd5: Optional[str] = Field( + xml_attribute=True, + ) + + error: Optional[str] = Field( + xml_attribute=True, + ) + + missingok: Optional[bool] = Field( + xml_attribute=True, + ) diff --git a/osc/obs_api/package_sources.py b/osc/obs_api/package_sources.py new file mode 100644 index 00000000..51c74f2f --- /dev/null +++ b/osc/obs_api/package_sources.py @@ -0,0 +1,68 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import +from .linkinfo import Linkinfo +from .package_sources_file import PackageSourcesFile +from .serviceinfo import Serviceinfo + + +class PackageSources(XmlModel): + XML_TAG = "directory" + + name: str = Field( + xml_attribute=True, + ) + + rev: str = Field( + xml_attribute=True, + ) + + vrev: Optional[str] = Field( + xml_attribute=True, + ) + + srcmd5: str = Field( + xml_attribute=True, + ) + + linkinfo: Optional[Linkinfo] = Field( + ) + + serviceinfo: Optional[Serviceinfo] = Field( + ) + + file_list: Optional[List[PackageSourcesFile]] = Field( + xml_name="entry", + ) + + @classmethod + def from_api( + cls, + apiurl: str, + project: str, + package: str, + *, + deleted: Optional[bool] = None, + expand: Optional[bool] = None, + meta: Optional[bool] = None, + rev: Optional[str] = None, + ): + """ + :param deleted: Set to ``True`` to list source files of a deleted package. + Throws 400: Bad Request if such package exists. + :param expand: Expand links. + :param meta: Set to ``True`` to list metadata file (``_meta``) instead of the sources. + :param rev: Show sources of the specified revision. + """ + from ..core import revision_is_empty + + if revision_is_empty(rev): + rev = None + + url_path = ["source", project, package] + url_query = { + "deleted": deleted, + "expand": expand, + "meta": meta, + "rev": rev, + } + response = cls.xml_request("GET", apiurl, url_path, url_query) + return cls.from_file(response, apiurl=apiurl) diff --git a/osc/obs_api/package_sources_file.py b/osc/obs_api/package_sources_file.py new file mode 100644 index 00000000..add82edd --- /dev/null +++ b/osc/obs_api/package_sources_file.py @@ -0,0 +1,28 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import + + +class PackageSourcesFile(XmlModel): + XML_TAG = "entry" + + name: str = Field( + xml_attribute=True, + ) + + md5: str = Field( + xml_attribute=True, + ) + + mtime: int = Field( + xml_attribute=True, + ) + + size: int = Field( + xml_attribute=True, + ) + + skipped: Optional[bool] = Field( + xml_attribute=True, + ) + + def _get_cmp_data(self): + return (self.name, self.mtime, self.size, self.md5, self.skipped or False) diff --git a/osc/obs_api/serviceinfo.py b/osc/obs_api/serviceinfo.py new file mode 100644 index 00000000..70ab1a92 --- /dev/null +++ b/osc/obs_api/serviceinfo.py @@ -0,0 +1,21 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import + + +class Serviceinfo(XmlModel): + XML_TAG = "serviceinfo" + + xsrcmd5: Optional[str] = Field( + xml_attribute=True, + ) + + lsrcmd5: Optional[str] = Field( + xml_attribute=True, + ) + + error: Optional[str] = Field( + xml_attribute=True, + ) + + code: Optional[str] = Field( + xml_attribute=True, + )