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
184 lines (138 loc) · 5.04 KB
/
models.py
File metadata and controls
184 lines (138 loc) · 5.04 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
from logging import getLogger
from django.db import models
from pulpcore.plugin.models import Content, Model, Publication, PublicationDistribution, Remote
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"),
)
class Classifier(Model):
"""
Custom tags for classifier.
Fields:
name (models.TextField): The name of the classifier
Relations:
python_package_content (models.ForeignKey):
The PythonPackageContent this classifier is associated with.
"""
name = models.TextField()
python_package_content = models.ForeignKey(
"PythonPackageContent",
related_name="classifiers",
related_query_name="classifier",
on_delete=models.CASCADE
)
class ProjectSpecifier(Model):
"""
A specifier of a python project.
Example:
digests: ["sha256:0000"] will only match the distributions that has the exact hash
name: "projectname" without specifiers will match every distribution in the project.
version_specifier: "==1.0.0" will match all distributions matching version
version_specifier: "~=1.0.0" will match all major version 1 distributions
version_specifier: "==1.0.0" digests: ["sha256:0000"] will only match the distributions
with the hash and with version 1.0.0
version_specifier: ">=0.9,<1.0" will match all versions matching 0.9.*
Fields:
name (models.TextField): The name of a python project
version_specifier (models.TextField): Used to filter the versions of a project to sync
exclude (models.BooleanField): Whether the specified projects should excluded or included
Relations:
remote (models.ForeignKey): The remote this project specifier is associated with
include (models.BooleanField): Used to blacklist/whitelist projects to sync
"""
name = models.TextField()
version_specifier = models.TextField(default="")
exclude = models.BooleanField(default=False)
remote = models.ForeignKey(
"PythonRemote",
related_name="projects",
related_query_name="projectspecifier",
on_delete=models.CASCADE
)
class Meta:
unique_together = ('name', 'version_specifier', 'exclude', 'remote')
class PythonDistribution(PublicationDistribution):
"""
Distribution for 'Python' Content.
"""
TYPE = 'python'
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
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 = models.TextField(default="[]")
provides_dist = models.TextField(default="[]")
obsoletes_dist = models.TextField(default="[]")
requires_external = models.TextField(default="[]")
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:
unique_together = ('filename',)
class PythonPublication(Publication):
"""
A Publication for PythonContent.
"""
TYPE = 'python'
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)
@property
def includes(self):
"""
Specify include list.
"""
return ProjectSpecifier.objects.filter(remote=self, exclude=False)
@property
def excludes(self):
"""
Specify exclude list.
"""
return ProjectSpecifier.objects.filter(remote=self, exclude=True)