changeset 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
files +mpm/MatlabPathManager.m
diffstat 1 files changed, 42 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/+mpm/MatlabPathManager.m	Mon Sep 17 14:39:00 2018 +0200
+++ b/+mpm/MatlabPathManager.m	Mon Sep 17 15:44:19 2018 +0200
@@ -6,7 +6,6 @@
 
     methods
         function obj = MatlabPathManager()
-
         end
 
         function p = stateFilePath(obj)
@@ -17,9 +16,8 @@
         function loadSubpath(obj, p)
             state = mpm.load_state();
 
-            subpath = fullfile(pwd, p);
-            addpath(subpath);
-            state.added_paths(subpath) = true;
+            addpath(p);
+            state.added_paths(p) = true;
 
             mpm.save_state(state);
 
@@ -30,9 +28,8 @@
         function unloadSubpath(obj, p)
             state = mpm.load_state();
 
-            subpath = fullfile(pwd, p);
-            rmpath(subpath);
-            state.added_paths.remove(subpath);
+            rmpath(p);
+            state.added_paths.remove(p);
 
             mpm.save_state(state);
 
@@ -55,6 +52,10 @@
             % TODO: Make it respect order from the matlab path
         end
 
+        function ps = matlabPath(obj)
+            ps = split(path(), pathsep);
+        end
+
         % Return all subpaths loaded into the matlab path, mimicing the order they appear there.
         function s = pathStatus(obj)
         end
@@ -68,7 +69,8 @@
             sp = obj.projectSubpaths(projectFolder);
 
             for i = 1:length(sp)
-                obj.loadSubpath(sp{i});
+                fullSubpath = fullfile(projectFolder, sp{i});
+                obj.loadSubpath(fullSubpath);
             end
         end
 
@@ -77,7 +79,38 @@
             sp = obj.projectSubpaths(projectFolder);
 
             for i = 1:length(sp)
-                obj.unloadSubpath(sp{i});
+                fullSubpath = fullfile(projectFolder, sp{i});
+                obj.unloadSubpath(fullSubpath);
+            end
+        end
+
+        % Check if the projects settings are correct
+        % Is the project file correct?
+        % The right version is in the matlab path
+        % The right version is at the top of the path
+        function b = verify(obj, projectFolder)
+            mpath = obj.matlabPath();
+            sp = obj.projectSubpaths(projectFolder);
+
+            for i = 1:length(sp)
+                if ~isAtTop(sp{i}, fullfile(projectFolder, sp{i}), mpath)
+                    b = false;
+                    return;
+                end
+            end
+            b = true;
+
+            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
         end