source: prextra/prtools_export.m @ 133

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