source: prextra/prtools_export.m @ 158

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