Skip to content

Commit 393f7d6

Browse files
committed
Style changing: storing raw json, provide access through @Property.
1 parent d05d932 commit 393f7d6

File tree

1 file changed

+116
-63
lines changed

1 file changed

+116
-63
lines changed

dataikuapi/dss/plugin.py

Lines changed: 116 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def list_usages(self, project_key=None):
118118
:param str project_key: optional key of project where to look for usages. Default is None and looking in all projects.
119119
:return: a :class:`DSSPluginUsages`
120120
"""
121-
return DSSPluginUsages.build(
121+
return DSSPluginUsages(
122122
self.client._perform_json("GET", "/plugins/{pluginId}/actions/listUsages".format(pluginId=self.plugin_id),
123123
params={"projectKey": project_key})
124124
)
@@ -179,64 +179,97 @@ def put_file(self, path, f):
179179
class DSSPluginUsage(object):
180180
"""
181181
Information on a usage of an element of a plugin.
182-
183-
object_id, object_type and project_key are usually provided, excepted for some global
184-
types, such as cluster types.
185182
"""
186-
def __init__(self, element_kind, element_type, object_id, object_type, project_key):
187-
"""
188-
189-
:param str element_kind:
190-
:param str element_type:
191-
:param str object_id:
192-
:param str object_type:
193-
:param str project_key:
194-
"""
195-
self.element_kind = element_kind
196-
self.element_type = element_type
197-
self.object_id = object_id
198-
self.object_type = object_type
199-
self.project_key = project_key
200-
201-
@staticmethod
202-
def build(json_object):
203-
return DSSPluginUsage(
204-
json_object["elementKind"],
205-
json_object["elementType"],
206-
json_object.get("objectId", None),
207-
json_object.get("objectType", None),
208-
json_object.get("projectKey", None)
209-
)
183+
def __init__(self, json_object):
184+
self._json_object = json_object
185+
186+
def get_raw(self):
187+
return self._json_object
188+
189+
@property
190+
def element_kind(self):
191+
"""
192+
Element kind (webapps, python-formats,...)
193+
:return: the element kind
194+
:rtype: str
195+
"""
196+
return self._json_object["elementKind"]
197+
198+
@property
199+
def element_type(self):
200+
"""
201+
Element type
202+
:return: the element type
203+
:rtype: str
204+
"""
205+
return self._json_object["elementType"]
206+
207+
@property
208+
def object_id(self):
209+
"""
210+
:return: Id of the object using the plugin element
211+
:rtype: str or none
212+
"""
213+
return self._json_object.get("objectId", None)
214+
215+
@property
216+
def object_type(self):
217+
"""
218+
:return: Type of the object using the plugin element
219+
:rtype: str or none
220+
"""
221+
return self._json_object.get("objectType", None)
222+
223+
@property
224+
def project_key(self):
225+
"""
226+
:return: Project key of the object using the plugin element
227+
:rtype: str or none
228+
"""
229+
return self._json_object.get("projectKey", None)
210230

211231

212232
class DSSMissingType(object):
213233
"""
214234
Information on a type not found while analyzing usages of a plugin.
215-
216-
object_id, object_type and project_key are usually provided, excepted for some global
217-
types, such as cluster types.
218235
"""
219-
def __init__(self, missing_type, object_id, object_type, project_key):
220-
"""
221-
222-
:param str missing_type: the missing type
223-
:param str object_id: the object using the missing type (can be None)
224-
:param str object_type: the type of the object using the missing type (can be None)
225-
:param str project_key: the project key where the type was found missing (can be None)
226-
"""
227-
self.missing_type = missing_type
228-
self.object_id = object_id
229-
self.object_type = object_type
230-
self.project_key = project_key
231-
232-
@staticmethod
233-
def build(json_object):
234-
return DSSMissingType(
235-
json_object["missingType"],
236-
json_object.get("objectId", None),
237-
json_object.get("objectType", None),
238-
json_object.get("projectKey", None)
239-
)
236+
def __init__(self, json_object):
237+
self._json_object = json_object
238+
239+
def get_raw(self):
240+
return self._json_object
241+
242+
@property
243+
def missing_type(self):
244+
"""
245+
:return: the missing type
246+
:rtype: str
247+
"""
248+
return self._json_object["missingType"]
249+
250+
@property
251+
def object_id(self):
252+
"""
253+
:return: Id of the object relying on the missing type
254+
:rtype: str or none
255+
"""
256+
return self._json_object.get("objectId", None)
257+
258+
@property
259+
def object_type(self):
260+
"""
261+
:return: Type of the object relying on the missing type
262+
:rtype: str or none
263+
"""
264+
return self._json_object.get("objectType", None)
265+
266+
@property
267+
def project_key(self):
268+
"""
269+
:return: Project key of the object relying on the missing type
270+
:rtype: str or none
271+
"""
272+
return self._json_object.get("projectKey", None)
240273

241274

242275
class DSSPluginUsages(object):
@@ -250,20 +283,40 @@ class DSSPluginUsages(object):
250283
but is still used. This prevents some detailed analysis and may hide some uses.
251284
This information is provided in missingTypes.
252285
"""
253-
def __init__(self, usages, missing_types):
286+
def __init__(self, json_object):
254287
"""
288+
:param dict json_object: the usages as json dict
255289
:param list(:class:`DSSPluginUsage`) usages: plugin usages
256290
:param list(:class:`DSSMissingType`) missing_types:
257291
"""
258-
self.usages = usages
259-
self.missing_types = missing_types
260-
261-
@staticmethod
262-
def build(json_object):
263-
usages = []
264-
missing_types = []
292+
self._json_object = json_object
293+
self._usages = []
294+
self._missing_types = []
265295
for json_usage in json_object.get("usages", []):
266-
usages.append(DSSPluginUsage.build(json_usage))
296+
self._usages.append(DSSPluginUsage(json_usage))
267297
for json_missing_type in json_object.get("missingTypes"):
268-
missing_types.append(DSSMissingType.build(json_missing_type))
269-
return DSSPluginUsages(usages, missing_types)
298+
self._missing_types.append(DSSMissingType(json_missing_type))
299+
300+
def get_raw(self):
301+
return self._json_object
302+
303+
def needs_force_delete(self):
304+
return not self._usages or not self._missing_types
305+
306+
@property
307+
def usages(self):
308+
"""
309+
List of plugin usages
310+
:return: plugin usages
311+
:rtype: list(:class:`DSSPluginUsage`)
312+
"""
313+
return self._usages
314+
315+
@property
316+
def missing_types(self):
317+
"""
318+
List of missing types
319+
:return: missing types
320+
:rtype: list(:class:`DSSMissingType` )
321+
"""
322+
return self._missing_types

0 commit comments

Comments
 (0)