-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy path__init__.py
More file actions
66 lines (58 loc) · 2.43 KB
/
__init__.py
File metadata and controls
66 lines (58 loc) · 2.43 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
65
66
from django.db.models.signals import post_migrate
from pulpcore.plugin import PulpPluginAppConfig
from gettext import gettext as _
class PulpPythonPluginAppConfig(PulpPluginAppConfig):
"""
Entry point for pulp_python plugin.
"""
name = "pulp_python.app"
label = "python"
version = "3.29.0.dev"
python_package_name = "pulp-python"
domain_compatible = True
def ready(self):
"""Register PyPI access policy hook."""
super().ready()
post_migrate.connect(
_populate_pypi_access_policies,
sender=self,
dispatch_uid="populate_pypi_access_policies_identifier",
)
# TODO: Remove this when https://github.com/pulp/pulpcore/issues/5500 is resolved
def _populate_pypi_access_policies(sender, apps, verbosity, **kwargs):
from pulp_python.app.pypi.views import PyPIView, SimpleView, UploadView, MetadataView
try:
AccessPolicy = apps.get_model("core", "AccessPolicy")
except LookupError:
if verbosity >= 1:
print(_("AccessPolicy model does not exist. Skipping initialization."))
return
for viewset in (PyPIView, SimpleView, UploadView, MetadataView):
access_policy = getattr(viewset, "DEFAULT_ACCESS_POLICY", None)
if access_policy is not None:
viewset_name = viewset.urlpattern()
db_access_policy, created = AccessPolicy.objects.get_or_create(
viewset_name=viewset_name, defaults=access_policy
)
if created:
if verbosity >= 1:
print(
"Access policy for {viewset_name} created.".format(
viewset_name=viewset_name
)
)
elif not db_access_policy.customized:
dirty = False
for key in ["statements", "creation_hooks", "queryset_scoping"]:
value = access_policy.get(key)
if getattr(db_access_policy, key, None) != value:
setattr(db_access_policy, key, value)
dirty = True
if dirty:
db_access_policy.save()
if verbosity >= 1:
print(
"Access policy for {viewset_name} updated.".format(
viewset_name=viewset_name
)
)