Skip to content

Feature/dss51 coders xp #37

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 7 commits into
base: release/7.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 121 additions & 1 deletion dataikuapi/dss/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
########################################################
Expand Down Expand Up @@ -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)


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})

25 changes: 25 additions & 0 deletions dataikuapi/dssclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
########################################################
Expand Down