ita_path_handling.m 2.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function varargout = ita_path_handling(varargin)
% handle the ITA-toolbox paths in MATLAB
%
% This function is not supposed to get triggered directly
% ita_generate_documentation needs a pathList not pathStr
%
% CALL: ita_path_handling
%       pathStr = ita_path_handling
%       [pathStr pathList] = ita_path_handling
%

% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved. 
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder. 
% </ITA-Toolbox>

%% Settings
if nargin > 0
    error('There should not be any input arguments to ita_path_handling');
end
21
ignoreList  = {'.git','.svn','private','tmp','prop-base','props','text-base','template','doc','helpers'};
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

%% toolbox prefix string
fullpath = ita_toolbox_path();
fullPathParts = regexp(fullpath,filesep,'split');
prefixToolbox = fullPathParts{end};
pathStr = genpath(fullpath);
addpath(fullpath)

%% path handling
outpathList    = regexp(pathStr,pathsep,'split');
outpathList    = outpathList(~cellfun(@isempty,outpathList)); % kick out empty entries

% kick out ignore entries
for idx=1:numel(ignoreList)
   ignoreEntries = cellfun(@strfind,outpathList,repmat(ignoreList(idx),1,numel(outpathList)),'UniformOutput',false);
   validIdx = cellfun(@isempty,ignoreEntries);
   outpathList = outpathList(validIdx); 
end

% remove first pathsep
if ~isempty(outpathList)
    ita_delete_toolboxpaths;
    warnstate = warning('off','MATLAB:dispatcher:pathWarning'); %RSC: quiet
    addpath(outpathList{:})
    warning(warnstate);
end

%% Save the path list if possible
50
51
52
53
54
55
56
57
58
59
60
ita_verbose_info('ita_path_handling::Saving path list to your users pathdef.m...',1);
upath = userpath();
if isempty(upath)
    userpath('reset');
end
if isempty(userpath())
    ita_verbose_info('Oh Lord! I cannot set your userpath. Please check if the default directory exists or manually try saving your path variable.', 0);
else
    save_state = savepath(fullfile(upath, 'pathdef.m'));
    if save_state == 1
        ita_verbose_info('Oh Lord! I could not write to your users pathdef.m', 0);
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    end
end

if nargout
    outpathStr = [];
    prefixToolboxIdx = strfind(fullpath,prefixToolbox);
    for idx = 1:numel(outpathList)
        outpathStr = [outpathStr pathsep outpathList{idx}]; %#ok<AGROW>
        outpathList{idx} = outpathList{idx}(prefixToolboxIdx:end);
    end
    
    varargout{1}=outpathStr(2:end);
    if nargout == 2
        varargout{2}=outpathList;
    end
end