1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-29 11:16:14 +01:00

Add obs_api.PackageSources class for handling OBS SCM sources

This commit is contained in:
Daniel Mach 2024-02-29 09:54:23 +01:00
parent 772509c023
commit e5370b9c0b
5 changed files with 159 additions and 0 deletions

View File

@ -1,2 +1,3 @@
from .package import Package
from .package_sources import PackageSources
from .project import Project

41
osc/obs_api/linkinfo.py Normal file
View File

@ -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,
)

View File

@ -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)

View File

@ -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)

View File

@ -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,
)