From f0e81c9e734703e193b7ab073d4803a873403613 Mon Sep 17 00:00:00 2001 From: Thomas Labadie Date: Fri, 30 Nov 2018 10:57:24 +0100 Subject: [PATCH 1/7] Coders XP Python API --- dataikuapi/dss/plugin.py | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index c2e94f65..05e1a996 100644 --- a/dataikuapi/dss/plugin.py +++ b/dataikuapi/dss/plugin.py @@ -79,4 +79,62 @@ 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) + 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("GET", "/plugins/%s/actions/pullRebase" % (self.plugin_id)) + + def push(self): + """ + Push from the current branch of the plugin. + """ + return self.client._perform_json("GET", "/plugins/%s/actions/push" % (self.plugin_id)) + + def fetch(self): + """ + Fetch new content from remote repository. + """ + return self.client._perform_json("GET", "/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("GET", "/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("GET", "/plugins/%s/actions/resetToRemoteHeadState" % (self.plugin_id)) + + def set_remote(self, repository_URL): + """ + Sets the URL of the Git remote origin for your local repository. + """ + return self.client._perform_json("POST", "/plugins/%s/gitRemote" % (self.plugin_id), body={'repositoryUrl': repository_URL}) + + def delete_remote(self, repository_URL): + """ + Removes the URL of the Git remote origin for your local repository. + """ + return self.client._perform_json("DELETE", "/plugins/%s/gitRemote" % (self.plugin_id)) + \ No newline at end of file From c911d741b45c8768045028125e6406f4d21b2430 Mon Sep 17 00:00:00 2001 From: Thomas Labadie Date: Fri, 30 Nov 2018 11:07:12 +0100 Subject: [PATCH 2/7] Python API for getting remote repository URL --- dataikuapi/dss/plugin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index 05e1a996..554ae9ac 100644 --- a/dataikuapi/dss/plugin.py +++ b/dataikuapi/dss/plugin.py @@ -125,16 +125,21 @@ def reset_to_remote_head_state(self): """ return self.client._perform_json("GET", "/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. """ return self.client._perform_json("POST", "/plugins/%s/gitRemote" % (self.plugin_id), body={'repositoryUrl': repository_URL}) - def delete_remote(self, 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)) - \ No newline at end of file From 53cf7178226135e27ebd3b2bb0780a718af5005b Mon Sep 17 00:00:00 2001 From: Thomas Labadie Date: Tue, 4 Dec 2018 11:42:07 +0100 Subject: [PATCH 3/7] Changed a few API paths to match new specs --- dataikuapi/dss/plugin.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index 554ae9ac..97e2dfcb 100644 --- a/dataikuapi/dss/plugin.py +++ b/dataikuapi/dss/plugin.py @@ -99,31 +99,31 @@ def pull_rebase(self): """ Pull the latest version from the current branch of the plugin. Aborts if merge fails. """ - return self.client._perform_json("GET", "/plugins/%s/actions/pullRebase" % (self.plugin_id)) + 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("GET", "/plugins/%s/actions/push" % (self.plugin_id)) + 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("GET", "/plugins/%s/actions/fetch" % (self.plugin_id)) + 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("GET", "/plugins/%s/actions/resetToLocalHeadState" % (self.plugin_id)) + 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("GET", "/plugins/%s/actions/resetToRemoteHeadState" % (self.plugin_id)) + return self.client._perform_json("POST", "/plugins/%s/actions/resetToRemoteHeadState" % (self.plugin_id)) def get_remote(self): """ @@ -135,7 +135,7 @@ def set_remote(self, repository_URL): """ Sets the URL of the Git remote origin for your local repository. """ - return self.client._perform_json("POST", "/plugins/%s/gitRemote" % (self.plugin_id), body={'repositoryUrl': repository_URL}) + return self.client._perform_json("POST", "/plugins/%s/gitRemote" % (self.plugin_id), params={'repositoryUrl': repository_URL}) def delete_remote(self): """ @@ -143,3 +143,15 @@ def delete_remote(self): """ 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 set_active_branch(self, branch, creation=False): + """ + Sets the active branch on your local repository. + """ + return self.client._perform_json("POST", "/plugins/%s/activeGitBranch" % (self.plugin_id), params={'branch': branch, 'creation': creation}) + From 906bc23f7a8e25a2a815a0697d98fb7e3d0f9d1e Mon Sep 17 00:00:00 2001 From: Thomas Labadie Date: Tue, 4 Dec 2018 14:37:50 +0100 Subject: [PATCH 4/7] Body params for public API calls --- dataikuapi/dss/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index 97e2dfcb..64c815b3 100644 --- a/dataikuapi/dss/plugin.py +++ b/dataikuapi/dss/plugin.py @@ -135,7 +135,7 @@ def set_remote(self, repository_URL): """ Sets the URL of the Git remote origin for your local repository. """ - return self.client._perform_json("POST", "/plugins/%s/gitRemote" % (self.plugin_id), params={'repositoryUrl': repository_URL}) + return self.client._perform_json("POST", "/plugins/%s/gitRemote" % (self.plugin_id), body={'repositoryUrl': repository_URL}) def delete_remote(self): """ @@ -153,5 +153,5 @@ def set_active_branch(self, branch, creation=False): """ Sets the active branch on your local repository. """ - return self.client._perform_json("POST", "/plugins/%s/activeGitBranch" % (self.plugin_id), params={'branch': branch, 'creation': creation}) + return self.client._perform_json("POST", "/plugins/%s/activeGitBranch" % (self.plugin_id), body={'branch': branch, 'creation': creation}) From 28b1ae2895f25aad55efa9e5aac9840d15b5f431 Mon Sep 17 00:00:00 2001 From: Thomas Labadie Date: Tue, 4 Dec 2018 15:22:00 +0100 Subject: [PATCH 5/7] Python API to create dev plugin from Git, more docstring --- dataikuapi/dss/plugin.py | 5 +++++ dataikuapi/dssclient.py | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index 64c815b3..e02c1d0d 100644 --- a/dataikuapi/dss/plugin.py +++ b/dataikuapi/dss/plugin.py @@ -134,6 +134,8 @@ def get_remote(self): 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}) @@ -152,6 +154,9 @@ def get_branches(self): 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 ######################################################## From dabf9fb5e156dafbd2062edc22b013f72c819b1a Mon Sep 17 00:00:00 2001 From: Thomas Labadie Date: Fri, 7 Dec 2018 11:55:27 +0100 Subject: [PATCH 6/7] Python APIs for setting/getting settings and code-envs --- dataikuapi/dss/plugin.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index e02c1d0d..479b03e8 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 ######################################################## From 362684cab32255f2bd475d8fcdc0cff887225099 Mon Sep 17 00:00:00 2001 From: Thomas Labadie Date: Tue, 11 Dec 2018 16:08:52 +0100 Subject: [PATCH 7/7] Python API > Method to get the current branch on the repository --- dataikuapi/dss/plugin.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dataikuapi/dss/plugin.py b/dataikuapi/dss/plugin.py index 479b03e8..1bf56dff 100644 --- a/dataikuapi/dss/plugin.py +++ b/dataikuapi/dss/plugin.py @@ -185,6 +185,12 @@ def get_branches(self): """ 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.