comparison +mpm/MatlabPathManager.m @ 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
comparison
equal deleted inserted replaced
16:4c5d876068c2 17:c37f67ccabac
11 11
12 function p = stateFilePath(obj) 12 function p = stateFilePath(obj)
13 p = fullfile(mpm.install_location(), obj.stateFileName); 13 p = fullfile(mpm.install_location(), obj.stateFileName);
14 end 14 end
15 15
16 % Load a given path into the state file and the matlab path and do savepath(), atomically 16 % Load a given subpath into the state file and the matlab path and do savepath(), atomically
17 function loadPath(obj, p) 17 function loadSubpath(obj, p)
18 state = mpm.load_state();
19
20 subpath = fullfile(pwd, p);
21 addpath(subpath);
22 state.added_paths(subpath) = true;
23
24 mpm.save_state(state);
25
26 % TODO: Make atomic + add savepath()
18 end 27 end
19 28
20 % opposite of load 29 % Unload a given subpath from the state file and the matlab path and do savepath(), atomically
21 function unloadPath(obj, p) 30 function unloadSubpath(obj, p)
31 state = mpm.load_state();
32
33 subpath = fullfile(pwd, p);
34 rmpath(subpath);
35 state.added_paths.remove(subpath);
36
37 mpm.save_state(state);
38
39 % TODO: Make atomic + add savepath()
40 end
41
42 % Read project file in a folder and return cell array of all subpaths
43 function sp = projectSubpaths(obj, projectFolder)
44 try
45 fstr = fileread(fullfile(projectFolder, obj.projectFileName));
46 catch
47 error('Subpath definition file ''%s'' not found.', obj.projectFileName);
48 end
49 sp = splitlines(strtrim(fstr));
50 end
51
52 function s = loadedSubpaths(obj)
53 state = mpm.load_state();
54 s = state.added_paths.keys();
55 % TODO: Make it respect order from the matlab path
22 end 56 end
23 57
24 % Return all subpaths loaded into the matlab path, mimicing the order they appear there. 58 % Return all subpaths loaded into the matlab path, mimicing the order they appear there.
25 function s = pathStatus(obj) 59 function s = pathStatus(obj)
26 end 60 end
29 function s = projectStatus(obj, projectFolder) 63 function s = projectStatus(obj, projectFolder)
30 end 64 end
31 65
32 % Load all subpaths for a project 66 % Load all subpaths for a project
33 function checkin(obj, projectFolder) 67 function checkin(obj, projectFolder)
68 sp = obj.projectSubpaths(projectFolder);
69
70 for i = 1:length(sp)
71 obj.loadSubpath(sp{i});
72 end
34 end 73 end
35 74
36 % Unload all subpaths for a project 75 % Unload all subpaths for a project
37 function checkout(obj, projectFolder) 76 function checkout(obj, projectFolder)
77 sp = obj.projectSubpaths(projectFolder);
78
79 for i = 1:length(sp)
80 obj.unloadSubpath(sp{i});
81 end
38 end 82 end
39 83
40 % Unload all loaded subpaths. The matlab path should be returned to it's original state 84 % Unload all loaded subpaths. The matlab path should be returned to it's original state
41 function clear(obj) 85 function clear(obj)
86 sp = obj.loadedSubpaths();
87
88 for i = 1:length(sp)
89 obj.unload(sp{i});
90 end
42 end 91 end
43 end 92 end
44 end 93 end
94
95 % TODO: get rid of mpm.load_state and mpm.save_state