From 149c7f799f4f61f0bac27a74f8204f59d1601e61 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 5 Mar 2024 14:25:54 +0100 Subject: [PATCH] Add obs_api.Person class --- osc/obs_api/__init__.py | 1 + osc/obs_api/enums.py | 5 ++ osc/obs_api/person.py | 71 +++++++++++++++++++++++++ osc/obs_api/person_owner.py | 9 ++++ osc/obs_api/person_watchlist.py | 20 +++++++ osc/obs_api/person_watchlist_package.py | 13 +++++ osc/obs_api/person_watchlist_project.py | 9 ++++ osc/obs_api/person_watchlist_request.py | 9 ++++ 8 files changed, 137 insertions(+) create mode 100644 osc/obs_api/person.py create mode 100644 osc/obs_api/person_owner.py create mode 100644 osc/obs_api/person_watchlist.py create mode 100644 osc/obs_api/person_watchlist_package.py create mode 100644 osc/obs_api/person_watchlist_project.py create mode 100644 osc/obs_api/person_watchlist_request.py diff --git a/osc/obs_api/__init__.py b/osc/obs_api/__init__.py index 7bc9a365..37c7a52b 100644 --- a/osc/obs_api/__init__.py +++ b/osc/obs_api/__init__.py @@ -1,4 +1,5 @@ from .package import Package from .package_sources import PackageSources +from .person import Person from .project import Project from .request import Request diff --git a/osc/obs_api/enums.py b/osc/obs_api/enums.py index f7c55be7..3fc8de30 100644 --- a/osc/obs_api/enums.py +++ b/osc/obs_api/enums.py @@ -7,6 +7,11 @@ class BlockModes(str, Enum): NEVER = "never" +class BoolString(str, Enum): + TRUE = "true" + FALSE = "false" + + class BuildArch(str, Enum): NOARCH = "noarch" AARCH64 = "aarch64" diff --git a/osc/obs_api/person.py b/osc/obs_api/person.py new file mode 100644 index 00000000..54925d20 --- /dev/null +++ b/osc/obs_api/person.py @@ -0,0 +1,71 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import +from .enums import BoolString +from .person_owner import PersonOwner +from .person_watchlist import PersonWatchlist + + +class Person(XmlModel): + XML_TAG = "person" + + login: str = Field( + ) + + email: Optional[str] = Field( + ) + + realname: Optional[str] = Field( + ) + + owner: Optional[PersonOwner] = Field( + ) + + state: Optional[str] = Field( + ) + + globalrole_list: Optional[List[str]] = Field( + xml_name="globalrole", + ) + + watchlist: Optional[PersonWatchlist] = Field( + ) + + ignore_auth_services: Optional[BoolString] = Field( + ) + + @classmethod + def from_api(cls, apiurl: str, username: str): + url_path = ["person", username] + url_query = {} + response = cls.xml_request("GET", apiurl, url_path, url_query) + return cls.from_file(response, apiurl=apiurl) + + @classmethod + def search( + cls, + apiurl: str, + login: Optional[str] = None, + email: Optional[str] = None, + realname: Optional[str] = None, + state: Optional[str] = None, + **kwargs, + ) -> List["Person"]: + from xml.etree import ElementTree as ET + from ..util.xpath import XPathQuery as Q + + url_path = ["search", "person"] + url_query = { + "match": Q( + login=login, + email=email, + realname=realname, + state=state, + **kwargs, + ), + } + response = cls.xml_request("GET", apiurl, url_path, url_query) + root = ET.parse(response).getroot() + assert root.tag == "collection" + result = [] + for node in root: + result.append(cls.from_xml(node, apiurl=apiurl)) + return result diff --git a/osc/obs_api/person_owner.py b/osc/obs_api/person_owner.py new file mode 100644 index 00000000..d799baa1 --- /dev/null +++ b/osc/obs_api/person_owner.py @@ -0,0 +1,9 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import + + +class PersonOwner(XmlModel): + XML_TAG = "owner" + + userid: str = Field( + xml_attribute=True, + ) diff --git a/osc/obs_api/person_watchlist.py b/osc/obs_api/person_watchlist.py new file mode 100644 index 00000000..defdf39f --- /dev/null +++ b/osc/obs_api/person_watchlist.py @@ -0,0 +1,20 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import +from .person_watchlist_package import PersonWatchlistPackage +from .person_watchlist_project import PersonWatchlistProject +from .person_watchlist_request import PersonWatchlistRequest + + +class PersonWatchlist(XmlModel): + XML_TAG = "watchlist" + + project_list: Optional[List[PersonWatchlistProject]] = Field( + xml_name="project", + ) + + package_list: Optional[List[PersonWatchlistPackage]] = Field( + xml_name="package", + ) + + request_list: Optional[List[PersonWatchlistRequest]] = Field( + xml_name="request", + ) diff --git a/osc/obs_api/person_watchlist_package.py b/osc/obs_api/person_watchlist_package.py new file mode 100644 index 00000000..cb591b18 --- /dev/null +++ b/osc/obs_api/person_watchlist_package.py @@ -0,0 +1,13 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import + + +class PersonWatchlistPackage(XmlModel): + XML_TAG = "package" + + name: str = Field( + xml_attribute=True, + ) + + project: str = Field( + xml_attribute=True, + ) diff --git a/osc/obs_api/person_watchlist_project.py b/osc/obs_api/person_watchlist_project.py new file mode 100644 index 00000000..3943eede --- /dev/null +++ b/osc/obs_api/person_watchlist_project.py @@ -0,0 +1,9 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import + + +class PersonWatchlistProject(XmlModel): + XML_TAG = "project" + + name: str = Field( + xml_attribute=True, + ) diff --git a/osc/obs_api/person_watchlist_request.py b/osc/obs_api/person_watchlist_request.py new file mode 100644 index 00000000..2b14132e --- /dev/null +++ b/osc/obs_api/person_watchlist_request.py @@ -0,0 +1,9 @@ +from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import + + +class PersonWatchlistRequest(XmlModel): + XML_TAG = "request" + + number: str = Field( + xml_attribute=True, + )