Mercurial > hg > ltpda
comparison m-toolbox/mk_file_list.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function [fails, ginfoFails] = mk_file_list(varargin) | |
2 % A script to make a list of toolbox files and write an m-file to | |
3 % declare the files | |
4 % | |
5 % Usage: mk_file_list(toolbox_dir); | |
6 % | |
7 % M Hewitson | |
8 % | |
9 % $Id: mk_file_list.m,v 1.18 2008/12/21 18:49:25 hewitson Exp $ | |
10 % | |
11 | |
12 if nargin == 0 | |
13 rdir = 'c:\matlab\ltpda_toolbox'; | |
14 else | |
15 rdir = varargin{1}; | |
16 end | |
17 | |
18 if rdir(end) ~= filesep | |
19 rdir = [rdir filesep]; | |
20 end | |
21 | |
22 % Initialise | |
23 nn = 1; | |
24 fails = {}; | |
25 ginfoFails = {}; | |
26 | |
27 % make a list of all class methods | |
28 classes = utils.helper.ltpda_classes; | |
29 | |
30 % Go through each class | |
31 for cls=classes | |
32 cl = char(cls); | |
33 | |
34 % get the methods for this class | |
35 mths = methods(cl); | |
36 | |
37 for m=1:numel(mths) | |
38 mth = mths{m}; | |
39 % get file name | |
40 fi = which(fullfile(cl, mth)); | |
41 if isempty(fi) | |
42 warning('!!! Can''t find %s/%s', cl, mth) | |
43 end | |
44 % Get path,name,ext | |
45 [path, fcnname, ext, ver] = fileparts(fi); | |
46 | |
47 % get short name | |
48 sname = mth; | |
49 if ~strcmpi(mth, 'contents') | |
50 disp(sprintf('*** processing %s', mth)); | |
51 % load file | |
52 fc = ''; | |
53 if ~isempty(fi) | |
54 fd = fopen(fi, 'r'); | |
55 if fd == -1 | |
56 error('### Could not open %s', fi); | |
57 end | |
58 fc = fscanf(fd, '%s'); | |
59 fclose(fd); | |
60 end | |
61 | |
62 % Look for a CVS version string | |
63 verstr = ''; | |
64 try | |
65 ii = strfind(fc, '$Id:'); | |
66 ts = fc(ii(1):end); | |
67 ii = strfind(ts, '$'); | |
68 verstr = ts(1:ii(2)); | |
69 catch | |
70 warning('!!! CVS Tag not found: Failed on %s', sname) | |
71 fails = [fails {sname}]; | |
72 end | |
73 | |
74 % If we have a valid version string, continue | |
75 ver = ''; | |
76 dt = ''; | |
77 tt = ''; | |
78 nm = ''; | |
79 if ~isempty(verstr) | |
80 | |
81 % parse version string | |
82 tks = regexp(verstr, 'v([.0-9]+)(\d{4}/\d{2}/\d{2})(\d{2}:\d{2}:\d{2})(\S+)', 'tokens'); | |
83 try | |
84 ver = tks{1}{1}; % version | |
85 dt = tks{1}{2}; % date | |
86 tt = tks{1}{3}; % time | |
87 ni = strfind(tks{1}{4}, 'Exp$'); | |
88 nm = tks{1}{4}(1:ni-1); % name | |
89 catch | |
90 ver = ''; | |
91 dt = ''; | |
92 tt = ''; | |
93 nm = ''; | |
94 fails = [fails {sname}]; | |
95 end | |
96 end | |
97 % make hash | |
98 if isempty(fc) | |
99 hs = ''; | |
100 else | |
101 hs = utils.prog.hash(fc, 'MD5'); | |
102 end | |
103 | |
104 % Look for the category | |
105 cat = ''; | |
106 argsMin = ''; | |
107 argsMax = ''; | |
108 try | |
109 cmd = sprintf('ii = %s.getInfo(''%s'', ''None'');', cl, mth); | |
110 eval(cmd); | |
111 cat = ii.mcategory; | |
112 argsMin = num2str(ii.argsmin); | |
113 argsMax = num2str(ii.argsmax); | |
114 catch | |
115 lasterr | |
116 | |
117 end | |
118 | |
119 % fill cell array | |
120 vers(nn,1) = {fi}; | |
121 vers(nn,2) = {sname}; | |
122 vers(nn,3) = {ver}; | |
123 vers(nn,4) = {dt}; | |
124 vers(nn,5) = {tt}; | |
125 vers(nn,6) = {nm}; | |
126 vers(nn,7) = {path}; | |
127 vers(nn,8) = {hs}; | |
128 vers(nn,9) = {cat}; | |
129 vers(nn,10) = {cl}; | |
130 vers(nn,11) = {argsMin}; | |
131 vers(nn,12) = {argsMax}; | |
132 nn = nn + 1; | |
133 end | |
134 end | |
135 end | |
136 | |
137 | |
138 %--- Write out version file | |
139 fname = fullfile(rdir, 'ltpda', 'm', 'etc','ltpda_versions.m'); | |
140 fd = fopen(fname, 'w+'); | |
141 fprintf(fd, 'versions = {...\n'); | |
142 for j=1:size(vers,1) | |
143 fprintf(fd, '\t\t'); | |
144 for k=1:size(vers,2) | |
145 fprintf(fd, '''%s''', vers{j,k}); | |
146 if k~=size(vers,2) | |
147 fprintf(fd, ', '); | |
148 end | |
149 end | |
150 fprintf(fd, '; ...\n'); | |
151 end | |
152 fprintf(fd, '\t\t};\n'); | |
153 fclose(fd); | |
154 | |
155 % Compile this to p-code | |
156 run(fname) | |
157 % pcode(fname, '-inplace'); | |
158 % delete(fname); | |
159 | |
160 %--- Display failures | |
161 for j=1:length(fails) | |
162 disp(sprintf('### FAILED: %s', fails{j})); | |
163 end | |
164 | |
165 end | |
166 | |
167 % %--- Process each file | |
168 % for j=1:nfs | |
169 % | |
170 % % This file | |
171 % fi = tbfs{j}; | |
172 % | |
173 % % Get path,name,ext | |
174 % [path, fcnname, ext, ver] = fileparts(fi); | |
175 % | |
176 % % Make exceptions | |
177 % if ~strcmp(fcnname, 'Contents') && ... | |
178 % ~strcmp(fcnname, 'MakeContents') | |
179 % | |
180 % % get short name | |
181 % sname = strrep(fi, rdir, ''); | |
182 % if sname(1) == '/' | |
183 % sname = sname(2:end); | |
184 % end | |
185 % disp(sprintf('*** processing %s', sname)); | |
186 % | |
187 % % load file | |
188 % fd = fopen(fi, 'r'); | |
189 % fc = fscanf(fd, '%s'); | |
190 % fclose(fd); | |
191 % | |
192 % % Look for a CVS version string | |
193 % try | |
194 % ii = strfind(fc, '$Id:'); | |
195 % ts = fc(ii(1):end); | |
196 % ii = strfind(ts, '$'); | |
197 % verstr = ts(1:ii(2)); | |
198 % catch | |
199 % warning('!!! CVS Tag not found: Failed on %s', sname) | |
200 % fails = [fails {sname}]; | |
201 % end | |
202 % | |
203 % | |
204 % | |
205 % % If we have a valid version string, continue | |
206 % if ~isempty(verstr) | |
207 % | |
208 % % parse version string | |
209 % tks = regexp(verstr, 'v([.0-9]+)(\d{4}/\d{2}/\d{2})(\d{2}:\d{2}:\d{2})(\S+)', 'tokens'); | |
210 % try | |
211 % ver = tks{1}{1}; % version | |
212 % dt = tks{1}{2}; % date | |
213 % tt = tks{1}{3}; % time | |
214 % ni = strfind(tks{1}{4}, 'Exp$'); | |
215 % nm = tks{1}{4}(1:ni-1); % name | |
216 % catch | |
217 % ver = ''; | |
218 % dt = ''; | |
219 % tt = ''; | |
220 % nm = ''; | |
221 % fails = [fails {sname}]; | |
222 % end | |
223 % | |
224 % % make hash | |
225 % hs = utils.prog.hash(fc, 'MD5'); | |
226 % | |
227 % % get class/category | |
228 % idx = strfind(sname, fcnname); | |
229 % pth = sname(1:idx(end)-1); | |
230 % | |
231 % % get class | |
232 % if ~isempty(strfind(pth, 'classes')) | |
233 % [s,r] = strtok(pth, '@'); | |
234 % cl = r(2:end-1); | |
235 % else | |
236 % cl = 'None'; | |
237 % end | |
238 % | |
239 % % Look for the category | |
240 % cat = ''; | |
241 % acc = ''; | |
242 % if ismember(cl, classes) | |
243 % if ~strcmp(cl, 'None') | |
244 % try | |
245 % cmd = sprintf('ii = %s.getInfo(''%s'', ''None'');', cl, fcnname); | |
246 % eval(cmd); | |
247 % cat = ii.mcategory; | |
248 % end | |
249 % end | |
250 % if isempty(cat) | |
251 % ginfoFails = [ginfoFails {sname}]; | |
252 % end | |
253 % end | |
254 % | |
255 % % fill cell array | |
256 % vers(nn,1) = {fi}; | |
257 % vers(nn,2) = {fcnname}; | |
258 % vers(nn,3) = {ver}; | |
259 % vers(nn,4) = {dt}; | |
260 % vers(nn,5) = {tt}; | |
261 % vers(nn,6) = {nm}; | |
262 % vers(nn,7) = {pth}; | |
263 % vers(nn,8) = {hs}; | |
264 % vers(nn,9) = {cat}; | |
265 % vers(nn,10) = {cl}; | |
266 % nn = nn + 1; | |
267 % else | |
268 % fails = [fails {sname}]; | |
269 % end | |
270 % end | |
271 % end | |
272 % % Only output those which are not empty | |
273 % vers = vers(1:nn-1,:); | |
274 % | |
275 % %--- Write out version file | |
276 % fname = [rdir '/ltpda/m/etc/ltpda_versions.m']; | |
277 % fd = fopen(fname, 'w+'); | |
278 % fprintf(fd, 'versions = {...\n'); | |
279 % for j=1:length(vers) | |
280 % fprintf(fd, '\t\t'); | |
281 % for k=1:size(vers,2) | |
282 % fprintf(fd, '''%s''', vers{j,k}); | |
283 % if k~=size(vers,2) | |
284 % fprintf(fd, ', '); | |
285 % end | |
286 % end | |
287 % fprintf(fd, '; ...\n'); | |
288 % end | |
289 % fprintf(fd, '\t\t};\n'); | |
290 % fclose(fd); | |
291 % | |
292 % % Compile this to p-code | |
293 % run(fname) | |
294 % % pcode(fname, '-inplace'); | |
295 % % delete(fname); | |
296 % | |
297 % %--- Display failures | |
298 % for j=1:length(fails) | |
299 % disp(sprintf('### FAILED: %s', fails{j})); | |
300 % end | |
301 | |
302 | |
303 function files = mtfilescan(root_dir, ext) | |
304 | |
305 % FILESCAN recursively scans the given directory for files that end in | |
306 % 'ext' and returns a list of the full paths. | |
307 % | |
308 % function files = mtfilescan(root_dir, ext) | |
309 % | |
310 | |
311 files = getfiles(root_dir, ext, []); | |
312 end | |
313 | |
314 %-------------------------------------------------------------------------- | |
315 function ofiles = getfiles(root_dir, iext, ofiles) | |
316 % Recursive function for getting file lists | |
317 % | |
318 | |
319 disp(sprintf(' + looking in %s', root_dir)); | |
320 files = dir(root_dir); | |
321 | |
322 for j=1:length(files) | |
323 f = files(j); | |
324 if f.isdir | |
325 if strcmp(f.name,'.')==0 && strcmp(f.name,'..')==0 | |
326 %mdisp('found dir %s', f.name); | |
327 ofiles = getfiles([root_dir '/' f.name], iext, ofiles); | |
328 end | |
329 else | |
330 [pathstr,name,ext,v] = fileparts(f.name); | |
331 if any(strcmp(ext, iext)) | |
332 ofiles = [ofiles; cellstr([root_dir '/' f.name])]; | |
333 end | |
334 end | |
335 end | |
336 end | |
337 | |
338 function mths = getMethods(cl) | |
339 | |
340 mths = []; | |
341 % Class info | |
342 try | |
343 % get meta info for this class | |
344 ci = eval(sprintf('?%s', cl)); | |
345 % Get methods | |
346 ms = methods(cl); %ci.Methods; | |
347 | |
348 % Check if this is an abstract class | |
349 try | |
350 o = feval(cl); | |
351 abstract = false; | |
352 catch | |
353 abstract = true; | |
354 end | |
355 | |
356 if ~abstract | |
357 % Go through methods | |
358 for kk=1:numel(ms) | |
359 m = eval(sprintf('?%s', ms{kk})); | |
360 % If this is not an inherited | |
361 % if strcmp(m.DefiningClass.Name, cl) | |
362 disp(sprintf(' -- checking %s/%s', cl, m.Name)); | |
363 if strcmp(m.Access, 'public') && ~m.Static && ~strcmp(m.Name, 'Contents') | |
364 mths = [mths; {m}]; | |
365 end | |
366 % else | |
367 % warning('!!! Skipping inherited method %s/%s', cl, m.Name); | |
368 % end | |
369 end | |
370 end | |
371 catch | |
372 warning('!!! Couldn''t get meta info for class %s', cl); | |
373 end | |
374 end | |
375 | |
376 % END |