forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
185 lines (147 loc) · 5.22 KB
/
models.py
File metadata and controls
185 lines (147 loc) · 5.22 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
from logging import getLogger
from aiohttp.web import json_response
from django.contrib.postgres.fields import ArrayField, JSONField
from django.db import models
from pulpcore.plugin.models import (
Content,
Publication,
Distribution,
Remote,
Repository
)
from pathlib import PurePath
from .utils import python_content_to_json, PYPI_LAST_SERIAL, PYPI_SERIAL_CONSTANT
log = getLogger(__name__)
PACKAGE_TYPES = (
("bdist_dmg", "bdist_dmg"),
("bdist_dumb", "bdist_dumb"),
("bdist_egg", "bdist_egg"),
("bdist_msi", "bdist_msi"),
("bdist_rpm", "bdist_rpm"),
("bdist_wheel", "bdist_wheel"),
("bdist_wininst", "bdist_wininst"),
("sdist", "sdist"),
)
PLATFORMS = (("windows", "windows"),
("macos", "macos"),
("freebsd", "freebsd"),
("linux", "linux"))
class PythonDistribution(Distribution):
"""
Distribution for 'Python' Content.
"""
TYPE = 'python'
def content_handler(self, path):
"""
Handler to serve extra, non-Artifact content for this Distribution
Args:
path (str): The path being requested
Returns:
None if there is no content to be served at path. Otherwise a
aiohttp.web_response.Response with the content.
"""
path = PurePath(path)
name = None
version = None
if path.match("pypi/*/*/json"):
version = path.parts[2]
name = path.parts[1]
elif path.match("pypi/*/json"):
name = path.parts[1]
if name:
package_content = PythonPackageContent.objects.filter(
pk__in=self.publication.repository_version.content,
name__iexact=name
)
# TODO Change this value to the Repo's serial value when implemented
headers = {PYPI_LAST_SERIAL: str(PYPI_SERIAL_CONSTANT)}
json_body = python_content_to_json(self.base_path, package_content, version=version)
if json_body:
return json_response(json_body, headers=headers)
return None
class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
class PythonPackageContent(Content):
"""
A Content Type representing Python's Distribution Package.
As defined in pep-0426 and pep-0345.
https://www.python.org/dev/peps/pep-0491/
https://www.python.org/dev/peps/pep-0345/
"""
TYPE = 'python'
# Required metadata
filename = models.TextField(unique=True, db_index=True)
packagetype = models.TextField(choices=PACKAGE_TYPES)
name = models.TextField()
version = models.TextField()
# Optional metadata
python_version = models.TextField()
metadata_version = models.TextField()
summary = models.TextField()
description = models.TextField()
keywords = models.TextField()
home_page = models.TextField()
download_url = models.TextField()
author = models.TextField()
author_email = models.TextField()
maintainer = models.TextField()
maintainer_email = models.TextField()
license = models.TextField()
requires_python = models.TextField()
project_url = models.TextField()
platform = models.TextField()
supported_platform = models.TextField()
requires_dist = JSONField(default=list)
provides_dist = JSONField(default=list)
obsoletes_dist = JSONField(default=list)
requires_external = JSONField(default=list)
classifiers = JSONField(default=list)
def __str__(self):
"""
Provide more useful repr information.
Overrides Content.str to provide the distribution version and type at
the end.
e.g. <PythonPackageContent: shelf-reader [version] (whl)>
"""
return '<{obj_name}: {name} [{version}] ({type})>'.format(
obj_name=self._meta.object_name,
name=self.name,
version=self.version,
type=self.packagetype
)
class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ('filename',)
class PythonPublication(Publication):
"""
A Publication for PythonContent.
"""
TYPE = 'python'
class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
class PythonRemote(Remote):
"""
A Remote for Python Content.
Fields:
prereleases (models.BooleanField): Whether to sync pre-release versions of packages.
"""
TYPE = 'python'
prereleases = models.BooleanField(default=False)
includes = JSONField(default=list)
excludes = JSONField(default=list)
package_types = ArrayField(models.CharField(max_length=15, blank=True),
choices=PACKAGE_TYPES, default=list)
keep_latest_packages = models.IntegerField(default=0)
exclude_platforms = ArrayField(models.CharField(max_length=10, blank=True),
choices=PLATFORMS, default=list)
class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
class PythonRepository(Repository):
"""
Repository for "python" content.
"""
TYPE = "python"
CONTENT_TYPES = [PythonPackageContent]
REMOTE_TYPES = [PythonRemote]
class Meta:
default_related_name = "%(app_label)s_%(model_name)s"