Mercurial > repos > public > matlab_path_manager
changeset 17:c37f67ccabac
Copy implementations into the MPM class
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 17 Sep 2018 14:39:00 +0200 |
parents | 4c5d876068c2 |
children | 1e568093b569 |
files | +mpm/MatlabPathManager.m |
diffstat | 1 files changed, 55 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/+mpm/MatlabPathManager.m Mon Sep 17 14:11:38 2018 +0200 +++ b/+mpm/MatlabPathManager.m Mon Sep 17 14:39:00 2018 +0200 @@ -13,12 +13,46 @@ p = fullfile(mpm.install_location(), obj.stateFileName); end - % Load a given path into the state file and the matlab path and do savepath(), atomically - function loadPath(obj, p) + % Load a given subpath into the state file and the matlab path and do savepath(), atomically + function loadSubpath(obj, p) + state = mpm.load_state(); + + subpath = fullfile(pwd, p); + addpath(subpath); + state.added_paths(subpath) = true; + + mpm.save_state(state); + + % TODO: Make atomic + add savepath() end - % opposite of load - function unloadPath(obj, p) + % Unload a given subpath from the state file and the matlab path and do savepath(), atomically + function unloadSubpath(obj, p) + state = mpm.load_state(); + + subpath = fullfile(pwd, p); + rmpath(subpath); + state.added_paths.remove(subpath); + + mpm.save_state(state); + + % TODO: Make atomic + add savepath() + end + + % Read project file in a folder and return cell array of all subpaths + function sp = projectSubpaths(obj, projectFolder) + try + fstr = fileread(fullfile(projectFolder, obj.projectFileName)); + catch + error('Subpath definition file ''%s'' not found.', obj.projectFileName); + end + sp = splitlines(strtrim(fstr)); + end + + function s = loadedSubpaths(obj) + state = mpm.load_state(); + s = state.added_paths.keys(); + % TODO: Make it respect order from the matlab path end % Return all subpaths loaded into the matlab path, mimicing the order they appear there. @@ -31,14 +65,31 @@ % Load all subpaths for a project function checkin(obj, projectFolder) + sp = obj.projectSubpaths(projectFolder); + + for i = 1:length(sp) + obj.loadSubpath(sp{i}); + end end % Unload all subpaths for a project function checkout(obj, projectFolder) + sp = obj.projectSubpaths(projectFolder); + + for i = 1:length(sp) + obj.unloadSubpath(sp{i}); + end end % Unload all loaded subpaths. The matlab path should be returned to it's original state function clear(obj) + sp = obj.loadedSubpaths(); + + for i = 1:length(sp) + obj.unload(sp{i}); + end end end end + +% TODO: get rid of mpm.load_state and mpm.save_state