Skip to content

Commit

Permalink
Requested Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tpfau committed Mar 21, 2018
1 parent 1ae222e commit 170f782
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion initCobraToolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function initCobraToolbox()
end

%get the current content of the init Folder
dirContent = getFilesInDir('gitTypeFlag','all');
dirContent = getFilesInDir('type','all');

% add the folders of The COBRA Toolbox
folders = {'tutorials', 'papers', 'binary', 'deprecated', 'src', 'test', '.tmp'};
Expand Down
41 changes: 25 additions & 16 deletions src/base/install/getFilesInDir.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function files = getFilesInDir(varargin)
% List all files in the supplied (git tracked) Directory with their absolute path name
% based on the git ls-file command. If the directory is not git controlled, the
% gitTypeFlag is assumed to be 'all' and all files (except for .git files
% type is assumed to be 'all' and all files (except for .git files
% will be returned).
%
% USAGE:
Expand All @@ -12,7 +12,7 @@
% options are:
% dirToList - the directory to list the files for,
% (Default: The current working directory)
% gitTypeFlag - Git type of files to return
% type - Git type of files to return
% 'tracked' - Only tracked files
% 'ignored' - Only git ignored files
% including files that are tracked but
Expand All @@ -24,8 +24,10 @@
% and not tracked. (new files)
% 'all' - all files except for the git
% specific files (e.g. .git, .gitignore etc).
% 'COBRAIgnored' - use the COBRA Toolbox .gitignore
% file to determine the ignored files.
% 'ignoredByCOBRA' - use the COBRA Toolbox .gitignore
% file. Only return those
% files which match
% patterns specified there.
% Slower than 'ignored',
% since all files have to
% be manually checked
Expand All @@ -40,53 +42,60 @@
% empty. (Default: '', i.e. ignored)
% checkSubFolders - check the subfolders of the current
% directory. (Default: true)
%
%
% OUTPUTS:
% files: A Cell Array of files with absolute file pathes.
% present in this folder matching the options choosen.
%
% EXAMPLES:
% Get all m files in the source folder:
% files = getFilesInDir('dirToList', [CBTDIR filesep 'src'], 'restrictToPattern', '\.m$');
% Get the git tracked files in the test Directory.
% files = getFilesInDir('dirToList', [CBTDIR filesep 'test'], 'gitTypeFlag', 'tracked');
% files = getFilesInDir('dirToList', [CBTDIR filesep 'test'], 'type', 'tracked');
% Get all git tracked files which start with "MyFile" in the current directory
% files = getFilesInDir('gitTypeFlag', 'tracked', 'restrictToPattern', '^MyFile');
% files = getFilesInDir('type', 'tracked', 'restrictToPattern', '^MyFile');
% Get only the gitIgnored files in the current folder
% files = getFilesInDir('gitTypeFlag', 'ignored');
% files = getFilesInDir('type', 'ignored');

persistent COBRAIgnored

if isempty(COBRAIgnored)
COBRAIgnored = regexptranslate('wildcard',getIgnoredFiles());
end

gitFileTypes = {'tracked','all','untracked','ignored','COBRAIgnored'};
gitFileTypes = {'tracked','all','untracked','ignored','ignoredByCOBRA'};
parser = inputParser();
parser.addParamValue('dirToList',pwd,@(x) exist(x,'file') == 7);
parser.addParamValue('gitTypeFlag','all',@(x) ischar(x) && any(strcmpi(x,gitFileTypes)));
parser.addParamValue('type','all',@(x) ischar(x) && any(strcmpi(x,gitFileTypes)));
parser.addParamValue('restrictToPattern','',@(x) ischar(x));
parser.addParamValue('checkSubFolders','',@(x) islogical(x) || (isnumeric(x) && x == 0 || x == 1));

parser.parse(varargin{:});

%get the absolute path of the files that are listed

currentDir = cd(parser.Results.dirToList);

%get the absolute path to the folder to be listed.
absPath = pwd;

%get all files in the directory.
gitType = lower(parser.Results.gitTypeFlag);
selectedType = parser.Results.type;

%test, whether the folder is git controlled
[gitStatus,~] = system('git status');
if gitStatus ~= 0 && ~strcmpi(gitType,'cobraignored')
gitType = 'all';
if gitStatus ~= 0 && ~strcmpi(selectedType,'ignoredByCOBRA')
selectedType = 'all';
end
if gitStatus == 0 && strcmpi(gitType,'cobraignored')
if gitStatus == 0 && strcmpi(selectedType,'ignoredByCOBRA')
[~,repos] = system('git remote -v');
if any(cellfun(@(x) ~isempty(strfind(x,'cobratoolbox.git')),strsplit(repos,'\n')))
%So, we are on a COBRA repo. lets just use the ignored option
gitType = 'ignored';
selectedType = 'ignored';
end
end

switch gitType
switch selectedType
case 'all'
if gitStatus == 0
[status, trackedfiles] = system('git ls-files');
Expand Down
7 changes: 4 additions & 3 deletions src/base/install/removeTempFiles.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
function removeTempFiles(directory, oldcontent, varargin)
function status = removeTempFiles(directory, oldcontent, varargin)
% Removes all files that are in the specified directory but not part of
% the oldcontent. By default only removes those files which match files
% mentioned in the COBRA .gitignore file.
%
% USAGE:
% removeTempFiles(directory, oldcontent, varargin)
% status = removeTempFiles(directory, oldcontent, varargin)
%
% INPUT:
% directory: The directory which should be checked for changing files.
Expand Down Expand Up @@ -35,7 +36,7 @@ function removeTempFiles(directory, oldcontent, varargin)
end

% get the new Content of the folder.
newContent = getFilesInDir('gitTypeFlag',gitTypeFlag,'checkSubFolders',checkSubFolders);
newContent = getFilesInDir('type',gitTypeFlag,'checkSubFolders',checkSubFolders);

% get all .log files that were present only after initCobraToolbox was called.
newIgnoredFiles = setdiff(newContent, oldcontent);
Expand Down
2 changes: 1 addition & 1 deletion src/base/solvers/changeCobraSolver.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
%actually set i.e. initCobraToolbox is called before). This is only
%necessary, if the solver is being validated.
if validationLevel == 1
origFiles = getFilesInDir('gitTypeFlag','COBRAIgnored','checkSubFolders',false);
origFiles = getFilesInDir('type','ignoredByCOBRA','checkSubFolders',false);
finish = onCleanup(@() removeTempFiles(pwd, origFiles,'checkSubFolders',false));
end
% configure the environment variables
Expand Down
2 changes: 1 addition & 1 deletion test/testAll.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

%Init the cleanup:
currentDir = cd('test');
testDirContent = getFilesInDir('gitTypeFlag','all'); %Get all currently present files in the folder.
testDirContent = getFilesInDir('type','all'); %Get all currently present files in the folder.
testDirPath = pwd;
cd(currentDir);

Expand Down

0 comments on commit 170f782

Please sign in to comment.