77from .apiservice import DSSAPIService
88import sys
99
10+ class DSSPluginSettings (object ):
11+ """
12+ The settings of a plugin.
13+ """
14+
15+ def __init__ (self , client , plugin_id , settings ):
16+ """Do not call this directly, use :meth:`DSSPlugin.get_settings`"""
17+ self .client = client
18+ self .plugin_id = plugin_id
19+ self .settings = settings
20+
21+ def get_raw (self ):
22+ """Returns the raw settings object"""
23+ return self .settings
24+
25+ def save (self ):
26+ """Saves the settings to DSS"""
27+ self .client ._perform_empty ("POST" , "/plugins/%s/settings" % (self .plugin_id ), body = self .settings )
28+
1029class DSSPlugin (object ):
1130 """
1231 A plugin on the DSS instance
@@ -16,65 +35,109 @@ def __init__(self, client, plugin_id):
1635 self .plugin_id = plugin_id
1736
1837 ########################################################
19- # plugin upload/update as zip
38+ # Settings
2039 ########################################################
2140
22- def upload (self , file_path ):
41+ def get_settings (self ):
42+ """Return the plugin-level settings
43+
44+ :return: a :class:`DSSPluginSettings`
2345 """
24- Upload the given file as a plugin
46+ settings = self .client ._perform_json ("GET" , "/plugins/%s/settings" % (self .plugin_id ))
47+ return DSSPluginSettings (self .client , self .plugin_id , settings )
2548
26- Note: this call requires an API key with admin rights
27-
28- :param: file_path : the path to the zip file of the plugin
49+ ########################################################
50+ # Code env
51+ ########################################################
52+
53+ def create_code_env (self , python_interpreter = None , conda = False ):
2954 """
30- with open (file_path , 'rb' ) as f :
31- return self .client ._perform_json_upload ("POST" , "/plugins/%s/upload" % (self .plugin_id ), 'plugin.zip' , f ).text
55+ Starts the creation of the code env of the plugin
3256
33- def update ( self , file_path ):
57+ :return: a :class:`dataikuapi.dssfuture.DSSFuture`
3458 """
35- Update the plugin with the given file
59+ ret = self .client ._perform_json ("POST" , "/plugins/%s/code-env/actions/create" % (self .plugin_id ), body = {
60+ "conda" : conda ,
61+ "pythonInterpreter" : python_interpreter
62+ })
63+ return self .client .get_future (ret ["jobId" ])
3664
37- Note: this call requires an API key with admin rights
38-
39- :param: file_path : the path to the zip file of the plugin
65+
66+ def update_code_env (self ):
4067 """
41- with open (file_path , 'rb' ) as f :
42- return self .client ._perform_json_upload ("POST" , "/plugins/%s/update" % (self .plugin_id ), 'plugin.zip' , f ).text
68+ Starts an update of the code env of the plugin
69+
70+ :return: a :class:`dataikuapi.dss.future.DSSFuture`
71+ """
72+ ret = self .client ._perform_json ("POST" , "/plugins/%s/code-env/actions/update" % (self .plugin_id ))
73+ return self .client .get_future (ret ["jobId" ])
74+
75+
76+ ########################################################
77+ # Plugin update
78+ ########################################################
79+
80+ def update_from_zip (self , fp ):
81+ """
82+ Updates the plugin from a plugin archive (as a file object)
83+
84+ :param object fp: A file-like object pointing to a plugin archive zip
85+ """
86+ files = {'file' : fp }
87+ self .client ._perform_json ("POST" , "/plugins/%s/actions/updateFromZip" % (self .plugin_id ), files = files )
88+
89+ def update_from_store (self ):
90+ """
91+ Updates the plugin from the Dataiku plugin store
92+
93+ :return: a :class:`~dataikuapi.dss.future.DSSFuture`
94+ """
95+ ret = self .client ._perform_json ("POST" , "/plugins/%s/actions/updateFromStore" % (self .plugin_id ))
96+ return self .client .get_future (ret ["jobId" ])
97+
98+ def update_from_git (self , repository_url , checkout = "master" , subpath = None ):
99+ """
100+ Updates the plugin from a Git repository. DSS must be setup to allow access to the repository.
101+
102+ :param str repository_url: URL of a Git remote
103+ :param str checkout: branch/tag/SHA1 to commit. For example "master"
104+ :param str subpath: Optional, path within the repository to use as plugin. Should contain a 'plugin.json' file
105+ :return: a :class:`~dataikuapi.dss.future.DSSFuture`
106+ """
107+ ret = self .client ._perform_json ("POST" , "/plugins/%s/actions/updateFromGit" % (self .plugin_id ), body = {
108+ "gitRepositoryUrl" : repository_url ,
109+ "gitCheckout" : checkout ,
110+ "gitSubpath" : subpath
111+ })
112+ return self .client .get_future (ret ["jobId" ])
43113
44114 ########################################################
45115 # Managing the dev plugin's contents
46116 ########################################################
47117
48118 def list_files (self ):
49119 """
50- Get the hierarchy of files in the plugin
51-
52- Returns:
53- the plugins's contents
120+ Get the hierarchy of files in the plugin (dev plugins only)
54121 """
55122 return self .client ._perform_json ("GET" , "/plugins/%s/contents" % (self .plugin_id ))
56123
57124 def get_file (self , path ):
58125 """
59- Get a file from the plugin folder
60-
61- Args:
62- path: the name of the file, from the root of the plugin
126+ Get a file from the plugin folder (dev plugins only)
63127
64- Returns:
65- the file's content, as a stream
128+ :param str path: the path of the file, relative to the root of the plugin
129+
130+ :return: a file-like object containing the file's content
66131 """
67132 return self .client ._perform_raw ("GET" , "/plugins/%s/contents/%s" % (self .plugin_id , path )).raw
68133
69134 def put_file (self , path , f ):
70135 """
71- Update a file in the plugin folder
136+ Update a file in the plugin folder (dev plugins only)
72137
73- Args:
74- f: the file contents, as a stream
75- path: the name of the file, from the root of the plugin
138+ :param file-like f: the file contents, as a file-like object
139+ :param str path: the path of the file, relative ot the root of the plugin
76140 """
77-
78141 file_name = path .split ('/' )[- 1 ]
79142 data = f .read () # eat it all, because making it work with a path variable and a MultifilePart in swing looks complicated
80143 return self .client ._perform_empty ("POST" , "/plugins/%s/contents/%s" % (self .plugin_id , path ), raw_body = data )
0 commit comments