forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserializers.py
More file actions
191 lines (169 loc) · 7.03 KB
/
Copy pathserializers.py
File metadata and controls
191 lines (169 loc) · 7.03 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from gettext import gettext as _
from rest_framework import serializers
from pulpcore.plugin import serializers as platform
from . import models
class ClassifierSerializer(serializers.ModelSerializer):
"""
A serializer for Python Classifiers
"""
name = serializers.CharField(
help_text=_("A string giving a single classification value for a Python package.")
)
class Meta:
model = models.Classifier
fields = ('name',)
class PythonPackageContentSerializer(platform.ContentSerializer):
"""
A Serializer for PythonPackageContent.
"""
filename = serializers.CharField(
help_text=_('The name of the distribution package, usually of the format:'
' {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}'
'-{platform tag}.{packagetype}')
)
packagetype = serializers.CharField(
help_text=_('The type of the distribution package '
'(e.g. sdist, bdist_wheel, bdist_egg, etc)')
)
name = serializers.CharField(
help_text=_('The name of the python project.')
)
version = serializers.CharField(
help_text=_('The packages version number.')
)
metadata_version = serializers.CharField(
help_text=_('Version of the file format')
)
summary = serializers.CharField(
required=False, allow_blank=True,
help_text=_('A one-line summary of what the package does.')
)
description = serializers.CharField(
required=False, allow_blank=True,
help_text=_('A longer description of the package that can run to several paragraphs.')
)
keywords = serializers.ListField(
child=serializers.CharField(),
required=False, default=[],
help_text=_('A list of additional keywords to be used to assist searching for the '
'package in a larger catalog.')
)
home_page = serializers.CharField(
required=False, allow_blank=True,
help_text=_('The URL for the package\'s home page.')
)
download_url = serializers.CharField(
required=False, allow_blank=True,
help_text=_('Legacy field denoting the URL from which this package can be downloaded.')
)
author = serializers.CharField(
required=False, allow_blank=True,
help_text=_('Text containing the author\'s name. Contact information can also be added,'
' separated with newlines.')
)
author_email = serializers.CharField(
required=False, allow_blank=True,
help_text=_('The author\'s e-mail address. ')
)
maintainer = serializers.CharField(
required=False, allow_blank=True,
help_text=_('The maintainer\'s name at a minimum; '
'additional contact information may be provided.')
)
maintainer_email = serializers.CharField(
required=False, allow_blank=True,
help_text=_('The maintainer\'s e-mail address.')
)
license = serializers.CharField(
required=False, allow_blank=True,
help_text=_('Text indicating the license covering the distribution')
)
requires_python = serializers.CharField(
required=False, allow_blank=True,
help_text=_('The Python version(s) that the distribution is guaranteed to be '
'compatible with.')
)
project_url = serializers.CharField(
required=False, allow_blank=True,
help_text=_('A browsable URL for the project and a label for it, separated by a comma.')
)
platform = serializers.CharField(
required=False, allow_blank=True,
help_text=_('A comma-separated list of platform specifications, '
'summarizing the operating systems supported by the package.')
)
supported_platform = serializers.CharField(
required=False, allow_blank=True,
help_text=_('Field to specify the OS and CPU for which the binary package was compiled. ')
)
requires_dist = serializers.CharField(
required=False, default="[]",
help_text=_('A JSON list containing names of some other distutils project '
'required by this distribution.')
)
provides_dist = serializers.CharField(
required=False, default="[]",
help_text=_('A JSON list containing names of a Distutils project which is contained'
' within this distribution.')
)
obsoletes_dist = serializers.CharField(
required=False, default="[]",
help_text=_('A JSON list containing names of a distutils project\'s distribution which '
'this distribution renders obsolete, meaning that the two projects should not '
'be installed at the same time.')
)
requires_external = serializers.CharField(
required=False, default="[]",
help_text=_('A JSON list containing some dependency in the system that the distribution '
'is to be used.')
)
classifiers = ClassifierSerializer(
required=False,
many=True
)
def create(self, validated_data):
"""
Creates a PythonPackageContent
Overriding default create() to write the classifiers nested field
:param validated_data:
:return:
"""
classifiers = validated_data.pop('classifiers')
PythonPackageContent = models.PythonPackageContent.objects.create(**validated_data)
for classifier in classifiers:
models.Classifier.objects.create(python_package_content=PythonPackageContent,
**classifier)
return PythonPackageContent
class Meta:
fields = platform.ContentSerializer.Meta.fields + (
'filename', 'packagetype', 'name', 'version', 'metadata_version', 'summary',
'description', 'keywords', 'home_page', 'download_url', 'author', 'author_email',
'maintainer', 'maintainer_email', 'license', 'requires_python', 'project_url',
'platform', 'supported_platform', 'requires_dist', 'provides_dist',
'obsoletes_dist', 'requires_external', 'classifiers'
)
model = models.PythonPackageContent
class PythonImporterSerializer(platform.ImporterSerializer):
"""
A Serializer for PythonImporter.
"""
projects = serializers.CharField(
required=True,
help_text=_('A JSON list of project names to sync.')
)
class Meta:
fields = platform.ImporterSerializer.Meta.fields + ('projects',)
model = models.PythonImporter
class PythonPublisherSerializer(platform.PublisherSerializer):
"""
A Serializer for PythonPublisher.
Add any new fields if defined on PythonPublisher.
Similar to the example above, in PythonContentSerializer.
Additional validators can be added to the parent validators list
For example::
class Meta:
validators = platform.PublisherSerializer.Meta.validators + [myValidator1, myValidator2]
"""
class Meta:
fields = platform.PublisherSerializer.Meta.fields
model = models.PythonPublisher