-
Notifications
You must be signed in to change notification settings - Fork 32
/
nwbClearGenerated.m
55 lines (51 loc) · 1.79 KB
/
nwbClearGenerated.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function clearedNamespaceNames = nwbClearGenerated(targetFolder, options)
% NWBCLEARGENERATED - Clear generated class files.
%
% Syntax:
% NWBCLEARGENERATED() Clear generated class files from the ``+types``
% folder in the matnwb root directory.
%
% Input Arguments:
% - targetFolder (string) -
% Path name for folder containing generated classes in a ``+types``
% namespace folder. Default value is the matnwb root directory
%
% - options (name-value pairs) -
% Optional name-value pairs. Available options:
%
% - ClearCache (logical) -
% Whether to clear the cached schema data in the ``namespaces`` folder.
% Default is ``false``
%
% Usage:
% Example 1 - Clear all generated classes in the matnwb root directory::
%
% nwbClearGenerated();
%
% See also:
% generateCore, generateExtension
arguments
targetFolder (1,1) string {mustBeFolder} = misc.getMatnwbDir()
options.ClearCache (1,1) logical = false
end
typesPath = fullfile(targetFolder, '+types');
listing = dir(typesPath);
moduleNames = setdiff({listing.name}, {'+untyped', '+util', '.', '..'});
generatedPaths = fullfile(typesPath, moduleNames);
for i=1:length(generatedPaths)
rmdir(generatedPaths{i}, 's');
end
if options.ClearCache
cachePath = fullfile(targetFolder, 'namespaces');
listing = dir(fullfile(cachePath, '*.mat'));
generatedPaths = fullfile(cachePath, {listing.name});
for i=1:length(generatedPaths)
delete(generatedPaths{i});
end
end
if nargout == 1 % Return names of cleared namespaces
[~, clearedNamespaceNames] = fileparts(generatedPaths);
clearedNamespaceNames = strrep(clearedNamespaceNames, '+', '');
clearedNamespaceNames = string(clearedNamespaceNames);
end
end