forked from plotly/plotly_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotlycleanup.m
More file actions
98 lines (74 loc) · 3.03 KB
/
plotlycleanup.m
File metadata and controls
98 lines (74 loc) · 3.03 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
function removed = plotlycleanup
% cleans up any old Plotly API MATLAB library files and folders
% initialize output
removed = {};
%----REMOVE WRAPPER FILES----%
REMOVEFILES = {'plotly.m'};
%----REMOVE WRAPPER FOLDERS----%
REMOVEFOLDERS = {'fig2plotly_aux'};
%----check for local Plotly instances----%
try
plotlyScriptDirs = which('plotly.m','-all');
if isempty(plotlyScriptDirs);
error('plotly:missingScript',...
['\n\nWe were unable to locate plotly.m. Please Add this\n',...
'script to your MATLAB search path and try again.\n\n']);
end
catch exception %locating plotly error catch...
fprintf(['\n\n' exception.identifier exception.message '\n\n']);
return
end
% plotly toolbox directory
plotlyToolboxDir = fullfile(matlabroot,'toolbox','plotly');
% find the location of all plotly/ directories
dircount = 1;
for d = 1:length(plotlyScriptDirs)
%parse filepath string at the Plotly directory
plotlyLoc = strfind(fileparts(plotlyScriptDirs{d}),fullfile('MATLAB-api-master','plotly'));
plotlyToolboxLoc = strfind(fileparts(plotlyScriptDirs{d}),plotlyToolboxDir);
if ~isempty(plotlyLoc)
plotlyDirs{dircount} = fullfile(plotlyScriptDirs{d}(1:plotlyLoc-1),'MATLAB-api-master','plotly');
dircount = dircount + 1;
elseif ~isempty(plotlyToolboxLoc)
plotlyDirs{dircount} = plotlyToolboxDir;
dircount = dircount + 1;
end
end
for d = 1:length(plotlyDirs)
% add plotlydirs to searchpath (will be removed in future once handled by plotlyupdate)
addpath(genpath(plotlyDirs{d}));
% delete files from plotly directory
removefiles = fullfile(plotlyDirs{d}, REMOVEFILES);
for f = 1:length(removefiles)
% remove removefiles filepath from searchpath
rmpath(fileparts(removefiles{f}));
if exist(removefiles{f},'file')
delete(removefiles{f});
% update removed list
removed = [removed removefiles{f}];
end
% add removefiles filepath back to searchpath
addpath(fileparts(removefiles{f}));
end
% remove folders from plotly directory
removefolders = fullfile(plotlyDirs{d},REMOVEFOLDERS);
for f = 1:length(removefolders)
if exist(removefolders{f},'dir')
%remove folder from path
rmpath(genpath(removefolders{f}));
%delete folder/subfolders
try
status = rmdir(removefolders{f},'s');
if (status == 0)
error('plotly:deletePlotlyAPI',...
['\n\nShoot! It looks like something went wrong removing the Plotly API ' ...
'from the MATLAB toolbox directory \n' ...
'Please contact your system admin. or chuck@plot.ly for more information. \n\n']);
end
% update removed list
removed = [removed removefolders{f}];
end
end
end
end
end