-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathaddplotlystartup.m
More file actions
59 lines (57 loc) · 2.89 KB
/
Copy pathaddplotlystartup.m
File metadata and controls
59 lines (57 loc) · 2.89 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
function [warnings] = addplotlystartup(startupPaths)
%[1]looks at startup.m files specified by the entries of startupPaths
%[2]appends the addplotly function to startup.m files (if not already
% present)
%[3]checks for other plotly addpath calls within any startup.m and
% outputs warning
%output warnings
warnings = cell(size(startupPaths));
for locs = 1:size(startupPaths,1);
%addpath string for Plotly API
addString = ['addpath(genpath(fullfile(matlabroot,''toolbox'',' ...
'''plotly'')),''-end'');'];
%open current startup.m to read
currentStartupID = fopen(startupPaths{locs},'r');
if currentStartupID == -1, error('plotly:startupRead', ...
['\n\nShoot! It looks like something went wrong ' ...
'reading the file: \n' startupPaths{locs} '\n\n' ...
'Please contact your system admin or post a topic on ' ...
'https://community.plotly.com/c/api/matlab/ for more ' ...
'\ninformation. In the mean time you can add the ' ...
'Plotly API \nto your search path manually whenever ' ...
'you need it! \n\n']);
end
%check for any instances of the addplotlyapi function
startupScan = textscan(currentStartupID, '%s', 'delimiter', ...
'\n', 'whitespace', '');
startupLines = startupScan{1};
Index = find(strcmp(startupLines,addString));
otherPlotlyOccurrence = findstr(fileread(startupPaths{locs}), ...
'plotly');
%if addString is not in startup.m add it
if (~any(Index))
%reopen current startup.m with new permission
currentStartupID = fopen(startupPaths{locs},'a+');
if currentStartupID == -1
error('plotly:startupWrite', ['\n\nShoot! It looks ' ...
'like something went wrong writing to the ' ...
'file: \n\n' startupPaths{locs} '\n\nPlease ' ...
'contact your system admin or post a topic on ' ...
'https://community.plotly.com/c/api/matlab/ ' ...
'for more \ninformation. In the mean time you ' ...
'can add the Plotly API \nto your search path ' ...
'manually whenever you need it! \n']);
end
fprintf(currentStartupID,['\n' addString]);
end
if (length(Index) ~= length(otherPlotlyOccurrence))
warnings{locs} = ['\n[WARNING]: \n\nWe found an addpath ' ...
'specification for another version of Plotly at: ' ...
'\n\n' startupPaths{locs} '\n\nyou may be forcing ' ...
'MATLAB to look for an older version of Plotly!\n\n'];
else
warnings{locs} = '';
end
fclose(currentStartupID);
end
end