diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m index 21147015be728a6748c597fd2f677ba381a2a097..f571cc41b8e3920c5335c09bcde83d79dd7a854d 100644 --- a/+PlotID/Publish.m +++ b/+PlotID/Publish.m @@ -161,13 +161,7 @@ dlgObj.userMSG(msg); % user functions if options.CopyUserFCN - [fList,pList] = matlab.codetools.requiredFilesAndProducts(scriptPath); - fList = fList(~ismember(fList,scriptPath)); % rmv script from list - fList = fList(~contains(fList,'config.json')); % rmv config.json from list - fList = PlotID.removePltIdFiles(fList); % Do not copy files that are part of PlotID - if ~isempty(fList) - PlotID.createFileCopy(fList,folderName,storPath,ID,'userFcn'); - end + toolboxList = PlotID.copyUserFCN(scriptPath, folderName, storPath, ID); end %% Research data handling @@ -239,7 +233,7 @@ meta.ProjectID = ID; meta.CreationDate = datestr(now); meta.MatlabVersion = version; if options.CopyUserFCN - meta.ToolboxVersions = pList; + meta.ToolboxVersions = toolboxList; end % write meta metaPath = fullfile(storPath,folderName,'plotID_data.json'); diff --git a/+PlotID/copyUserFCN.m b/+PlotID/copyUserFCN.m new file mode 100644 index 0000000000000000000000000000000000000000..4525737320b5b2347b8dd2caf18c051ac0c6a90a --- /dev/null +++ b/+PlotID/copyUserFCN.m @@ -0,0 +1,60 @@ +function pList = copyUserFCN(scriptPath, folderName, storPath, ID) +%COPYUSERFCN copies all user functions, classes and toolboxes that are used +%by the base script (scriptpath). +% folderName, storPath and ID are required for createfilecopy + [fList,pList] = matlab.codetools.requiredFilesAndProducts(scriptPath); + fList = fList(~ismember(fList,scriptPath)); % rmv plot script itself from list + fList = fList(~contains(fList,'config.json')); % rmv config.json from list + fList = removePltIdFiles(fList); % Do not copy files that are part of PlotID + + % copy Classes and Toolboxes as a whole + copyTBorClass(fList,'+', folderName, storPath, ID); % Toolboxes + copyTBorClass(fList,'@', folderName, storPath, ID); % Classes + %remove class and toolbox files from flist + fList = fList(~contains(fList,{'@','+'})); + + % copy User FCN + if ~isempty(fList) + PlotID.createFileCopy(fList,folderName,storPath,ID,'userFcn'); + end +end + +function [fListClean] = removePltIdFiles(fList) + %removePltIdFiles removes functions that are part of PlotID out of flist + % Detailed explanation goes here + + [~,names,ext] = fileparts(fList); + names = strcat(names, ext); % add ext for comparison + + % Get a list of all .m files that are part of Plot id + packageContent = what('PlotID'); + % packageContent.classes has no extensions + PltID_classlist = packageContent.classes; + + % Class Methods need to be listed in an additional function + Class_flist = cell(1,numel(packageContent.classes)); %preallocate + for i=1:numel(packageContent.classes) + temp = what(['PlotID',filesep,'@',PltID_classlist{i}]); + Class_flist{i} = temp.m; + end + + Class_flist = vertcat(Class_flist{:}); + % all plotID .m files: + PltID_flist = [packageContent.m; Class_flist]; + % Comparison and filter + fListClean = fList(~ismember(names,PltID_flist)); +end + +function [status, msg] = copyTBorClass(fList,leadChar, folderName, storPath, ID) +%copyTBorClass copies the Toolboxes or Classes that are part of flist +% lead char must be either '@' for Classes or '+' for Toolboxes +if any(contains(fList,leadChar)) + list = fList(contains(fList, leadChar)); + names = extractBetween(list,leadChar,filesep); + paths = extractBefore(list,strcat(leadChar,names)); + fullPaths = strcat(paths,strcat(leadChar,names)); + fullPaths = unique(fullPaths); + [~, status, msg] =PlotID.createFileCopy(fullPaths,... + folderName,storPath,ID,'class'); +end %if +end \ No newline at end of file diff --git a/+PlotID/createFileCopy.m b/+PlotID/createFileCopy.m index e876e70926a4e70791d4295d0745e60c9b166d41..10ac4e7100e4143edcf33de37f5d4dd9bddbd05f 100644 --- a/+PlotID/createFileCopy.m +++ b/+PlotID/createFileCopy.m @@ -29,6 +29,8 @@ end case 'userFcn' %keep original name newfile = sprintf([name,ext]); + case {'class','toolbox'} + newfile = name; % copy whole folder otherwise error([type,' is not a valid type for createFileCopy']) end %switch diff --git a/+PlotID/removePltIdFiles.m b/+PlotID/removePltIdFiles.m deleted file mode 100644 index 57a07b7c9a7ea20f7d4a209402729bc469aac232..0000000000000000000000000000000000000000 --- a/+PlotID/removePltIdFiles.m +++ /dev/null @@ -1,27 +0,0 @@ -function [fListClean] = removePltIdFiles(fList) -%removePltIdFiles removes functions that are part of PlotID out of flist -% Detailed explanation goes here - -[~,names,ext] = fileparts(fList); -names = strcat(names, ext); % add ext for comparison - -% Get a list of all .m files that are part of Plot id -packageContent = what('PlotID'); -% packageContent.classes has no extensions -PltID_classlist = packageContent.classes; - -% Class Methods need to be listed in an additional function -Class_flist = cell(1,numel(packageContent.classes)); %preallocate -for i=1:numel(packageContent.classes) - temp = what(['PlotID',filesep,'@',PltID_classlist{i}]); - Class_flist{i} = temp.m; -end - -Class_flist = vertcat(Class_flist{:}); -% all plotID .m files: -PltID_flist = [packageContent.m; Class_flist]; -% Comparison and filter -fListClean = fList(~ismember(names,PltID_flist)); -end - -