Skip to content
Closed
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
19 changes: 15 additions & 4 deletions dataikuapi/dss/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import re
import os.path as osp
from .future import DSSFuture
from dataikuapi.utils import DataikuException
Expand Down Expand Up @@ -40,7 +41,8 @@ def create_instance(self, instance_key, instance_name, wait=True):
return future

def make_random_project_key(self):
return "%s_tmp_%s" % (self.app_id, random_string(10))
slugified_app_id = re.sub(r'[^A-Za-z_0-9]+', '_', self.app_id)
return "%s_tmp_%s" % (slugified_app_id, random_string(10))

def create_temporary_instance(self):
"""
Expand Down Expand Up @@ -77,15 +79,17 @@ def get_instance(self, instance_key):

def get_manifest(self):
raw_data = self.client._perform_json("GET", "/apps/%s/" % self.app_id)
return DSSAppManifest(self.client, raw_data)
project_key = self.app_id[8:] if self.app_id.startswith('PROJECT_') else None
return DSSAppManifest(self.client, raw_data, project_key)


class DSSAppManifest(object):

def __init__(self, client, raw_data):
def __init__(self, client, raw_data, project_key=None):
"""The manifest for an app. Do not create this class directly"""
self.client = client
self.raw_data = raw_data
self.project_key = project_key

def get_raw(self):
return self.raw_data
Expand All @@ -97,6 +101,13 @@ def get_runnable_scenarios(self):
"""Return the scenario identifiers that are declared as actions for this app"""
return [x["scenarioId"] for x in self.get_all_actions() if x["type"] == "SCENARIO_RUN"]

def save(self):
"""Saves the changes to this manifest object back to the template project"""
if self.project_key is None:
raise Exception("This manifest object wasn't created from a project, cannot be saved back")
self.client._perform_empty("PUT", "/projects/%s/app-manifest" % self.project_key, body=self.raw_data)


class DSSAppInstance(object):

def __init__(self, client, project_key):
Expand Down Expand Up @@ -124,7 +135,7 @@ def __init__(self, client, project_key):


def close(self):
self.get_as_project().delete()
self.get_as_project().delete(drop_data=True)

def __enter__(self,):
return self
Expand Down
Loading