Skip to content

Commit 5e2f403

Browse files
committed
Taiking in account remarks from review.
1 parent af94d69 commit 5e2f403

File tree

1 file changed

+54
-26
lines changed

1 file changed

+54
-26
lines changed

dataikuapi/dss/plugin.py

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def save(self):
2121
"""Saves the settings to DSS"""
2222
self.client._perform_empty("POST", "/plugins/%s/settings" % (self.plugin_id), body=self.settings)
2323

24+
2425
class DSSPlugin(object):
2526
"""
2627
A plugin on the DSS instance
@@ -180,11 +181,19 @@ class DSSPluginUsage(object):
180181
"""
181182
Information on a usage of an element of a plugin.
182183
"""
183-
def __init__(self, json_object):
184-
self._json_object = json_object
184+
def __init__(self, data):
185+
"""
186+
Instantiate a DSSPluginUsage from the dict of its properties.
187+
:param dict data: dict of properties
188+
"""
189+
self._data = data
185190

186191
def get_raw(self):
187-
return self._json_object
192+
"""
193+
Get plugin usage as a dictionary
194+
:rtype: dict
195+
"""
196+
return self._data
188197

189198
@property
190199
def element_kind(self):
@@ -193,7 +202,7 @@ def element_kind(self):
193202
:return: the element kind
194203
:rtype: str
195204
"""
196-
return self._json_object["elementKind"]
205+
return self._data["elementKind"]
197206

198207
@property
199208
def element_type(self):
@@ -202,105 +211,124 @@ def element_type(self):
202211
:return: the element type
203212
:rtype: str
204213
"""
205-
return self._json_object["elementType"]
214+
return self._data["elementType"]
206215

207216
@property
208217
def object_id(self):
209218
"""
210219
:return: Id of the object using the plugin element
211220
:rtype: str or none
212221
"""
213-
return self._json_object.get("objectId", None)
222+
return self._data.get("objectId", None)
214223

215224
@property
216225
def object_type(self):
217226
"""
218227
:return: Type of the object using the plugin element
219228
:rtype: str or none
220229
"""
221-
return self._json_object.get("objectType", None)
230+
return self._data.get("objectType", None)
222231

223232
@property
224233
def project_key(self):
225234
"""
226235
:return: Project key of the object using the plugin element
227236
:rtype: str or none
228237
"""
229-
return self._json_object.get("projectKey", None)
238+
return self._data.get("projectKey", None)
230239

231240

232241
class DSSMissingType(object):
233242
"""
234243
Information on a type not found while analyzing usages of a plugin.
235244
"""
236-
def __init__(self, json_object):
237-
self._json_object = json_object
245+
def __init__(self, data):
246+
"""
247+
Instantiate a DSSMissingType from the dict of its properties
248+
:param dict data: dictionary of properties
249+
"""
250+
self._data = data
238251

239252
def get_raw(self):
240-
return self._json_object
253+
"""
254+
Get missing type as a dictionary
255+
:rtype: dict
256+
"""
257+
return self._data
241258

242259
@property
243260
def missing_type(self):
244261
"""
245262
:return: the missing type
246263
:rtype: str
247264
"""
248-
return self._json_object["missingType"]
265+
return self._data["missingType"]
249266

250267
@property
251268
def object_id(self):
252269
"""
253-
:return: Id of the object relying on the missing type
270+
:return: Id of the object depending on the missing type
254271
:rtype: str or none
255272
"""
256-
return self._json_object.get("objectId", None)
273+
return self._data.get("objectId", None)
257274

258275
@property
259276
def object_type(self):
260277
"""
261-
:return: Type of the object relying on the missing type
278+
:return: Type of the object depending on the missing type
262279
:rtype: str or none
263280
"""
264-
return self._json_object.get("objectType", None)
281+
return self._data.get("objectType", None)
265282

266283
@property
267284
def project_key(self):
268285
"""
269-
:return: Project key of the object relying on the missing type
286+
:return: Project key of the object depending on the missing type
270287
:rtype: str or none
271288
"""
272-
return self._json_object.get("projectKey", None)
289+
return self._data.get("projectKey", None)
273290

274291

275292
class DSSPluginUsages(object):
276293
"""
277294
Information on the usages of a plugin.
278295
279-
Contains both usages (a list of instances of :class:`DSSPluginUsage`) and analysis errors, if any
280-
(a list of instances of :class:`DSSMissingType`).
296+
Contains both usages (a list of :class:`DSSPluginUsage`) and analysis errors, if any
297+
(a list of :class:`DSSMissingType`).
281298
282299
Some custom types may not be found during usage analysis, typically when a plugin was removed
283300
but is still used. This prevents some detailed analysis and may hide some uses.
284301
This information is provided in missingTypes.
285302
"""
286-
def __init__(self, json_object):
303+
def __init__(self, data):
287304
"""
288-
:param dict json_object: the usages as json dict
305+
Initialize a DSSPluginUsages from a dict of its properties
306+
307+
:param dict data: the usages as json dict
289308
:param list(:class:`DSSPluginUsage`) usages: plugin usages
290309
:param list(:class:`DSSMissingType`) missing_types:
291310
"""
292-
self._json_object = json_object
311+
self._data = data
293312
self._usages = []
294313
self._missing_types = []
295-
for json_usage in json_object.get("usages", []):
314+
for json_usage in data.get("usages", []):
296315
self._usages.append(DSSPluginUsage(json_usage))
297-
for json_missing_type in json_object.get("missingTypes"):
316+
for json_missing_type in data.get("missingTypes"):
298317
self._missing_types.append(DSSMissingType(json_missing_type))
299318

300319
def get_raw(self):
301-
return self._json_object
320+
"""
321+
Get plugin usages as a dictionary.
322+
:rtype: dict
323+
"""
324+
return self._data
302325

303326
def needs_force_delete(self):
327+
"""
328+
Returns true the deletion of the plugin should be forced, as usages of the plugin were found, or errors
329+
encoutered during analysis.
330+
:return:
331+
"""
304332
return not (not self._usages and not self._missing_types)
305333

306334
@property

0 commit comments

Comments
 (0)