Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object wrappers for OBS XML #1349

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions behave/features/setdevelproject-pkgcheckout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Scenario: Run `osc setdevelproject <devel_project>`
And stdout is
"""
Setting devel project of package 'test:factory/test-pkgA' to package 'test:devel/test-pkgA'
Sending meta data...
Done.
"""


Expand All @@ -27,8 +25,6 @@ Scenario: Run `osc setdevelproject <devel_project> <devel_package>`
And stdout is
"""
Setting devel project of package 'test:factory/test-pkgA' to package 'test:devel/test-pkgA'
Sending meta data...
Done.
"""


Expand All @@ -39,8 +35,6 @@ Scenario: Run `osc setdevelproject <devel_project>/<devel_package>`
And stdout is
"""
Setting devel project of package 'test:factory/test-pkgA' to package 'test:devel/test-pkgA'
Sending meta data...
Done.
"""


Expand All @@ -52,6 +46,4 @@ Scenario: Run `osc setdevelproject --unset`
And stdout is
"""
Unsetting devel project from package 'test:factory/test-pkgA'
Sending meta data...
Done.
"""
8 changes: 0 additions & 8 deletions behave/features/setdevelproject-project-package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Scenario: Run `osc setdevelproject <project> <package> <devel_project>`
And stdout is
"""
Setting devel project of package 'test:factory/test-pkgA' to package 'test:devel/test-pkgA'
Sending meta data...
Done.
"""


Expand All @@ -25,8 +23,6 @@ Scenario: Run `osc setdevelproject <project> <package> <devel_project> <devel_pa
And stdout is
"""
Setting devel project of package 'test:factory/test-pkgB' to package 'test:devel/test-pkgA'
Sending meta data...
Done.
"""


Expand All @@ -37,8 +33,6 @@ Scenario: Run `osc setdevelproject <project>/<package> <devel_project>/<devel_p
And stdout is
"""
Setting devel project of package 'test:factory/test-pkgB' to package 'test:devel/test-pkgA'
Sending meta data...
Done.
"""


Expand All @@ -49,6 +43,4 @@ Scenario: Run `osc setdevelproject <project> <package> --unset`
And stdout is
"""
Unsetting devel project from package 'test:factory/test-pkgA'
Sending meta data...
Done.
"""
45 changes: 21 additions & 24 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3864,15 +3864,20 @@


def show_devel_project(apiurl, prj, pac):
m = show_package_meta(apiurl, prj, pac)
node = ET.fromstring(b''.join(m)).find('devel')
if node is None:
from . import obs_api

Check warning on line 3867 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3867

Added line #L3867 was not covered by tests

package_obj = obs_api.Package.from_api(apiurl, prj, pac)
if package_obj.devel is None:

Check warning on line 3870 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3869-L3870

Added lines #L3869 - L3870 were not covered by tests
return None, None
else:
return node.get('project'), node.get('package', None)

# mute a false-positive: Instance of 'dict' has no 'project' member (no-member)
# pylint: disable=no-member
return package_obj.devel.project, package_obj.devel.package

Check warning on line 3875 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3875

Added line #L3875 was not covered by tests


def set_devel_project(apiurl, prj, pac, devprj=None, devpac=None, print_to="debug"):
from . import obs_api

Check warning on line 3879 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3879

Added line #L3879 was not covered by tests

if devprj:
msg = "Setting devel project of"
else:
Expand All @@ -3887,26 +3892,18 @@
)
_private.print_msg(msg, print_to=print_to)

meta = show_package_meta(apiurl, prj, pac)
root = ET.fromstring(b''.join(meta))
node = root.find('devel')
if node is None:
if devprj is None:
return
node = ET.Element('devel')
root.append(node)
package_obj = obs_api.Package.from_api(apiurl, prj, pac)

Check warning on line 3895 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3895

Added line #L3895 was not covered by tests

if devprj is None:
package_obj.devel = None

Check warning on line 3898 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3897-L3898

Added lines #L3897 - L3898 were not covered by tests
else:
if devprj is None:
root.remove(node)
else:
node.clear()
if devprj:
node.set('project', devprj)
if devpac:
node.set('package', devpac)
url = makeurl(apiurl, ['source', prj, pac, '_meta'])
mf = metafile(url, ET.tostring(root, encoding=ET_ENCODING))
mf.sync()
package_obj.devel = {"project": devprj, "package": devpac}

Check warning on line 3900 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3900

Added line #L3900 was not covered by tests

if package_obj.has_changed():
return package_obj.to_api(apiurl)

Check warning on line 3903 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3902-L3903

Added lines #L3902 - L3903 were not covered by tests

# TODO: debug log that we have skipped the API call
return None

Check warning on line 3906 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3906

Added line #L3906 was not covered by tests


def show_package_disabled_repos(apiurl: str, prj: str, pac: str):
Expand Down
2 changes: 2 additions & 0 deletions osc/obs_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .package import Package
from .project import Project

Check warning on line 2 in osc/obs_api/__init__.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/__init__.py#L1-L2

Added lines #L1 - L2 were not covered by tests
79 changes: 79 additions & 0 deletions osc/obs_api/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import

Check warning on line 1 in osc/obs_api/enums.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/enums.py#L1

Added line #L1 was not covered by tests


class BlockModes(str, Enum):
ALL = "all"
LOCAL = "local"
NEVER = "never"

Check warning on line 7 in osc/obs_api/enums.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/enums.py#L4-L7

Added lines #L4 - L7 were not covered by tests


class BuildArch(str, Enum):
NOARCH = "noarch"
AARCH64 = "aarch64"
AARCH64_ILP32 = "aarch64_ilp32"
ARMV4L = "armv4l"
ARMV5L = "armv5l"
ARMV6L = "armv6l"
ARMV7L = "armv7l"
ARMV5EL = "armv5el"
ARMV6EL = "armv6el"
ARMV7EL = "armv7el"
ARMV7HL = "armv7hl"
ARMV8EL = "armv8el"
HPPA = "hppa"
M68K = "m68k"
I386 = "i386"
I486 = "i486"
I586 = "i586"
I686 = "i686"
ATHLON = "athlon"
IA64 = "ia64"
K1OM = "k1om"
MIPS = "mips"
MIPSEL = "mipsel"
MIPS32 = "mips32"
MIPS64 = "mips64"
MIPS64EL = "mips64el"
PPC = "ppc"
PPC64 = "ppc64"
PPC64P7 = "ppc64p7"
PPC64LE = "ppc64le"
RISCV64 = "riscv64"
S390 = "s390"
S390X = "s390x"
SH4 = "sh4"
SPARC = "sparc"
SPARC64 = "sparc64"
SPARC64V = "sparc64v"
SPARCV8 = "sparcv8"
SPARCV9 = "sparcv9"
SPARCV9V = "sparcv9v"
X86_64 = "x86_64"
LOCAL = "local"

Check warning on line 52 in osc/obs_api/enums.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/enums.py#L10-L52

Added lines #L10 - L52 were not covered by tests


class LinkedbuildModes(str, Enum):
OFF = "off"
LOCALDEP = "localdep"
ALLDIRECT = "alldirect"
ALL = "all"

Check warning on line 59 in osc/obs_api/enums.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/enums.py#L55-L59

Added lines #L55 - L59 were not covered by tests


class LocalRole(str, Enum):
MAINTAINER = "maintainer"
BUGOWNER = "bugowner"
REVIEWER = "reviewer"
DOWNLOADER = "downloader"
READER = "reader"

Check warning on line 67 in osc/obs_api/enums.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/enums.py#L62-L67

Added lines #L62 - L67 were not covered by tests


class RebuildModes(str, Enum):
TRANSITIVE = "transitive"
DIRECT = "direct"
LOCAL = "local"

Check warning on line 73 in osc/obs_api/enums.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/enums.py#L70-L73

Added lines #L70 - L73 were not covered by tests


class ReleaseTriggers(str, Enum):
MANUAL = "manual"
MAINTENANCE = "maintenance"
OBSGENDIFF = "obsgendiff"

Check warning on line 79 in osc/obs_api/enums.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/enums.py#L76-L79

Added lines #L76 - L79 were not covered by tests
24 changes: 24 additions & 0 deletions osc/obs_api/flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import

Check warning on line 1 in osc/obs_api/flag.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/flag.py#L1

Added line #L1 was not covered by tests


class Flag(XmlModel):
XML_TAG = None

Check warning on line 5 in osc/obs_api/flag.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/flag.py#L4-L5

Added lines #L4 - L5 were not covered by tests

def __init__(self, flag, **kwargs):
super().__init__(flag=flag, **kwargs)

Check warning on line 8 in osc/obs_api/flag.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/flag.py#L7-L8

Added lines #L7 - L8 were not covered by tests

class FlagChoices(Enum):
ENABLE = "enable"
DISABLE = "disable"

Check warning on line 12 in osc/obs_api/flag.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/flag.py#L10-L12

Added lines #L10 - L12 were not covered by tests

flag: FlagChoices = Field(

Check warning on line 14 in osc/obs_api/flag.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/flag.py#L14

Added line #L14 was not covered by tests
xml_set_tag=True,
)

arch: Optional[str] = Field(

Check warning on line 18 in osc/obs_api/flag.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/flag.py#L18

Added line #L18 was not covered by tests
xml_attribute=True,
)

repository: Optional[str] = Field(

Check warning on line 22 in osc/obs_api/flag.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/flag.py#L22

Added line #L22 was not covered by tests
xml_attribute=True,
)
15 changes: 15 additions & 0 deletions osc/obs_api/group_role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import

Check warning on line 1 in osc/obs_api/group_role.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/group_role.py#L1

Added line #L1 was not covered by tests

from .enums import LocalRole

Check warning on line 3 in osc/obs_api/group_role.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/group_role.py#L3

Added line #L3 was not covered by tests


class GroupRole(XmlModel):
XML_TAG = "group"

Check warning on line 7 in osc/obs_api/group_role.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/group_role.py#L6-L7

Added lines #L6 - L7 were not covered by tests

groupid: str = Field(

Check warning on line 9 in osc/obs_api/group_role.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/group_role.py#L9

Added line #L9 was not covered by tests
xml_attribute=True,
)

role: LocalRole = Field(

Check warning on line 13 in osc/obs_api/group_role.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/group_role.py#L13

Added line #L13 was not covered by tests
xml_attribute=True,
)
127 changes: 127 additions & 0 deletions osc/obs_api/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import

Check warning on line 1 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L1

Added line #L1 was not covered by tests

from .flag import Flag
from .group_role import GroupRole
from .package_devel import PackageDevel
from .person_role import PersonRole
from .simple_flag import SimpleFlag
from .status import Status

Check warning on line 8 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L3-L8

Added lines #L3 - L8 were not covered by tests


class Package(XmlModel):
XML_TAG = "package"

Check warning on line 12 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L11-L12

Added lines #L11 - L12 were not covered by tests

name: str = Field(

Check warning on line 14 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L14

Added line #L14 was not covered by tests
xml_attribute=True,
)

project: str = Field(

Check warning on line 18 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L18

Added line #L18 was not covered by tests
xml_attribute=True,
)

title: str = Field()

Check warning on line 22 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L22

Added line #L22 was not covered by tests

description: str = Field()

Check warning on line 24 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L24

Added line #L24 was not covered by tests

devel: Optional[PackageDevel] = Field()

Check warning on line 26 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L26

Added line #L26 was not covered by tests

releasename: Optional[str] = Field()

Check warning on line 28 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L28

Added line #L28 was not covered by tests

person_list: Optional[List[PersonRole]] = Field(

Check warning on line 30 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L30

Added line #L30 was not covered by tests
xml_name="person",
)

group_list: Optional[List[GroupRole]] = Field(

Check warning on line 34 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L34

Added line #L34 was not covered by tests
xml_name="group",
)

lock: Optional[SimpleFlag] = Field()

Check warning on line 38 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L38

Added line #L38 was not covered by tests

build_list: Optional[List[Flag]] = Field(

Check warning on line 40 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L40

Added line #L40 was not covered by tests
xml_name="build",
xml_wrapped=True,
)

publish_list: Optional[List[Flag]] = Field(

Check warning on line 45 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L45

Added line #L45 was not covered by tests
xml_name="publish",
xml_wrapped=True,
)

useforbuild_list: Optional[List[Flag]] = Field(

Check warning on line 50 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L50

Added line #L50 was not covered by tests
xml_name="useforbuild",
xml_wrapped=True,
)

debuginfo_list: Optional[List[Flag]] = Field(

Check warning on line 55 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L55

Added line #L55 was not covered by tests
xml_name="debuginfo",
xml_wrapped=True,
)

binarydownload: Optional[SimpleFlag] = Field()

Check warning on line 60 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L60

Added line #L60 was not covered by tests

sourceaccess: Optional[SimpleFlag] = Field()

Check warning on line 62 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L62

Added line #L62 was not covered by tests

url: Optional[str] = Field()

Check warning on line 64 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L64

Added line #L64 was not covered by tests

scmsync: Optional[str] = Field()

Check warning on line 66 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L66

Added line #L66 was not covered by tests

bcntsynctag: Optional[str] = Field()

Check warning on line 68 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L68

Added line #L68 was not covered by tests

@classmethod
def from_api(cls, apiurl, project, package, *, rev=None):
url_path = ["source", project, package, "_meta"]
url_query = {

Check warning on line 73 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L70-L73

Added lines #L70 - L73 were not covered by tests
"rev": rev,
}
response = cls.xml_request("GET", apiurl, url_path, url_query)
return cls.from_file(response)

Check warning on line 77 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L76-L77

Added lines #L76 - L77 were not covered by tests

def to_api(self, apiurl, *, project=None, package=None):
project = project or self.project
package = package or self.name
url_path = ["source", project, package, "_meta"]
url_query = {}
response = self.xml_request("PUT", apiurl, url_path, url_query, data=self.to_string())
return Status.from_file(response)

Check warning on line 85 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L79-L85

Added lines #L79 - L85 were not covered by tests

@classmethod
def cmd_release(

Check warning on line 88 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L87-L88

Added lines #L87 - L88 were not covered by tests
cls,
apiurl: str,
project: str,
package: str,
*,
repository: Optional[str] = None,
arch: Optional[str] = None,
target_project: Optional[str] = None,
target_repository: Optional[str] = None,
setrelease: Optional[str] = None,
nodelay: Optional[bool] = None,
):
"""
POST /source/{project}/{package}?cmd=release
Release sources and binaries of a specified package.

:param apiurl: Full apiurl or its alias.
:param project: Project name.
:param package: Package name.
:param repository: Limit the release to the given repository.
:param arch: Limit the release to the given architecture.
:param target_project: The name of the release target project.
:param target_repository: The name of the release target repository.
:param setrelease: Tag the release with the given value.
:param nodelay: Do not delay the relase. If not set, the release will be delayed to be done later.
"""

url_path = ["source", project, package]
url_query = {

Check warning on line 117 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L116-L117

Added lines #L116 - L117 were not covered by tests
"cmd": "release",
"repository": repository,
"arch": arch,
"target_project": target_project,
"target_repository": target_repository,
"setrelease": setrelease,
"nodelay": nodelay,
}
response = cls.xml_request("POST", apiurl, url_path, url_query)
return Status.from_string(response.read())

Check warning on line 127 in osc/obs_api/package.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package.py#L126-L127

Added lines #L126 - L127 were not covered by tests
13 changes: 13 additions & 0 deletions osc/obs_api/package_devel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import

Check warning on line 1 in osc/obs_api/package_devel.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package_devel.py#L1

Added line #L1 was not covered by tests


class PackageDevel(XmlModel):
XML_TAG = "devel"

Check warning on line 5 in osc/obs_api/package_devel.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package_devel.py#L4-L5

Added lines #L4 - L5 were not covered by tests

project: str = Field(

Check warning on line 7 in osc/obs_api/package_devel.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package_devel.py#L7

Added line #L7 was not covered by tests
xml_attribute=True,
)

package: Optional[str] = Field(

Check warning on line 11 in osc/obs_api/package_devel.py

View check run for this annotation

Codecov / codecov/patch

osc/obs_api/package_devel.py#L11

Added line #L11 was not covered by tests
xml_attribute=True,
)
Loading
Loading