Mercurial > repos > public > matlab_path_manager
comparison +mpm/MatlabPathManager.m @ 18:1e568093b569
Add verify method. Fix some bugs
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 17 Sep 2018 15:44:19 +0200 |
parents | c37f67ccabac |
children | 2e29cca20d8a |
comparison
equal
deleted
inserted
replaced
17:c37f67ccabac | 18:1e568093b569 |
---|---|
4 stateFileName = ''; | 4 stateFileName = ''; |
5 end | 5 end |
6 | 6 |
7 methods | 7 methods |
8 function obj = MatlabPathManager() | 8 function obj = MatlabPathManager() |
9 | |
10 end | 9 end |
11 | 10 |
12 function p = stateFilePath(obj) | 11 function p = stateFilePath(obj) |
13 p = fullfile(mpm.install_location(), obj.stateFileName); | 12 p = fullfile(mpm.install_location(), obj.stateFileName); |
14 end | 13 end |
15 | 14 |
16 % Load a given subpath into the state file and the matlab path and do savepath(), atomically | 15 % Load a given subpath into the state file and the matlab path and do savepath(), atomically |
17 function loadSubpath(obj, p) | 16 function loadSubpath(obj, p) |
18 state = mpm.load_state(); | 17 state = mpm.load_state(); |
19 | 18 |
20 subpath = fullfile(pwd, p); | 19 addpath(p); |
21 addpath(subpath); | 20 state.added_paths(p) = true; |
22 state.added_paths(subpath) = true; | |
23 | 21 |
24 mpm.save_state(state); | 22 mpm.save_state(state); |
25 | 23 |
26 % TODO: Make atomic + add savepath() | 24 % TODO: Make atomic + add savepath() |
27 end | 25 end |
28 | 26 |
29 % Unload a given subpath from the state file and the matlab path and do savepath(), atomically | 27 % Unload a given subpath from the state file and the matlab path and do savepath(), atomically |
30 function unloadSubpath(obj, p) | 28 function unloadSubpath(obj, p) |
31 state = mpm.load_state(); | 29 state = mpm.load_state(); |
32 | 30 |
33 subpath = fullfile(pwd, p); | 31 rmpath(p); |
34 rmpath(subpath); | 32 state.added_paths.remove(p); |
35 state.added_paths.remove(subpath); | |
36 | 33 |
37 mpm.save_state(state); | 34 mpm.save_state(state); |
38 | 35 |
39 % TODO: Make atomic + add savepath() | 36 % TODO: Make atomic + add savepath() |
40 end | 37 end |
53 state = mpm.load_state(); | 50 state = mpm.load_state(); |
54 s = state.added_paths.keys(); | 51 s = state.added_paths.keys(); |
55 % TODO: Make it respect order from the matlab path | 52 % TODO: Make it respect order from the matlab path |
56 end | 53 end |
57 | 54 |
55 function ps = matlabPath(obj) | |
56 ps = split(path(), pathsep); | |
57 end | |
58 | |
58 % Return all subpaths loaded into the matlab path, mimicing the order they appear there. | 59 % Return all subpaths loaded into the matlab path, mimicing the order they appear there. |
59 function s = pathStatus(obj) | 60 function s = pathStatus(obj) |
60 end | 61 end |
61 | 62 |
62 % Return all subpaths in the project and if they are active on the matlab path or not. | 63 % Return all subpaths in the project and if they are active on the matlab path or not. |
66 % Load all subpaths for a project | 67 % Load all subpaths for a project |
67 function checkin(obj, projectFolder) | 68 function checkin(obj, projectFolder) |
68 sp = obj.projectSubpaths(projectFolder); | 69 sp = obj.projectSubpaths(projectFolder); |
69 | 70 |
70 for i = 1:length(sp) | 71 for i = 1:length(sp) |
71 obj.loadSubpath(sp{i}); | 72 fullSubpath = fullfile(projectFolder, sp{i}); |
73 obj.loadSubpath(fullSubpath); | |
72 end | 74 end |
73 end | 75 end |
74 | 76 |
75 % Unload all subpaths for a project | 77 % Unload all subpaths for a project |
76 function checkout(obj, projectFolder) | 78 function checkout(obj, projectFolder) |
77 sp = obj.projectSubpaths(projectFolder); | 79 sp = obj.projectSubpaths(projectFolder); |
78 | 80 |
79 for i = 1:length(sp) | 81 for i = 1:length(sp) |
80 obj.unloadSubpath(sp{i}); | 82 fullSubpath = fullfile(projectFolder, sp{i}); |
83 obj.unloadSubpath(fullSubpath); | |
84 end | |
85 end | |
86 | |
87 % Check if the projects settings are correct | |
88 % Is the project file correct? | |
89 % The right version is in the matlab path | |
90 % The right version is at the top of the path | |
91 function b = verify(obj, projectFolder) | |
92 mpath = obj.matlabPath(); | |
93 sp = obj.projectSubpaths(projectFolder); | |
94 | |
95 for i = 1:length(sp) | |
96 if ~isAtTop(sp{i}, fullfile(projectFolder, sp{i}), mpath) | |
97 b = false; | |
98 return; | |
99 end | |
100 end | |
101 b = true; | |
102 | |
103 function b = isAtTop(subpath, fullsubpath, paths) | |
104 for i = 1:length(paths) | |
105 if ~endsWith(paths{i}, subpath) | |
106 continue | |
107 end | |
108 | |
109 b = strcmp(fullsubpath, paths{i}); | |
110 return | |
111 end | |
112 | |
113 b = false; | |
81 end | 114 end |
82 end | 115 end |
83 | 116 |
84 % Unload all loaded subpaths. The matlab path should be returned to it's original state | 117 % Unload all loaded subpaths. The matlab path should be returned to it's original state |
85 function clear(obj) | 118 function clear(obj) |