Commit f314a7bc authored by jayd1860's avatar jayd1860
Browse files

-- Greatly simplify and make it more straighfoward the setpaths process.

-- Add .numberfiles to submodules and check during setpaths process to make sure an incomplete download is detected and triggers a clean download.
parent ed93e886
Loading
Loading
Loading
Loading
Compare 06abb78a to 25e07119
Original line number Diff line number Diff line
Subproject commit 06abb78afc8905e1862c9913078716048ad1ff38
Subproject commit 25e07119db1607bd4d5d7ae440dbde310e1dd6a6
Compare 3df13ee0 to 4a556753
Original line number Diff line number Diff line
Subproject commit 3df13ee056e0b89f1b28652907c7154e3ae4e811
Subproject commit 4a556753be082a39f9c4fd34c222d455a98073c9
+36 −2
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ s = parseGitSubmodulesFile();
% Check for missing libs
kk = checkMissingLibraries(s);
if isempty(kk) && optionExists_startup(options, 'init')
    addSearchPaths(s);
    return;
end

@@ -24,6 +25,7 @@ end
% Check again for missing libs
kk = checkMissingLibraries(s);
if isempty(kk) && (optionExists_startup(options, 'init') || all(errs==0))
    addSearchPaths(s);
    return;
end

@@ -41,6 +43,7 @@ end
kk = checkMissingLibraries(s);
if isempty(kk)
    errs = 0;
    addSearchPaths(s);
    return;
end

@@ -60,7 +63,8 @@ end
function kk = checkMissingLibraries(s)
kk = [];
for ii = 1:size(s,1)
    if isemptyFolder(s{ii,3})
    if isIncompleteSubmodule(s{ii,3})
        removeFolderContents(s{ii,3});
        kk = [kk, ii]; %#ok<AGROW>
    end    
end
@@ -101,3 +105,33 @@ msg = [msg{:}];
q = menu(msg, {'Quit setpaths, install git and rerun setpaths','Download submodules manually and provide their locations'});




% ----------------------------------------------------------
function addSearchPaths(s)
kk = [];
exclSearchList  = {'.git'};
for ii = 1:size(s,1)
    foo = findDotMFolders(s{ii,3}, exclSearchList);
    for kk = 1:length(foo)
        addpath(foo{kk}, '-end');
        setpermissions(foo{kk});
    end
end




% ---------------------------------------------------
function setpermissions(appPath)
if isunix() || ismac()
    if ~isempty(strfind(appPath, '/bin'))
        fprintf(sprintf('chmod 755 %s/*\n', appPath));
        files = dir([appPath, '/*']);
        if ~isempty(files)
            system(sprintf('chmod 755 %s/*', appPath));
        end
    end
end

+43 −0
Original line number Diff line number Diff line
function files = findAllFiles(subdir)
files = {};
if ~exist('subdir','var')
    subdir = pwd;
end
if ~ispathvalid_startup(subdir, 'dir')
    fprintf('Warning: folder %s doesn''t exist under %s\n', subdir, pwd);
    return;
end
if strcmp(subdir, '.')
    return
end
if strcmp(subdir, '..')
    return
end
if strcmp(subdir, '.git')
    return
end

% If current subjdir is in the exclList then go back to curr dir and exit
subdirFullpath = filesepStandard_startup(subdir,'full');
f = dir([subdirFullpath, '*']);
for ii = 1:length(f)
    if strcmp(f(ii).name, '.')
        continue
    end
    if strcmp(f(ii).name, '..')
        continue
    end
    if strcmp(f(ii).name, '.git')
        continue
    end
    if strcmp(f(ii).name, '.numberfiles')
        continue
    end
    
    if ~f(ii).isdir
        files{end+1,1} = filesepStandard_startup(sprintf('%s%s%s', subdirFullpath, f(ii).name), 'nameonly');        
    else
        files = [files; findAllFiles([subdirFullpath, f(ii).name])];
    end
end
+91 −0
Original line number Diff line number Diff line
function dotmfolders = findDotMFolders(subdir, exclList)
dotmfolders = {};

if ~exist('subdir','var')
    subdir = pwd;
end
if ~exist('exclList','var')
    exclList = {};
end

if ~iscell(exclList)
    exclList = {exclList};
end

subdirFullpath = filesepStandard_startup(subdir,'full');

if ~ispathvalid_startup(subdirFullpath, 'dir')
    fprintf('Warning: folder %s doesn''t exist\n', subdirFullpath);
    return;
end

% If current subjdir is in the exclList then go back to curr dir and exit
if isExcluded(subdirFullpath, exclList)
    return;
end

dirs = dir([subdirFullpath, '*']);
if isempty(dirs)
    return;
end

if isdotmfolder(subdirFullpath)
    dotmfolders = {filesepStandard_startup(subdirFullpath, 'nameonly')};
end

for ii = 1:length(dirs)
    if ~dirs(ii).isdir
        continue;
    end
    if strcmp(dirs(ii).name, '.')
        continue;
    end
    if strcmp(dirs(ii).name, '..')
        continue;
    end
    if strcmp(dirs(ii).name, '.numberfiles')
        continue;
    end
    dotmfolders = [dotmfolders; findDotMFolders([subdirFullpath, dirs(ii).name], exclList)];
end





% -------------------------------------------------------------------------
function b = isdotmfolder(folder)
b = false;
if ~ispathvalid_startup(folder, 'dir')
    return
end
if isempty(ls([folder,'/*.m']))
    % Exceptions to rule that 'dotm' folder must have at least one '.m' file: 
    % it is a an executable folder (i.e. '/bin')
    if ~isempty(strfind(folder, '/bin/'))
        b = true;
        return
    end
    return;
end
b = true;




% -------------------------------------------------------------------------
function b = isExcluded(pname, exclList)
b = true;
if pname(end)=='/'
    pname(end) = '';
end
[~,f,e] = fileparts(pname);
for ii = 1:length(exclList)
    if strcmp(exclList{ii}, [f,e])
        return;
    end
end
b = false;


Loading