1 | %TOOLBOX_EXPORT Prepare toolbox for export, archive and send to website
|
---|
2 | %
|
---|
3 | % TOOLBOX_EXPORT(TOOLBOX,COPYFLAG,EXCLUDE,ARCHIVE)
|
---|
4 | %
|
---|
5 | % zip and copy TOOLBOX to PRTools server and archive in ARCHIVE. In case
|
---|
6 | % COPYFLAG is false (default) copying to the server is skipped.
|
---|
7 | %
|
---|
8 | % The tooolbox version as stored in the Contents.m file is interactively
|
---|
9 | % updated. In addition a TOOLBOX_version.txt file is created or updated on
|
---|
10 | % the server. Sub-directories of TOOLBOX given as a cell array in EXCLUDE
|
---|
11 | % will not be stored in the zip-file. Other sub-directories will be
|
---|
12 | % compressed as they are. In the main toolbox directory just the m-files
|
---|
13 | % are used.
|
---|
14 | %
|
---|
15 | % TOOLBOX should be in the search path and has to be given by the name
|
---|
16 | % only.
|
---|
17 | %
|
---|
18 | % The default for ARCHIVE is the prtools_export dir in the group server:
|
---|
19 | % \\srv051.tudelft.net\staff-groups-ewi\insy\PRLab\Matlab\prtools_export
|
---|
20 |
|
---|
21 | % Copyright: R.P.W. Duin
|
---|
22 |
|
---|
23 | function toolbox_export(toolbox,copyflag,exclude,archive)
|
---|
24 |
|
---|
25 | if nargin < 4 || isempty(archive)
|
---|
26 | archive = '\\srv051.tudelft.net\staff-groups-ewi\insy\PRLab\Matlab\prtools_export';
|
---|
27 | end
|
---|
28 | if nargin < 3, exclude = []; end
|
---|
29 | if nargin < 2 || isempty(copyflag); copyflag = false; end
|
---|
30 | if ischar(exclude), exclude = {exclude}; end
|
---|
31 |
|
---|
32 | if exist(archive,'dir') ~= 7
|
---|
33 | error(['Archive directory .\insy\PRLab\Matlab\prtools_export not found.' ...
|
---|
34 | newline 'Define it in the ARCHIVE parameter.'])
|
---|
35 | end
|
---|
36 |
|
---|
37 | % check toolbox
|
---|
38 | s = which([toolbox '/Contents.m']);
|
---|
39 | if isempty(s)
|
---|
40 | error(['Toolbox ' toolbox ' is not found in the path or it has no proper Contents.m file']);
|
---|
41 | end
|
---|
42 |
|
---|
43 | % create temp dir
|
---|
44 | zipdir = fullfile(fileparts(which(mfilename)),'tmp');
|
---|
45 | makedir(zipdir);
|
---|
46 | if exist(fullfile(zipdir,toolbox),'dir') == 7
|
---|
47 | rmdir(fullfile(zipdir,toolbox),'s');
|
---|
48 | end
|
---|
49 |
|
---|
50 | % get names and version
|
---|
51 | today = datestr(date,'ddmmmyy');
|
---|
52 | toolboxdir = fileparts(which(fullfile(toolbox,'Contents')));
|
---|
53 | [~,toolboxname] = fileparts(toolboxdir);
|
---|
54 | toolboxver = ver(toolboxdir);
|
---|
55 |
|
---|
56 | % get and set possibly new version number in Content file
|
---|
57 | fprintf(1,' Present %s version is %s\n',toolbox,toolboxver(end).Version);
|
---|
58 | pver_new = input([' Give new version number: [' toolboxver(end).Version '] '],'s');
|
---|
59 | if isempty(pver_new)
|
---|
60 | pver_new = toolboxver(end).Version;
|
---|
61 | else
|
---|
62 | set_version_in_Contents(toolboxdir,pver_new);
|
---|
63 | end
|
---|
64 |
|
---|
65 | % use a copy of TOOLBOX for cleaning and compression
|
---|
66 | disp(' Copying, cleaning and compression may take some time ...')
|
---|
67 | copyfile(toolboxdir,fullfile(zipdir,toolbox));
|
---|
68 | toolboxdir = fullfile(zipdir,toolbox);
|
---|
69 |
|
---|
70 | % zip
|
---|
71 | zfilename = [toolbox pver_new '_' today '.zip'];
|
---|
72 | ztoolbox = fullfile(zipdir,zfilename);
|
---|
73 | sdir = dirnames(toolboxdir);
|
---|
74 | for j=1:numel(sdir) % remove all hidden dirs (.svn)
|
---|
75 | dirnam = fullfile(fullfile(toolboxdir,sdir{j}),'.svn');
|
---|
76 | if exist(dirnam,'dir') == 7
|
---|
77 | rmdir(dirnam,'s');
|
---|
78 | end
|
---|
79 | end
|
---|
80 | if ~isempty(exclude)
|
---|
81 | for j=1:numel(exclude)
|
---|
82 | n = strmatch(exclude{j},sdir);
|
---|
83 | if isempty(n)
|
---|
84 | warning(['Subdirectory ' exclude{j} ' does not exist. Exclusion is skipped'])
|
---|
85 | else
|
---|
86 | sdir(n) = [];
|
---|
87 | end
|
---|
88 | end
|
---|
89 | end
|
---|
90 | zip(ztoolbox,[{'*.m'} sdir{:}],toolboxdir);
|
---|
91 |
|
---|
92 | % use or create specific archdir for this toolbox
|
---|
93 | archdir = fullfile(archive,toolboxname);
|
---|
94 | makedir(archdir);
|
---|
95 |
|
---|
96 | if copyflag
|
---|
97 | % copy to website, use the @ftp package
|
---|
98 | ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
|
---|
99 | cd(ftpsite,'httpdocs/files');
|
---|
100 | mput(ftpsite,ztoolbox);
|
---|
101 | rename(ftpsite,zfilename,[toolboxname '.zip']);
|
---|
102 | disp(' Export files have been stored on the website.')
|
---|
103 | disp(' Please check and adjust release notes and known problems on website')
|
---|
104 | webversion(pver_new,toolboxname,ftpsite); % reset the version file
|
---|
105 | close(ftpsite)
|
---|
106 |
|
---|
107 | % backup in exportdir
|
---|
108 | fprintf(1,' Storing backups of mfiles and export files ... \n');
|
---|
109 | [s,mess] = copyfile(ztoolbox,archdir);
|
---|
110 | if s
|
---|
111 | disp([' Export files have been archived in' newline ' ' archdir])
|
---|
112 | else
|
---|
113 | disp(mess);
|
---|
114 | end
|
---|
115 | else
|
---|
116 | copyfile(ztoolbox,archdir);
|
---|
117 | disp([' The zip-files have been created in ' archdir]);
|
---|
118 | disp([' They have not been copied to the website!']);
|
---|
119 | disp([' If needed, rerun with flag set']);
|
---|
120 | end
|
---|
121 | % cleanup
|
---|
122 | rmdir(zipdir,'s')
|
---|
123 |
|
---|
124 | function set_version_in_Contents(toolbox,prtv)
|
---|
125 |
|
---|
126 | if ~isstr(prtv)
|
---|
127 | error('Version should be given as string, e.g. ''3.2.7''')
|
---|
128 | end
|
---|
129 | contentfile = fullfile(toolbox,'Contents.m');
|
---|
130 | s = readf(contentfile);
|
---|
131 | n = findstr(s,newline);
|
---|
132 | r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
|
---|
133 | writf(contentfile,r);
|
---|
134 | disp(' Contents.m rewritten with new version number')
|
---|
135 |
|
---|
136 |
|
---|
137 | function [subdirs,files] = dirnames(dirname,ext)
|
---|
138 | %DIRNAMES
|
---|
139 | %
|
---|
140 | % [SUBDIRS,FILES]= DIRNAMES(DIR,EXT)
|
---|
141 | %
|
---|
142 | %Get names of all subdirs and files in direcotory DIR.
|
---|
143 | %Hidden files, . and .. and Thumbs.db neglected
|
---|
144 |
|
---|
145 | if nargin == 0
|
---|
146 | dirname = '.';
|
---|
147 | end
|
---|
148 |
|
---|
149 | if nargin > 1
|
---|
150 | allnames = dir([dirname '/*.' ext]);
|
---|
151 | else
|
---|
152 | allnames = dir(dirname);
|
---|
153 | end
|
---|
154 | n = length(allnames);
|
---|
155 | subdirs = cell(1,n);
|
---|
156 | files = cell(1,n);
|
---|
157 | ns = 0;
|
---|
158 | nf = 0;
|
---|
159 |
|
---|
160 | for j=1:n
|
---|
161 | name = deblank(allnames(j).name);
|
---|
162 | if (name(1) ~= '.') && ~strcmp(name,'Thumbs.db') % skip hidden files
|
---|
163 | if allnames(j).isdir
|
---|
164 | ns = ns+1;
|
---|
165 | subdirs{ns} = name;
|
---|
166 | else
|
---|
167 | nf = nf+1;
|
---|
168 | files{nf} = name;
|
---|
169 | end
|
---|
170 | end
|
---|
171 | end
|
---|
172 |
|
---|
173 | if ns > 0
|
---|
174 | subdirs = char(subdirs(1:ns));
|
---|
175 | subdirs = cellstr(subdirs);
|
---|
176 | else
|
---|
177 | subdirs = {''};
|
---|
178 | end
|
---|
179 | if nf > 0
|
---|
180 | files = char(files(1:nf));
|
---|
181 | files = cellstr(files);
|
---|
182 | else
|
---|
183 | files = [];
|
---|
184 | end
|
---|
185 |
|
---|
186 |
|
---|
187 | function makedir(name)
|
---|
188 | %MAKEDIR make directory if needed
|
---|
189 |
|
---|
190 | if exist(name,'dir') ~= 7
|
---|
191 | mkdir(name)
|
---|
192 | end
|
---|
193 |
|
---|
194 | function [s,n] = readf(file)
|
---|
195 | fid = fopen(file);
|
---|
196 | if fid < 0
|
---|
197 | error(['File ' file ' not found, probably wrong directory'])
|
---|
198 | end
|
---|
199 | [s,n] = fread(fid);
|
---|
200 | if isempty(s)
|
---|
201 | error(['File ' file ' could not be read'])
|
---|
202 | end
|
---|
203 | s = s(:)';
|
---|
204 | fclose(fid);
|
---|
205 |
|
---|
206 | function writf(file,s)
|
---|
207 | fid = fopen(file,'w');
|
---|
208 | if fid < 0
|
---|
209 | error(['File ' file ' could not be opened for writing'])
|
---|
210 | end
|
---|
211 | fwrite(fid,s);
|
---|
212 | fclose(fid);
|
---|