-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathyank.py
More file actions
64 lines (51 loc) · 2.15 KB
/
Copy pathyank.py
File metadata and controls
64 lines (51 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from packaging.utils import canonicalize_name
from pulpcore.plugin.exceptions import ValidationError
from pulpcore.plugin.tasking import aadd_and_remove
from pulp_python.app.models import PackageYank, PythonPackageContent, PythonRepository
async def ayank_package(repository_pk, name, version, yanked_reason=""):
"""
Yank a package version in a repository by adding a PackageYank marker.
Creates a new repository version with the yank marker added.
"""
normalized = canonicalize_name(name)
repository = await PythonRepository.objects.aget(pk=repository_pk)
latest = await repository.alatest_version()
exists = await PythonPackageContent.objects.filter(
pk__in=latest.content, name_normalized=normalized, version=version
).aexists()
if not exists:
raise ValidationError(f"Package {name}=={version} not found in repository")
existing_yank = await PackageYank.objects.filter(
pk__in=latest.content, name_normalized=normalized, version=version
).afirst()
if existing_yank and existing_yank.yanked_reason == yanked_reason:
return
yank_marker, _ = await PackageYank.objects.aget_or_create(
name_normalized=normalized,
version=version,
yanked_reason=yanked_reason,
_pulp_domain_id=repository.pulp_domain_id,
)
await aadd_and_remove(
repository_pk=repository.pk,
add_content_units=[yank_marker.pk],
remove_content_units=[],
)
async def aunyank_package(repository_pk, name, version):
"""
Unyank a package version in a repository by removing its PackageYank marker.
Creates a new repository version with the yank marker removed.
"""
normalized = canonicalize_name(name)
repository = await PythonRepository.objects.aget(pk=repository_pk)
latest = await repository.alatest_version()
yank_marker = await PackageYank.objects.filter(
pk__in=latest.content, name_normalized=normalized, version=version
).afirst()
if yank_marker is None:
return
await aadd_and_remove(
repository_pk=repository.pk,
add_content_units=[],
remove_content_units=[yank_marker.pk],
)