Skip to content

Commit 2435811

Browse files
authored
Restore models used by kaggle_api.py (#673)
These objects are used by `kaggle_api.py` but not the CLI. They will be removed in the GA release (unless we decide to continue supporting `kaggle_api.py`). I just copied them from an old version of the repo.
1 parent 9a8e456 commit 2435811

18 files changed

+6094
-0
lines changed

kaggle/models/dataset_new_request.py

Lines changed: 385 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,385 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2024 Kaggle Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# coding: utf-8
18+
19+
import pprint
20+
import re # noqa: F401
21+
22+
import six
23+
24+
from kaggle.models.upload_file import UploadFile # noqa: F401,E501
25+
26+
27+
class DatasetNewRequest(object):
28+
"""
29+
Attributes:
30+
project_types (dict): The key is attribute name
31+
and the value is attribute type.
32+
attribute_map (dict): The key is attribute name
33+
and the value is json key in definition.
34+
"""
35+
project_types = {
36+
'title': 'str',
37+
'slug': 'str',
38+
'owner_slug': 'str',
39+
'license_name': 'str',
40+
'subtitle': 'str',
41+
'description': 'str',
42+
'files': 'list[UploadFile]',
43+
'is_private': 'bool',
44+
'convert_to_csv': 'bool',
45+
'category_ids': 'list[str]'
46+
}
47+
48+
attribute_map = {
49+
'title': 'title',
50+
'slug': 'slug',
51+
'owner_slug': 'ownerSlug',
52+
'license_name': 'licenseName',
53+
'subtitle': 'subtitle',
54+
'description': 'description',
55+
'files': 'files',
56+
'is_private': 'isPrivate',
57+
'convert_to_csv': 'convertToCsv',
58+
'category_ids': 'categoryIds'
59+
}
60+
61+
def __init__(self, title=None, slug=None, owner_slug=None, license_name='unknown', subtitle=None, description='', files=None, is_private=True, convert_to_csv=True, category_ids=None): # noqa: E501
62+
63+
self._title = None
64+
self._slug = None
65+
self._owner_slug = None
66+
self._license_name = None
67+
self._subtitle = None
68+
self._description = None
69+
self._files = None
70+
self._is_private = None
71+
self._convert_to_csv = None
72+
self._category_ids = None
73+
self.discriminator = None
74+
75+
self.title = title
76+
if slug is not None:
77+
self.slug = slug
78+
if owner_slug is not None:
79+
self.owner_slug = owner_slug
80+
if license_name is not None:
81+
self.license_name = license_name
82+
if subtitle is not None:
83+
self.subtitle = subtitle
84+
if description is not None:
85+
self.description = description
86+
self.files = files
87+
if is_private is not None:
88+
self.is_private = is_private
89+
if convert_to_csv is not None:
90+
self.convert_to_csv = convert_to_csv
91+
if category_ids is not None:
92+
self.category_ids = category_ids
93+
94+
@property
95+
def title(self):
96+
"""Gets the title of this DatasetNewRequest. # noqa: E501
97+
98+
The title of the new dataset # noqa: E501
99+
100+
:return: The title of this DatasetNewRequest. # noqa: E501
101+
:rtype: str
102+
"""
103+
return self._title
104+
105+
@title.setter
106+
def title(self, title):
107+
"""Sets the title of this DatasetNewRequest.
108+
109+
The title of the new dataset # noqa: E501
110+
111+
:param title: The title of this DatasetNewRequest. # noqa: E501
112+
:type: str
113+
"""
114+
if title is None:
115+
raise ValueError("Invalid value for `title`, must not be `None`") # noqa: E501
116+
117+
self._title = title
118+
119+
@property
120+
def slug(self):
121+
"""Gets the slug of this DatasetNewRequest. # noqa: E501
122+
123+
The slug that the dataset should be created with # noqa: E501
124+
125+
:return: The slug of this DatasetNewRequest. # noqa: E501
126+
:rtype: str
127+
"""
128+
return self._slug
129+
130+
@slug.setter
131+
def slug(self, slug):
132+
"""Sets the slug of this DatasetNewRequest.
133+
134+
The slug that the dataset should be created with # noqa: E501
135+
136+
:param slug: The slug of this DatasetNewRequest. # noqa: E501
137+
:type: str
138+
"""
139+
140+
self._slug = slug
141+
142+
@property
143+
def owner_slug(self):
144+
"""Gets the owner_slug of this DatasetNewRequest. # noqa: E501
145+
146+
The owner's username # noqa: E501
147+
148+
:return: The owner_slug of this DatasetNewRequest. # noqa: E501
149+
:rtype: str
150+
"""
151+
return self._owner_slug
152+
153+
@owner_slug.setter
154+
def owner_slug(self, owner_slug):
155+
"""Sets the owner_slug of this DatasetNewRequest.
156+
157+
The owner's username # noqa: E501
158+
159+
:param owner_slug: The owner_slug of this DatasetNewRequest. # noqa: E501
160+
:type: str
161+
"""
162+
163+
self._owner_slug = owner_slug
164+
165+
@property
166+
def license_name(self):
167+
"""Gets the license_name of this DatasetNewRequest. # noqa: E501
168+
169+
The license that should be associated with the dataset # noqa: E501
170+
171+
:return: The license_name of this DatasetNewRequest. # noqa: E501
172+
:rtype: str
173+
"""
174+
return self._license_name
175+
176+
@license_name.setter
177+
def license_name(self, license_name):
178+
"""Sets the license_name of this DatasetNewRequest.
179+
180+
The license that should be associated with the dataset # noqa: E501
181+
182+
:param license_name: The license_name of this DatasetNewRequest. # noqa: E501
183+
:type: str
184+
"""
185+
allowed_values = ["CC0-1.0", "CC-BY-SA-4.0", "GPL-2.0", "ODbL-1.0", "CC-BY-NC-SA-4.0", "unknown", "DbCL-1.0", "CC-BY-SA-3.0", "copyright-authors", "other", "reddit-api", "world-bank", "CC-BY-4.0", "CC-BY-NC-4.0", "PDDL", "CC-BY-3.0", "CC-BY-3.0-IGO", "US-Government-Works", "CC-BY-NC-SA-3.0-IGO", "CDLA-Permissive-1.0", "CDLA-Sharing-1.0", "CC-BY-ND-4.0", "CC-BY-NC-ND-4.0", "ODC-BY-1.0", "LGPL-3.0", "AGPL-3.0", "FDL-1.3", "EU-ODP-Legal-Notice", "apache-2.0", "GPL-3.0"] # noqa: E501
186+
if license_name not in allowed_values:
187+
raise ValueError(
188+
"Invalid value for `license_name` ({0}), must be one of {1}" # noqa: E501
189+
.format(license_name, allowed_values)
190+
)
191+
else:
192+
license_name = license_name.lower()
193+
if license_name[0-1] == 'cc':
194+
license_name = 'cc'
195+
elif license_name[0-3] == 'gpl':
196+
license_name = 'gpl'
197+
elif license_name[0-3] == 'odb':
198+
license_name = 'odb'
199+
else:
200+
license_name = 'other'
201+
self._license_name = license_name
202+
203+
@property
204+
def subtitle(self):
205+
"""Gets the subtitle of this DatasetNewRequest. # noqa: E501
206+
207+
The subtitle to be set on the dataset # noqa: E501
208+
209+
:return: The subtitle of this DatasetNewRequest. # noqa: E501
210+
:rtype: str
211+
"""
212+
return self._subtitle
213+
214+
@subtitle.setter
215+
def subtitle(self, subtitle):
216+
"""Sets the subtitle of this DatasetNewRequest.
217+
218+
The subtitle to be set on the dataset # noqa: E501
219+
220+
:param subtitle: The subtitle of this DatasetNewRequest. # noqa: E501
221+
:type: str
222+
"""
223+
224+
self._subtitle = subtitle
225+
226+
@property
227+
def description(self):
228+
"""Gets the description of this DatasetNewRequest. # noqa: E501
229+
230+
The description to be set on the dataset # noqa: E501
231+
232+
:return: The description of this DatasetNewRequest. # noqa: E501
233+
:rtype: str
234+
"""
235+
return self._description
236+
237+
@description.setter
238+
def description(self, description):
239+
"""Sets the description of this DatasetNewRequest.
240+
241+
The description to be set on the dataset # noqa: E501
242+
243+
:param description: The description of this DatasetNewRequest. # noqa: E501
244+
:type: str
245+
"""
246+
247+
self._description = description
248+
249+
@property
250+
def files(self):
251+
"""Gets the files of this DatasetNewRequest. # noqa: E501
252+
253+
A list of files that should be associated with the dataset # noqa: E501
254+
255+
:return: The files of this DatasetNewRequest. # noqa: E501
256+
:rtype: list[UploadFile]
257+
"""
258+
return self._files
259+
260+
@files.setter
261+
def files(self, files):
262+
"""Sets the files of this DatasetNewRequest.
263+
264+
A list of files that should be associated with the dataset # noqa: E501
265+
266+
:param files: The files of this DatasetNewRequest. # noqa: E501
267+
:type: list[UploadFile]
268+
"""
269+
if files is None:
270+
raise ValueError("Invalid value for `files`, must not be `None`") # noqa: E501
271+
272+
self._files = files
273+
274+
@property
275+
def is_private(self):
276+
"""Gets the is_private of this DatasetNewRequest. # noqa: E501
277+
278+
Whether or not the dataset should be private # noqa: E501
279+
280+
:return: The is_private of this DatasetNewRequest. # noqa: E501
281+
:rtype: bool
282+
"""
283+
return self._is_private
284+
285+
@is_private.setter
286+
def is_private(self, is_private):
287+
"""Sets the is_private of this DatasetNewRequest.
288+
289+
Whether or not the dataset should be private # noqa: E501
290+
291+
:param is_private: The is_private of this DatasetNewRequest. # noqa: E501
292+
:type: bool
293+
"""
294+
295+
self._is_private = is_private
296+
297+
@property
298+
def convert_to_csv(self):
299+
"""Gets the convert_to_csv of this DatasetNewRequest. # noqa: E501
300+
301+
Whether or not a tabular dataset should be converted to csv # noqa: E501
302+
303+
:return: The convert_to_csv of this DatasetNewRequest. # noqa: E501
304+
:rtype: bool
305+
"""
306+
return self._convert_to_csv
307+
308+
@convert_to_csv.setter
309+
def convert_to_csv(self, convert_to_csv):
310+
"""Sets the convert_to_csv of this DatasetNewRequest.
311+
312+
Whether or not a tabular dataset should be converted to csv # noqa: E501
313+
314+
:param convert_to_csv: The convert_to_csv of this DatasetNewRequest. # noqa: E501
315+
:type: bool
316+
"""
317+
318+
self._convert_to_csv = convert_to_csv
319+
320+
@property
321+
def category_ids(self):
322+
"""Gets the category_ids of this DatasetNewRequest. # noqa: E501
323+
324+
A list of tag IDs to associated with the dataset # noqa: E501
325+
326+
:return: The category_ids of this DatasetNewRequest. # noqa: E501
327+
:rtype: list[str]
328+
"""
329+
return self._category_ids
330+
331+
@category_ids.setter
332+
def category_ids(self, category_ids):
333+
"""Sets the category_ids of this DatasetNewRequest.
334+
335+
A list of tag IDs to associated with the dataset # noqa: E501
336+
337+
:param category_ids: The category_ids of this DatasetNewRequest. # noqa: E501
338+
:type: list[str]
339+
"""
340+
341+
self._category_ids = category_ids
342+
343+
def to_dict(self):
344+
"""Returns the model properties as a dict"""
345+
result = {}
346+
347+
for attr, _ in six.iteritems(self.project_types):
348+
value = getattr(self, attr)
349+
if isinstance(value, list):
350+
result[attr] = list(map(
351+
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
352+
value
353+
))
354+
elif hasattr(value, "to_dict"):
355+
result[attr] = value.to_dict()
356+
elif isinstance(value, dict):
357+
result[attr] = dict(map(
358+
lambda item: (item[0], item[1].to_dict())
359+
if hasattr(item[1], "to_dict") else item,
360+
value.items()
361+
))
362+
else:
363+
result[attr] = value
364+
365+
return result
366+
367+
def to_str(self):
368+
"""Returns the string representation of the model"""
369+
return pprint.pformat(self.to_dict())
370+
371+
def __repr__(self):
372+
"""For `print` and `pprint`"""
373+
return self.to_str()
374+
375+
def __eq__(self, other):
376+
"""Returns true if both objects are equal"""
377+
if not isinstance(other, DatasetNewRequest):
378+
return False
379+
380+
return self.__dict__ == other.__dict__
381+
382+
def __ne__(self, other):
383+
"""Returns true if both objects are not equal"""
384+
return not self == other
385+

0 commit comments

Comments
 (0)