|
1 | | -%-----AUTOMATIC PLOTLY MATLAB API UPDATING-----% |
2 | | - |
3 | | -function plotlyupdate(varargin) |
4 | | - |
5 | | -% plotlyupdate.m automatically updates the Plotly |
6 | | -% API MATLAB library if the current version is not |
7 | | -% up to date. The new version replaces all instances |
8 | | -% of the Plotly API MATLAB library in the users |
9 | | -% search path. |
10 | | - |
11 | | -%successful update switch |
12 | | -success = true; |
13 | | - |
14 | | -%check for verbose |
15 | | -verbose = any(strcmp(varargin,'verbose')); |
16 | | - |
17 | | -%check for nocheck :) |
18 | | -nocheck = any(strcmp(varargin,'nocheck')); |
19 | | - |
20 | | -%default output |
21 | | -exception.identifier = ''; |
22 | | -exception.message = ''; |
23 | | - |
24 | | -%----check for necessary update----% |
25 | | -try |
26 | | - % local version number |
27 | | - pvLocal = plotly_version; |
28 | | -catch |
29 | | - exception.identifier = 'plotly:noVersion'; |
30 | | - fprintf(['\n' exception.identifier '\n\nWe were unable to locate plotly_version.m. Please Add\n',... |
31 | | - 'this script to your MATLAB search path and try again.\n\n']); |
32 | | - return |
33 | | -end |
34 | | - |
35 | | -% remote Plotly API MATLAB Library url |
36 | | -remote = ['https://raw.githubusercontent.com/plotly/MATLAB-api/',... |
37 | | - 'master/README.md']; |
38 | | - |
39 | | -% remote Plotly API MATLAB Library |
40 | | -try |
41 | | - pvContent = urlread(remote); |
42 | | -catch |
43 | | - fprintf(['\nAn error occurred while trying to read the latest\n',... |
44 | | - 'Plotly API MATLAB Library version number from:\n',... |
45 | | - 'https://github.com/plotly/MATLAB-api.\n',... |
46 | | - 'Please check your internet connection or\n',... |
47 | | - 'contact [email protected] for further assistance.\n\n']); |
48 | | - return |
49 | | -end |
50 | | - |
51 | | -% remote version number |
52 | | -[pvBounds(1), pvBounds(2)] = regexp(pvContent,'\d+.\d+.\d+', 'once'); |
53 | | -pvRemote = pvContent(pvBounds(1):pvBounds(2)); |
54 | | - |
55 | | -%----check for local Plotly instances----% |
56 | | -try |
57 | | - plotlyScriptDirs = which('plotly.m','-all'); |
58 | | - |
59 | | - if isempty(plotlyScriptDirs); |
60 | | - error('plotly:missingScript',... |
61 | | - ['\n\nWe were unable to locate plotly.m. Please Add this\n',... |
62 | | - 'script to your MATLAB search path and try again.\n\n']); |
63 | | - end |
64 | | - |
65 | | -catch exception |
66 | | - fprintf(['\n' exception.identifier exception.message]); |
67 | | - return |
68 | | -end |
69 | | - |
70 | | -% plotly toolbox directory |
71 | | -plotlyToolboxDir = fullfile(matlabroot,'toolbox','plotly'); |
72 | | - |
73 | | -% find the location of all plotly/ directories |
74 | | -dircount = 1; |
75 | | -plotlyDirs = {}; |
76 | | -for d = 1:length(plotlyScriptDirs) |
77 | | - %parse filepath string at the Plotly directory |
78 | | - plotlyLoc = strfind(fileparts(plotlyScriptDirs{d}),fullfile('MATLAB-api-master','plotly')); |
79 | | - plotlyToolboxLoc = strfind(fileparts(plotlyScriptDirs{d}),plotlyToolboxDir); |
80 | | - if ~isempty(plotlyLoc) |
81 | | - plotlyDirs{dircount} = fullfile(plotlyScriptDirs{d}(1:plotlyLoc-1),'MATLAB-api-master','plotly'); |
82 | | - dircount = dircount + 1; |
83 | | - elseif ~isempty(plotlyToolboxLoc) |
84 | | - plotlyDirs{dircount} = plotlyToolboxDir; |
85 | | - dircount = dircount + 1; |
86 | | - end |
87 | | -end |
88 | | - |
89 | | -if isempty(plotlyDirs) |
90 | | - error('It seems your plotly wrapper directory structure has changed. Update aborted.'); |
91 | | -end |
92 | | - |
93 | | -%----update if necessary----% |
94 | | -if strcmp(pvLocal,pvRemote) |
95 | | - fprintf(['\nYour Plotly API MATLAB Library v.' pvRemote ' is already up to date! \n\n']) |
96 | | - exception.identifier = 'plotly:alreadyUpdated'; |
97 | | - return |
98 | | -else |
99 | | - |
100 | | - if nocheck |
101 | | - |
102 | | - fprintf('\n************************************************\n'); |
103 | | - fprintf(['[UPDATING] Plotly v.' pvLocal ' ----> Plotly v.' pvRemote ' \n']); |
104 | | - fprintf('************************************************\n'); |
105 | | - |
106 | | - %----create temporary update folder----% |
107 | | - try |
108 | | - |
109 | | - %temporary update folder location |
110 | | - plotlyUpdateDir = fullfile(pwd,['plotlyupdate_' pvRemote]); |
111 | | - |
112 | | - if verbose |
113 | | - fprintf(['\nCreating temporary update directory: ' plotlyUpdateDir ' ... ']); |
114 | | - end |
115 | | - |
116 | | - %----make plotlyUpdateDir----% |
117 | | - status = mkdir(plotlyUpdateDir); |
118 | | - |
119 | | - if verbose |
120 | | - fprintf('Done! \n'); |
121 | | - end |
122 | | - |
123 | | - if (status == 0) |
124 | | - error('plotlyupdate:makeUpdateDir',... |
125 | | - ['\n\nShoot! It looks like something went wrong while making',... |
126 | | - 'the Plotly Update Directory. \n Please contact your system ',... |
127 | | - 'admin. or [email protected] for more information. \n\n']); |
128 | | - end |
129 | | - |
130 | | - catch exception |
131 | | - fprintf(['\n\n' exception.identifier exception.message]); |
132 | | - % update failed |
133 | | - success = false; |
134 | | - end |
135 | | - |
136 | | - %----download plotly----% |
137 | | - if success |
138 | | - try |
139 | | - if verbose |
140 | | - fprintf(['Downloading the Plotly API Matlab Library v.' pvRemote ' ... ']); |
141 | | - end |
142 | | - |
143 | | - newPlotlyUrl = 'https://github.com/plotly/MATLAB-api/archive/master.zip'; |
144 | | - newPlotlyZip = fullfile(plotlyUpdateDir,['plotlyupdate_' pvRemote '.zip']); |
145 | | - |
146 | | - %download from url |
147 | | - urlwrite(newPlotlyUrl,newPlotlyZip); |
148 | | - |
149 | | - if verbose |
150 | | - fprintf('Done! \n'); |
151 | | - end |
152 | | - |
153 | | - catch |
154 | | - fprintf('\n\nAn error occured while downloading the newest version of Plotly\n\n'); |
155 | | - % update failed |
156 | | - success = false; |
157 | | - end |
158 | | - end |
159 | | - |
160 | | - %----unzip updated plotly----% |
161 | | - if success |
162 | | - try |
163 | | - if verbose |
164 | | - fprintf(['Unzipping the Plotly API Matlab Library v.' pvRemote ' ... ']); |
165 | | - end |
166 | | - |
167 | | - unzip(newPlotlyZip,plotlyUpdateDir); |
168 | | - |
169 | | - if verbose |
170 | | - fprintf('Done! \n'); |
171 | | - end |
172 | | - |
173 | | - catch exception |
174 | | - fprintf('\n\nAn error occured while unzipping the newest version of Plotly\n\n'); |
175 | | - %update failed |
176 | | - success = false; |
177 | | - end |
178 | | - end |
179 | | - |
180 | | - %----replace all instances of plotly----% |
181 | | - if success |
182 | | - try |
183 | | - if verbose |
184 | | - fprintf(['Updating the Plotly API Matlab Library v.' pvLocal ' ... ']); |
185 | | - end |
186 | | - |
187 | | - % new Plotly directory |
188 | | - newPlotlyDir = fullfile(plotlyUpdateDir,'MATLAB-api-master','plotly'); |
189 | | - |
190 | | - % files in Plotly repo root |
191 | | - repoRoot = dir(fullfile(plotlyUpdateDir,'MATLAB-api-master')); |
192 | | - |
193 | | - % files not to be included |
194 | | - repoExclude = {'.','..','.gitignore','plotly'}; |
195 | | - |
196 | | - % aux Plotly repo root files |
197 | | - d = 1; |
198 | | - for r = 1:length(repoRoot); |
199 | | - if(isempty(intersect(repoRoot(r).name,repoExclude))) |
200 | | - auxFiles{d} = fullfile(plotlyUpdateDir,'MATLAB-api-master',repoRoot(r).name); |
201 | | - d = d+1; |
202 | | - end |
203 | | - end |
204 | | - |
205 | | - % remove old plotlyclean scripts |
206 | | - pcScripts = which('plotlycleanup.m','-all'); |
207 | | - |
208 | | - for d = 1:length(pcScripts) |
209 | | - |
210 | | - % remove plotlycleanup path from searchpath |
211 | | - rmpath(fileparts(pcScripts{d})); |
212 | | - |
213 | | - % delete plotlycleanup! |
214 | | - delete(pcScripts{d}); |
215 | | - |
216 | | - % add plotlycleanup path to searhpath |
217 | | - addpath(fileparts(pcScripts{d})); |
218 | | - |
219 | | - end |
220 | | - |
221 | | - % replace the old Plotly with the new Plotly |
222 | | - for d = 1:length(plotlyDirs) |
223 | | - |
224 | | - % do not copy aux Plotly repo root files to toolbox dir. Plotly |
225 | | - if ~strcmp(plotlyDirs{d},plotlyToolboxDir) |
226 | | - |
227 | | - % aux files destination |
228 | | - auxFileDest = fileparts(plotlyDirs{d}); |
229 | | - |
230 | | - % copy aux to appropriate destination |
231 | | - for r = 1:length(auxFiles) |
232 | | - copyfile(auxFiles{r},auxFileDest,'f'); |
233 | | - end |
234 | | - |
235 | | - end |
236 | | - |
237 | | - % copy actual Plotly API Matlab Library |
238 | | - copyfile(newPlotlyDir,plotlyDirs{d},'f'); |
239 | | - |
240 | | - % add new scripts to path! |
241 | | - addpath(genpath(plotlyDirs{d})); |
242 | | - |
243 | | - %rehash toolbox |
244 | | - rehash toolboxreset |
245 | | - end |
246 | | - |
247 | | - if verbose |
248 | | - fprintf('Done! \n'); |
249 | | - end |
250 | | - |
251 | | - catch exception |
252 | | - fprintf(['\n\nAn error occured while updating to the newest version \n',... |
253 | | - 'of Plotly v.' pvRemote '. Please check your write permissions\n',... |
254 | | - 'for your outdated Plotly directories with your system admin.\n',... |
255 | | - 'Contact [email protected] for more information.\n\n']); |
256 | | - % update failed |
257 | | - success = false; |
258 | | - end |
259 | | - end |
260 | | - |
261 | | - %----clean up old Plotly wrapper scipts----% |
262 | | - if success |
263 | | - try |
264 | | - if verbose |
265 | | - fprintf('Cleaning up outdated Plotly API MATLAB library scripts ... '); |
266 | | - end |
267 | | - |
268 | | - %run cleanup |
269 | | - removed = plotlycleanup; |
270 | | - |
271 | | - if verbose |
272 | | - fprintf('Done! \n'); |
273 | | - if ~isempty(removed) |
274 | | - fprintf('The following Plotly scripts were removed:\n'); |
275 | | - % explicitly state the removed files |
276 | | - for r = 1:length(removed) |
277 | | - fprintf([removed{r} '\n']); |
278 | | - end |
279 | | - end |
280 | | - end |
281 | | - catch exception |
282 | | - fprintf([exception '\n\nAn error occured while cleaning up the outdated Plotly scripts. Please\n',... |
283 | | - 'check your write permissions for your outdated Plotly directories with \n',... |
284 | | - 'your system admin. Contact [email protected] for more information.\n\n']); |
285 | | - end |
286 | | - end |
287 | | - |
288 | | - %----delete update directory-----% |
289 | | - if exist(plotlyUpdateDir,'dir') |
290 | | - try |
291 | | - if verbose |
292 | | - fprintf(['Removing temporary update directory: ' plotlyUpdateDir ' ... ']); |
293 | | - end |
294 | | - |
295 | | - % delete temp update dir. |
296 | | - rmdir(plotlyUpdateDir,'s'); |
297 | | - |
298 | | - if verbose |
299 | | - fprintf('Done! \n'); |
300 | | - end |
301 | | - |
302 | | - catch exception |
303 | | - fprintf(['\n\n An error occured while attempting to remove',... |
304 | | - ' the \n temporary update directory. Please remove manually.\n\n']); |
305 | | - end |
306 | | - end |
307 | | - |
308 | | - %----successful update----% |
309 | | - if success |
310 | | - if exist(fullfile(matlabroot,'toolbox','plotly'),'dir') |
311 | | - fprintf('\n**************************************************\n'); |
312 | | - fprintf(['[UPDATE SUCCESSFUL] visit: https://plot.ly/matlab \n',... |
313 | | - 'or contact: [email protected] for further information.\n'... |
314 | | - 'Please restart your MATLAB session so that the new\n',... |
315 | | - 'Plotly API MATLAB Libary scripts can be recognized.\n']); |
316 | | - fprintf('**************************************************\n\n'); |
317 | | - else |
318 | | - fprintf('\n**************************************************\n'); |
319 | | - fprintf(['[UPDATE SUCCESSFUL] visit: https://plot.ly/matlab \n',... |
320 | | - 'or contact: [email protected] for further information.\n']); |
321 | | - fprintf('**************************************************\n\n'); |
322 | | - end |
323 | | - else |
324 | | - fprintf('\n***************************************************\n'); |
325 | | - fprintf(['[UPDATE UNSUCCESSFUL] visit: https://plot.ly/matlab \n',... |
326 | | - 'or contact: [email protected] for further information. \n']); |
327 | | - fprintf('***************************************************\n\n'); |
328 | | - end |
329 | | - |
330 | | - else %check |
331 | | - |
332 | | - fprintf(['\nYou are about to update your Plotly API MATLAB Library v.' pvLocal ', which will\n',... |
333 | | - 'overwrite modifications made to the Plotly scripts in the following directories:\n\n']); |
334 | | - |
335 | | - % explicitly output directories |
336 | | - for d = 1:length(plotlyDirs) |
337 | | - fprintf([plotlyDirs{d} '\n']); |
338 | | - end |
339 | | - |
340 | | - overwrite = input('\nProceed with update (y/n) ? : ','s'); |
341 | | - |
342 | | - if(strcmpi(overwrite,'y')) |
343 | | - if verbose |
344 | | - if nargout |
345 | | - plotlyupdate('verbose','nocheck'); |
346 | | - else |
347 | | - plotlyupdate('verbose','nocheck'); |
348 | | - end |
349 | | - else |
350 | | - if nargout |
351 | | - plotlyupdate('nocheck'); |
352 | | - else |
353 | | - plotlyupdate('nocheck'); |
354 | | - end |
355 | | - end |
356 | | - else |
357 | | - fprintf('\n***********************************************\n'); |
358 | | - fprintf(['[UPDATE ABORTED] visit: https://plot.ly/matlab \n',... |
359 | | - 'or contact: [email protected] for more information. \n']); |
360 | | - fprintf('***********************************************\n\n'); |
361 | | - end |
362 | | - end |
363 | | -end |
364 | | - |
365 | | -end |
| 1 | +error('Automatic updates are currently disabled. Please see: https://github.com/plotly/MATLAB-Online for updates.'); |
0 commit comments