-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathplugin.py
More file actions
202 lines (160 loc) · 6.93 KB
/
plugin.py
File metadata and controls
202 lines (160 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from .dataset import DSSDataset
from .recipe import DSSRecipe
from .managedfolder import DSSManagedFolder
from .savedmodel import DSSSavedModel
from .job import DSSJob
from .scenario import DSSScenario
from .apiservice import DSSAPIService
import sys
class DSSPlugin(object):
"""
A plugin on the DSS instance
"""
def __init__(self, client, plugin_id):
self.client = client
self.plugin_id = plugin_id
########################################################
# plugin upload/update as zip
########################################################
def upload(self, file_path):
"""
Upload the given file as a plugin
Note: this call requires an API key with admin rights
:param: file_path : the path to the zip file of the plugin
"""
with open(file_path, 'rb') as f:
return self.client._perform_json_upload("POST", "/plugins/%s/upload" % (self.plugin_id), 'plugin.zip', f).text
def update(self, file_path):
"""
Update the plugin with the given file
Note: this call requires an API key with admin rights
:param: file_path : the path to the zip file of the plugin
"""
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
########################################################
def list_files(self):
"""
Get the hierarchy of files in the plugin
Returns:
the plugins's contents
"""
return self.client._perform_json("GET", "/plugins/%s/contents" % (self.plugin_id))
def get_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("GET", "/plugins/%s/contents/%s" % (self.plugin_id, path)).raw
def put_file(self, path, f):
"""
Update a file in the plugin folder
Args:
f: the file contents, as a stream
path: the name of the file, from the root of the plugin
"""
file_name = path.split('/')[-1]
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})