|
| 1 | +import time |
| 2 | +from .dataset import DSSDataset |
| 3 | +from .recipe import DSSRecipe |
| 4 | +from .managedfolder import DSSManagedFolder |
| 5 | +from .savedmodel import DSSSavedModel |
| 6 | +from .job import DSSJob, DSSJobWaiter |
| 7 | +from .scenario import DSSScenario |
| 8 | +from .apiservice import DSSAPIService |
| 9 | +import sys |
| 10 | +import os.path as osp |
| 11 | +from .future import DSSFuture |
| 12 | +from .notebook import DSSNotebook |
| 13 | +from .macro import DSSMacro |
| 14 | +from .wiki import DSSWiki |
| 15 | +from .discussion import DSSObjectDiscussions |
| 16 | +from .ml import DSSMLTask |
| 17 | +from .analysis import DSSAnalysis |
| 18 | +from dataikuapi.utils import DataikuException |
| 19 | + |
| 20 | + |
| 21 | +class DSSProjectFolder(object): |
| 22 | + """ |
| 23 | + A handle to interact with a project folder on the DSS instance. |
| 24 | +
|
| 25 | + Do not create this class directly, instead use :meth:`dataikuapi.DSSClient.get_project_folder` or :meth:`dataikuapi.DSSClient.get_root_project_folder` |
| 26 | + """ |
| 27 | + def __init__(self, client, project_folder_id): |
| 28 | + self.client = client |
| 29 | + self.project_folder_id = project_folder_id |
| 30 | + |
| 31 | + ######################################################## |
| 32 | + # Project folder deletion |
| 33 | + ######################################################## |
| 34 | + def delete(self): |
| 35 | + """ |
| 36 | + Delete the project folder |
| 37 | +
|
| 38 | + This call requires an API key with admin rights |
| 39 | + """ |
| 40 | + return self.client._perform_empty( |
| 41 | + "DELETE", "/project-folders/%s" % self.project_folder_id) |
| 42 | + |
| 43 | + ######################################################## |
| 44 | + # Project folder settings |
| 45 | + ######################################################## |
| 46 | + def get_settings(self): |
| 47 | + """ |
| 48 | + :returns: A :class:`dataikuapi.dss.projectfolder.DSSProjectFolderSettings` to interact with this project folder settings |
| 49 | + """ |
| 50 | + settings = self.client._perform_json("GET", "/project-folders/%s/settings" % self.project_folder_id) |
| 51 | + return DSSProjectFolderSettings(self.client, self.project_folder_id, settings) |
| 52 | + |
| 53 | + ######################################################## |
| 54 | + # Project folder sub-folder creation |
| 55 | + ######################################################## |
| 56 | + def create_sub_folder(self, name): |
| 57 | + """ |
| 58 | + Create a sub-folder into the current project folder |
| 59 | +
|
| 60 | + :param str name: the name of the project folder to create |
| 61 | + :returns: A :class:`dataikuapi.dss.projectfolder.DSSProjectFolder` to interact with the newly created project folder |
| 62 | + """ |
| 63 | + body = { |
| 64 | + "name": name |
| 65 | + } |
| 66 | + pf = self.client._perform_json("POST", "/project-folders/%s/children" % self.project_folder_id, body = body) |
| 67 | + return DSSProjectFolder(self.client, pf["id"]) |
| 68 | + |
| 69 | + ######################################################## |
| 70 | + # Project creation |
| 71 | + ######################################################## |
| 72 | + def create_project(self, project_key, name, owner, description=None, settings=None): |
| 73 | + """ |
| 74 | + Creates a new project within this project folder, and return a project handle to interact with it. |
| 75 | +
|
| 76 | + Note: this call requires an API key with admin rights or the rights to create a project |
| 77 | +
|
| 78 | + :param str project_key: the identifier to use for the project. Must be globally unique |
| 79 | + :param str name: the display name for the project. |
| 80 | + :param str owner: the login of the owner of the project. |
| 81 | + :param str description: a description for the project. |
| 82 | + :param dict settings: Initial settings for the project (can be modified later). The exact possible settings are not documented. |
| 83 | + |
| 84 | + :returns: A class:`dataikuapi.dss.project.DSSProject` project handle to interact with this project |
| 85 | + """ |
| 86 | + resp = self._perform_text( |
| 87 | + "POST", "/project-folders/%s/projects" % self.project_folder_id, body={ |
| 88 | + "projectKey" : project_key, |
| 89 | + "name" : name, |
| 90 | + "owner" : owner, |
| 91 | + "settings" : settings, |
| 92 | + "description" : description |
| 93 | + }) |
| 94 | + return DSSProject(self, project_key) |
| 95 | + |
| 96 | + ######################################################## |
| 97 | + # Project folder move |
| 98 | + ######################################################## |
| 99 | + def move(self, destination): |
| 100 | + """ |
| 101 | + Move this project folder into another project folder (aka. destination) |
| 102 | +
|
| 103 | + :param destination: the project folder to put this project folder into |
| 104 | + :type destination: A :class:`dataikuapi.dss.projectfolders.DSSProjectFolder` |
| 105 | + """ |
| 106 | + body = { |
| 107 | + "destination": destination.project_folder_id |
| 108 | + } |
| 109 | + self.client._perform_json("POST", "/project-folders/%s/move" % self.project_folder_id, body = body) |
| 110 | + |
| 111 | + ######################################################## |
| 112 | + # Project move |
| 113 | + ######################################################## |
| 114 | + def project_move(self, project_key, destination): |
| 115 | + """ |
| 116 | + Move a project within this project folder into another project folder (aka. destination) |
| 117 | +
|
| 118 | + :param str project_key: the project key associated with the project to move |
| 119 | + :param destination: the project folder to put this project into |
| 120 | + :type destination: A :class:`dataikuapi.dss.projectfolders.DSSProjectFolder` |
| 121 | + """ |
| 122 | + body = { |
| 123 | + "destination": destination.project_folder_id |
| 124 | + } |
| 125 | + self.client._perform_json("POST", "/project-folders/%s/children/%s/move" % (self.project_folder_id, project_key), body = body) |
| 126 | + |
| 127 | +class DSSProjectFolderSettings(object): |
| 128 | + """ |
| 129 | + A handle to interact with project folder settings |
| 130 | +
|
| 131 | + Do not create this class directly, instead use :meth:`dataikuapi.dss.projectfolder.DSSProjectFolder.get_settings` |
| 132 | + """ |
| 133 | + def __init__(self, client, project_folder_id, settings): |
| 134 | + self.client = client |
| 135 | + self.project_folder_id = project_folder_id |
| 136 | + self.settings = settings |
| 137 | + |
| 138 | + def get_raw(self): |
| 139 | + """Gets all settings as a raw dictionary. This returns a reference to the raw settings, not a copy, |
| 140 | + so changes made to the returned object will be reflected when saving. |
| 141 | +
|
| 142 | + :rtype: dict |
| 143 | + """ |
| 144 | + return self.settings |
| 145 | + |
| 146 | + def save(self): |
| 147 | + """Saves back the settings to the project folder""" |
| 148 | + self.client._perform_empty("PUT", "/project-folders/%s/settings" % (self.project_folder_id), body = self.settings) |
0 commit comments