Mercurial > repos > public > matlab_path_manager
changeset 21:02c290e2018c
Refactor ui functions to use the MPM class. Not tested
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 17 Sep 2018 15:49:39 +0200 |
parents | ddf75f18509f |
children | 29da718b8e7f |
files | +mpm/checkin.m +mpm/checkout.m +mpm/clear.m +mpm/info.m +mpm/subpaths.m +mpm/verify.m |
diffstat | 6 files changed, 21 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/+mpm/checkin.m Mon Sep 17 15:46:16 2018 +0200 +++ b/+mpm/checkin.m Mon Sep 17 15:49:39 2018 +0200 @@ -1,17 +1,9 @@ -% Set project to current folder -function set(d) - if ~exist('d', 'var') || isempty(d) - d = ''; +% Checkin a projects subpaths to the matlab path +function checkin(projectFolder) + if ~exist('projectFolder', 'var') || isempty(projectFolder) + projectFolder = pwd; end - state = mpm.load_state(); - - sp = mpm.subpaths(d); - for i = 1:length(sp) - subpath = fullfile(pwd, sp{i}); - addpath(subpath); - state.added_paths(subpath) = true; - end - - mpm.save_state(state); + m = mpm.MatlabPathManager(); + m.checkin(projectFolder); end
--- a/+mpm/checkout.m Mon Sep 17 15:46:16 2018 +0200 +++ b/+mpm/checkout.m Mon Sep 17 15:49:39 2018 +0200 @@ -1,17 +1,9 @@ -% Leave project in current folder -function leave(d) - if ~exist('d', 'var') || isempty(d) - d = ''; +% Checkout a projects subpaths from the matlab path +function checkout(projectFolder) + if ~exist('projectFolder', 'var') || isempty(projectFolder) + projectFolder = pwd; end - state = mpm.load_state(); - - sp = mpm.subpaths(d); - for i = 1:length(sp) - subpath = fullfile(pwd, sp{i}); - rmpath(subpath); - state.added_paths.remove(subpath); - end - - mpm.save_state(state); + m = mpm.MatlabPathManager(); + m.checkout(projectFolder); end
--- a/+mpm/clear.m Mon Sep 17 15:46:16 2018 +0200 +++ b/+mpm/clear.m Mon Sep 17 15:49:39 2018 +0200 @@ -1,13 +1,5 @@ % Remove all loaded subpaths from the matlab path function clear() - state = mpm.load_state(); - - subpaths = state.added_paths.keys(); - - for i = 1:length(subpaths) - rmpath(subpaths{i}); - state.added_paths.remove(subpaths{i}); - end - - mpm.save_state(state); + m = mpm.MatlabPathManager(); + m.clear(); end
--- a/+mpm/info.m Mon Sep 17 15:46:16 2018 +0200 +++ b/+mpm/info.m Mon Sep 17 15:49:39 2018 +0200 @@ -1,9 +1,8 @@ function info() - state = mpm.load_state(); + m = mpm.MatlabPathManager(); + subpaths = m.loadedSubpaths(); fprintf('Loaded subpaths:\n') - - subpaths = state.added_paths.keys(); for i = 1:length(subpaths); fprintf('\t%s\n', subpaths{i}); end
--- a/+mpm/subpaths.m Mon Sep 17 15:46:16 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -function sp = subpaths(d) - if ~exist('d', 'var') || isempty(d) - d = ''; - end - - try - fstr = fileread(fullfile(d, '.subpaths')); - catch - error('Subpath definition file ''.subpaths'' not found.') - end - sp = splitlines(strtrim(fstr)); -end
--- a/+mpm/verify.m Mon Sep 17 15:46:16 2018 +0200 +++ b/+mpm/verify.m Mon Sep 17 15:49:39 2018 +0200 @@ -3,30 +3,13 @@ % The right version is at the top of the path % % Useful to put at the top of some scripts -function check() +function verify(d) if ~exist('d', 'var') || isempty(d) - d = ''; + d = pwd; end - folders = split(path(), pathsep); - - sp = mpm.subpaths(d); - for i = 1:length(sp) - if ~isAtTop(sp{i}, fullfile(pwd, sp{i}), folders) - error('Subpaths are not correctly set. Try running mpm.set()'); - end + m = mpm.MatlabPathManager(); + if ~m.verify(d) + error('Subpaths are not correctly loaded. Try running mpm.checkin()'); end end - -function b = isAtTop(subpath, fullsubpath, paths) - for i = 1:length(paths) - if ~endsWith(paths{i}, subpath) - continue - end - - b = strcmp(fullsubpath, paths{i}); - return - end - - b = false; -end