diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index c2e94f65..1bf56dff 100644 --- a/dataikuapi/dss/plugin.py +++ b/dataikuapi/dss/plugin.py @@ -41,6 +41,40 @@ def update(self, file_path): with open(file_path, 'rb') as f: return self.client._perform_json_upload("POST", "/plugins/%s/update" % (self.plugin_id), 'plugin.zip', f).text + ######################################################## + # Plugin settings + ######################################################## + + def get_settings(self): + """ + Get the plugin settings + """ + return self.client._perform_json("GET", "/plugins/%s/settings" % (self.plugin_id)) + + def set_settings(self, plugin_settings): + """ + Set the plugin settings + + :param plugin_settings: the new plugin settings + """ + return self.client._perform_json("POST", "/plugins/%s/settings" % (self.plugin_id), body=plugin_settings) + + ######################################################## + # Plugin code env + ######################################################## + + def create_code_env(self): + """ + Create a new plugin code-env + """ + return self.client._perform_json("POST", "/plugins/%s/code-env/actions/create" % (self.plugin_id)) + + def update_code_env(self): + """ + Update the current plugin code-env + """ + return self.client._perform_json("POST", "/plugins/%s/code-env/actions/update" % (self.plugin_id)) + ######################################################## # Managing the dev plugin's contents ######################################################## @@ -79,4 +113,90 @@ def put_file(self, path, f): data = f.read() # eat it all, because making it work with a path variable and a MultifilePart in swing looks complicated return self.client._perform_empty("POST", "/plugins/%s/contents/%s" % (self.plugin_id, path), raw_body=data) - \ No newline at end of file + def delete_file(self, path): + """ + Get a file from the plugin folder + + Args: + path: the name of the file, from the root of the plugin + + Returns: + the file's content, as a stream + """ + return self.client._perform_raw("DELETE", "/plugins/%s/contents/%s" % (self.plugin_id, path)).raw + + ######################################################## + # Dev plugin Git integration + ######################################################## + + def pull_rebase(self): + """ + Pull the latest version from the current branch of the plugin. Aborts if merge fails. + """ + return self.client._perform_json("POST", "/plugins/%s/actions/pullRebase" % (self.plugin_id)) + + def push(self): + """ + Push from the current branch of the plugin. + """ + return self.client._perform_json("POST", "/plugins/%s/actions/push" % (self.plugin_id)) + + def fetch(self): + """ + Fetch new content from remote repository. + """ + return self.client._perform_json("POST", "/plugins/%s/actions/fetch" % (self.plugin_id)) + + def reset_to_local_head_state(self): + """ + Drop uncommitted changes and resets the current branch to local HEAD. + """ + return self.client._perform_json("POST", "/plugins/%s/actions/resetToLocalHeadState" % (self.plugin_id)) + + def reset_to_remote_head_state(self): + """ + Delete all of your non-pushed work on the current branch and resets it to the remote state. + """ + return self.client._perform_json("POST", "/plugins/%s/actions/resetToRemoteHeadState" % (self.plugin_id)) + + def get_remote(self): + """ + Gets the URL of the Git remote origin for your local repository. + """ + return self.client._perform_json("GET", "/plugins/%s/gitRemote" % (self.plugin_id)) + + def set_remote(self, repository_URL): + """ + Sets the URL of the Git remote origin for your local repository. + + :param str repository_URL: the repository URL + """ + return self.client._perform_json("POST", "/plugins/%s/gitRemote" % (self.plugin_id), body={'repositoryUrl': repository_URL}) + + def delete_remote(self): + """ + Removes the URL of the Git remote origin for your local repository. + """ + return self.client._perform_json("DELETE", "/plugins/%s/gitRemote" % (self.plugin_id)) + + def get_branches(self): + """ + Retrieves the list of available branches on your repository. + """ + return self.client._perform_json("GET", "/plugins/%s/gitBranches" % (self.plugin_id)) + + def get_active_branch(self): + """ + Gets the active branch on your local repository. + """ + return self.client._perform_json("GET", "/plugins/%s/activeGitBranch") + + def set_active_branch(self, branch, creation=False): + """ + Sets the active branch on your local repository. + + :param str branch: the branch name + :param bool creation: should it be created before checkout + """ + return self.client._perform_json("POST", "/plugins/%s/activeGitBranch" % (self.plugin_id), body={'branch': branch, 'creation': creation}) + diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index a6952dfe..ce3c3ddb 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -178,6 +178,31 @@ def get_plugin(self, plugin_id): """ return DSSPlugin(self, plugin_id) + def create_dev_plugin(self, creation_mode="EMPTY", plugin_id=None, git_repository=None, git_checkout=None, git_subpath=None): + """ + Create a new dev plugin inside DSS, and returns a handle to interact with it. + + :param str creation_mode: the way the plugin will be created; + - EMPTY: from scratch + - GIT_CLONE: from a full Git repository (history is retrieved) + - GIT_EXPORT: from a partial Git repository (no history, no push back) + :param str plugin_id: the identifier of the desired plugin (for EMPTY, guessed otherwise) + :param str git_repository: the Git repository URL (necessary for GIT_CLONE and GIT_EXPORT) + :param str git_checkout: the Git repository branch, tag or hash (necessary for GIT_EXPORT) + :param str git_subpath: path to the plugin in the repository (necessary for GIT_EXPORT) + :returns: A :class:`dataikuapi.dss.project.DSSPlugin` + """ + create_dev_plugin_body = { + 'creationMode': creation_mode, + 'pluginId': plugin_id, + 'gitRepository': git_repository, + 'gitCheckout': git_checkout, + 'gitSubpath': git_subpath, + } + res = self._perform_json("POST", "/plugins/actions/createDev", body=create_dev_plugin_body) + return DSSPlugin(self, res['details']) + + ######################################################## # SQL queries ########################################################