source: prextra/prtools_export.m @ 149

Last change on this file since 149 was 143, checked in by bduin, 5 years ago
File size: 9.5 KB
RevLine 
[113]1%PRTOOLS_EXPORT creates and stores PRTools export
2%
3% PRTOOLS_EXPORT(FLAG,EXPORTDIR)
4%
5% Creates, if FLAG is true an export version of PRTools in
6% http://prtools.tudelft.org/files/prtools.zip.
7%
8% If FLAG is false (default) just zip-files in EXPORTDIR are created for
9% inspection and the website is not attached.
10%
11% EXPORTDIR should be the Matlab/prtools_export dir in the PRLab group
12% directory. Default is K:\insy\PRLab\Matlab\prtools_export
13%
14% The intention is that this routine works on the PC as well as on the Unix
15% platform. The latter, however, has not yet been tested.
16%
17% Save trials are prtools_export, prtools_export(0), prtools_export(0,dir)
18% and inspect the prtools_export directory.
19%
20% This m-file should be located in PREXTRA, which should be in the path,
21% as it needs the overruled FTP commands located in PREXTRA
22%
23% Bob Duin 31 Aug 2016
24
25function prtools_export(doit,exportdir)
26
27if nargin < 2, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
28if nargin < 1, doit = false; end
29
30prdir = fileparts(which(mfilename));
31%exportdir = fullfile(prdir,'prtools_export'); % maybe to be located elsewwhere
32curdir = pwd;
33[~,prdirdir] = fileparts(prdir);
34if ~strcmp(prdirdir,'prextra')
35  error('prtools_export should be located in the prextra directory')
36end
37
38% create temp dir
39prtmp = fullfile(prdir,'tmp');
40if exist(prtmp,'dir') ~= 7
41  mkdir(prtmp);
42end
43
44% get rid of prtools in the path
[143]45prtools_path = which('fisherc');
46if ~isempty(prtools_path)
47  prtools_path = fileparts(prtools_path);
48  rmpath(prtools_path);
[113]49end
50
51cd(prtmp);
52dd = dir;
53n=strmatch('prtools',{dd.name},'exact');
54if ~isempty(n)
55  rmdir('prtools','s');
56end
57   
58% checkout present PRTools version
59if isunix
60  s = unix('svn co https://svn-mede.ewi.tudelft.nl/MM-ICT/PRTOOLS prtools');
61elseif ispc
62  fprintf(1,'    Tortoise will pop up, find it and click OK 2x');
63  s = dos('TortoiseProc.exe /command:checkout /url:"https://svn-mede.ewi.tudelft.nl/MM-ICT/PRTOOLS" /path:prtools');
64  fprintf(1,'\n');
65  input('    Ready to continue?');
66else
67  error('svn checkout not implemented for Mac')
68end
69if (s~=0)
70  error('Error in running svn: could not checkout prtools')
71end
72
73% adjust version number
74addpath(fullfile(pwd,'prtools'))
75pver  = prtver;
[143]76pver = pver{1}.Version;
77fprintf(1,'    Present PRTools version is %s\n',pver);
78pver_new = input(['    Give new version number: [' pver '] '],'s');
79if ~isempty(pver_new)
80  set_version_in_Contents(pver_new);
81  pver = pver_new;
82  % Commit version change
83  if isunix
84    s = unix(['svn ci ' fullfile('prtools','Contents.m')]);
85  elseif ispc
86    fprintf(1,'    Tortoise will pop up to commit change version number in Contents, find it and click OK 2x')
87    s = dos(['TortoiseProc.exe /command:commit /path:' fullfile('prtools','Contents.m')]);
88    fprintf(1,'\n');
89    input('    Ready to continue?');
90  else
91    error(['svn commit not implemented for Mac'])
92  end
[113]93end
94 
95% Delete all svn files
96fprintf(1,'    Removing all svn files ... \n');
97if isunix
98  unix('chmod -R +w prtools');
99  unix('\rm -rf prtools/.svn prtools/*/.svn');
100elseif ispc
101  dos('rmdir /S /Q prtools\.svn');
102  dos('rmdir /S /Q prtools\@prdataset\.svn');
103  dos('rmdir /S /Q prtools\@prdatafile\.svn');
104  dos('rmdir /S /Q prtools\@prmapping\.svn');
105  dos('rmdir /S /Q prtools\private\.svn');
106end
107
[133]108% Create export version in dir2, RD: not needed anymore from 2019
[113]109today = datestr(date,'ddmmmyy');
[133]110% exporttemp = fullfile(prtmp,['prtex' pver_new '.' today]);
111% mkdir(exporttemp);
112% dir1 = fileparts(which('fisherc'));
113% dir2 = fullfile(exporttemp,'prtools');
114% mkdir(dir2);
115% copydirm(dir1,dir2); % copy main dir
116% copydirm(fullfile(dir1,'private'),fullfile(dir2,'private'),'all'); % copy private as it is
117% copydirm(fullfile(dir1,'@prdataset'),fullfile(dir2,'@prdataset'),'%'); % copy headers only
118% copydirm(fullfile(dir1,'@prdatafile'),fullfile(dir2,'@prdatafile'),'%'); % copy headers only
119% copydirm(fullfile(dir1,'@prmapping'),fullfile(dir2,'@prmapping'),'%'); % copy headers only
[113]120
[133]121% Generate pcodes. RD: we stopped this in 2019
122% fprintf(1,'    Generating pcodes ... \n');
123% cd(fullfile(dir2,'@prdataset')); pcode(fullfile(dir1,'@prdataset'));  % generate pcode in dir2/@dataset
124% cd(fullfile(dir2,'@prdatafile')); pcode(fullfile(dir1,'@prdatafile')); % generate pcode in dir2/@datafile
125% cd(fullfile(dir2,'@prmapping')); pcode(fullfile(dir1,'@prmapping'));  % generate pcode in dir2/@mapping
[113]126
127% Create zip-files
128fprintf(1,'    Creating zip files ... \n');
[133]129exporttemp = prtmp; % RD: starting 2019, no separate exporttemp is needed
[113]130cd(exportdir);
131copyfile('License.txt',exporttemp,'f');
132copyfile('Install_notes.txt',exporttemp,'f');
133copyfile('Release_notes.txt',exporttemp,'f');
[143]134exppfiles = ['prtex' pver '.' today '.zip'];
135mfiles = ['prtools' pver '.' today '.zip'];
[133]136zip(exppfiles,{'prtools','License.txt','Install_notes.txt','Release_notes.txt'},exporttemp);
[113]137zip(mfiles,[fullfile(prtmp,'prtools') '/*']);
[143]138
139% Clean and reconstruct path
140rmpath(fullfile(prtmp,'prtools'));
[113]141rmdir(prtmp,'s');
[143]142if ~isempty(prtools_path)
143  addpath(prtools_path);
144end
[113]145 
146if doit
147  fprintf(1,'    FTP PRTools zip-file to website ... \n');
[133]148  % store export files on website
[128]149  ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
[113]150  cd(ftpsite,'httpdocs/files');
[133]151  mput(ftpsite,exppfiles);
152  rename(ftpsite,exppfiles,'prtools.zip');
[143]153  disp('    export files have been stored on the website.')
154  disp('    Please check and adjust release notes and known problems on website')
[113]155  close(ftpsite)
156 
157  % backup p-files and m-files
[133]158  fprintf(1,'    Storing backups of mfiles and export files ... \n');
159  [s,mess] = copyfile(exppfiles,fullfile(exportdir,'prtools_old_export'));
[113]160  if s
[133]161    delete(exppfiles);
[143]162    disp(['    export files have been backed-up in ' exportdir])
[113]163  else
164    disp(mess);
165  end
[128]166  [s,mess] = copyfile(mfiles,fullfile(exportdir,'prtools_old_archive'));
[113]167  if s
168    delete(mfiles);
[143]169    disp(['    m-files have been backed-up in ' exportdir])
[113]170  else
171    disp(mess);
172  end
[143]173else
174  fprintf(1,'    The zip-files have been created in exportdir.\n');
175  fprintf(1,'    They have not been copied to the website!\n');
176  fprintf(1,'    If needed, rerun with flag set.\n');
[113]177end
178   
179cd(curdir)
180
181       
182%COPYDIRM Copy mfiles from dir to dir
183function copydirm(dir1,dir2,type)
184if nargin < 3
185        type = 'm';
186end
187if exist(dir2) ~= 7
188        [parentdir,subdir] = fileparts(dir2);
189        mkdir(parentdir,subdir);
190end
191[f1,f2] = fileparts(dir2);
192%disp(['Copying ' f2]);
193switch type
194case {'m','%'}
195        if isunix
196                unix(['cp ' dir1 '/*.m ' dir2]);
197        else
198                list = dir([dir1 '/*.m']);
199        end
200case {'p'}
201        if isunix
202                unix(['cp ' dir1 '/*.p ' dir2]);
203        else
204                list = dir([dir1 '/*.p']);
205        end
206case {'qld'}
207        if isunix
208                unix(['cp ' dir1 '/qld.dl* ' dir2]);
209                unix(['cp ' dir1 '/qld.mex* ' dir2]);
210        else
211                list = dir([dir1 '/qld.dl*']);
212                list = [list; dir([dir1 '/qld.mex*'])];
213  end
214otherwise
215        if isunix
216                unix(['cp ' dir1 '/* ' dir2]);
217        else
218                list = dir([dir1 '/*']);
219        end
220
221end
222if ~isunix
223        k = length(list);
224        for i = 1:k
225                %disp(['File copy ' list(i).name]);
226                if ~list(i).isdir
227                        copyfile(fullfile(dir1,list(i).name),fullfile(dir2,list(i).name));
228                end
229        end
230end
231
232if strcmp(type,'%')
233        list = dir(dir2);
234        k = length(list);
235        for i=1:k
236                %disp(['File reduce ' list(i).name]);
237                if ~list(i).isdir
238                        r = gethf(fullfile(dir2,list(i).name));
239                        writf(fullfile(dir2,list(i).name),r);                   
240                end
241        end
242end
243
244%LISTN List lines specified by their line number
245%
246% t = listn(r,n)
247% Get the lines in r given by the line numbers in n.
248function t = listn(r,n)
249nlchar = setstr(10); % use Windows / Unix newline char
250k = [0,find(r==nlchar)];
251t = [];
252for j = n
253    t = [t,r(k(j)+1:k(j+1))];
254end
255return
256
257%GETHFT Create heading file from m-file
258%
259%       s = gethf(file)
260%
261% The heading of the given m-file consisting of all starting % lines
262% is isolated and returned in s.
263
264function s = gethf(file)
265[s,ns] = readf(file);
266p=grep(s,'%');
267if isempty(p), p = 0; end
268I = find(p - [0,p(1:length(p)-1)] ~= 1);
269if p(1) == 1 & isempty(I), I = length(p) + 1; end
270if length(I) > 0 & I(1) > 1
271        n = I(1) - 1;
272        s = listn(s,1:n);
273else
274        s = '';
275end
276
277%GREP Get line specific lines
278%
279% n = grep(r,s)
280% Get the numbers of all lines in the set of lines r
281% that contain s.
282
283function k = grep(r,s)
284n = [0,find(r==newline)];
285m = findstr(r,s);
286[i,j] = sort([n,m]);;
287q = [0,j(1:length(j)-1)]-j;
288k = j(find(q>0))-1;
289return
290
291function [s,n] = readf(file)
292fid = fopen(file);
293if fid < 0
294        error(['File ' file ' not found, probably wrong directory'])
295end
296[s,n] = fread(fid);
297if isempty(s)
298  error(['File ' file ' could not be read'])
299end
300s = s(:)';
301fclose(fid);
302
303function writf(file,s)
304filedir = fileparts(which(file));
305fid = fopen(fullfile(filedir,file),'w');
306if fid < 0
307        error(['File ' file ' could not be opened for writing'])
308end
309fwrite(fid,s);
310fclose(fid);
311
312function set_version_in_Contents(prtv)
313if ~isstr(prtv)
314        error('Version should be given as string, e.g. ''3.2.7''')
315end
316s = readf('Contents.m');
317n = findstr(s,newline);
318r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
319writf('Contents.m',r);
320disp('    Contents.m rewritten with new version number')
321
322function myedit(file)
323
324try
325  edit(file);
326catch
327  if isunix
328    s = input('    Could not find editor, OK to open vi? [yes]/no: ','s');
329    if isempty(s) | strcmp(s,'yes')
330      unix(['vi ' file]);
331    else
332      disp(['    Could not open ' file ' for editing']);
333    end
334  else
335    disp(['    Could not open ' file ' for editing']);
336  end
337end
Note: See TracBrowser for help on using the repository browser.