source: prextra/prtools_export.m @ 116

Last change on this file since 116 was 113, checked in by bduin, 8 years ago
File size: 8.9 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
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
107today = datestr(date,'ddmmmyy');
108exporttemp = fullfile(prtmp,['prtex' pver_new '.' today]);
109mkdir(exporttemp);
110dir1 = fileparts(which('fisherc'));
111dir2 = fullfile(exporttemp,'prtools');
112mkdir(dir2);
113copydirm(dir1,dir2); % copy main dir
114copydirm(fullfile(dir1,'private'),fullfile(dir2,'private'),'all'); % copy private as it is
115copydirm(fullfile(dir1,'@prdataset'),fullfile(dir2,'@prdataset'),'%'); % copy headers only
116copydirm(fullfile(dir1,'@prdatafile'),fullfile(dir2,'@prdatafile'),'%'); % copy headers only
117copydirm(fullfile(dir1,'@prmapping'),fullfile(dir2,'@prmapping'),'%'); % copy headers only
118
119% Generate pcodes
120fprintf(1,'    Generating pcodes ... \n');
121cd(fullfile(dir2,'@prdataset')); pcode(fullfile(dir1,'@prdataset'));  % generate pcode in dir2/@dataset
122cd(fullfile(dir2,'@prdatafile')); pcode(fullfile(dir1,'@prdatafile')); % generate pcode in dir2/@datafile
123cd(fullfile(dir2,'@prmapping')); pcode(fullfile(dir1,'@prmapping'));  % generate pcode in dir2/@mapping
124
125% Create zip-files
126fprintf(1,'    Creating zip files ... \n');
127cd(exportdir);
128copyfile('License.txt',exporttemp,'f');
129copyfile('Install_notes.txt',exporttemp,'f');
130copyfile('Release_notes.txt',exporttemp,'f');
131pfiles = ['prtex' pver_new '.' today '.zip'];
132mfiles = ['prtools' pver_new '.' today '.zip'];
133zip(pfiles,{'prtools','License.txt','Install_notes.txt','Release_notes.txt'},exporttemp);
134zip(mfiles,[fullfile(prtmp,'prtools') '/*']);
135rmdir(prtmp,'s');
136 
137if doit
138  fprintf(1,'    FTP PRTools zip-file to website ... \n');
139  % store p-files on website
140  ftpsite = ftp('prtools.tudelft.nl','prtools','pvG4z1!1');
141  cd(ftpsite,'httpdocs/files');
142  mput(ftpsite,pfiles);
143  rename(ftpsite,pfiles,'prtools.zip');
144  disp('p-files have been stored on the website.')
145  disp('Please check and adjust release notes and known problems on website')
146  close(ftpsite)
147 
148  % backup p-files and m-files
149  fprintf(1,'    Storing backups of mfiles and p-files ... \n');
150  [s,mess] = copyfile(pfiles,fullfile(exportdir,'prtools_old_p'));
151  if s
152    delete(pfiles);
153    disp(['p-files have been backed-up in ' exportdir])
154  else
155    disp(mess);
156  end
157  [s,mess] = copyfile(mfiles,fullfile(exportdir,'prtools_old_m'));
158  if s
159    delete(mfiles);
160    disp(['m-files have been backed-up in ' exportdir])
161  else
162    disp(mess);
163  end
164end
165   
166cd(curdir)
167
168       
169%COPYDIRM Copy mfiles from dir to dir
170function copydirm(dir1,dir2,type)
171if nargin < 3
172        type = 'm';
173end
174if exist(dir2) ~= 7
175        [parentdir,subdir] = fileparts(dir2);
176        mkdir(parentdir,subdir);
177end
178[f1,f2] = fileparts(dir2);
179%disp(['Copying ' f2]);
180switch type
181case {'m','%'}
182        if isunix
183                unix(['cp ' dir1 '/*.m ' dir2]);
184        else
185                list = dir([dir1 '/*.m']);
186        end
187case {'p'}
188        if isunix
189                unix(['cp ' dir1 '/*.p ' dir2]);
190        else
191                list = dir([dir1 '/*.p']);
192        end
193case {'qld'}
194        if isunix
195                unix(['cp ' dir1 '/qld.dl* ' dir2]);
196                unix(['cp ' dir1 '/qld.mex* ' dir2]);
197        else
198                list = dir([dir1 '/qld.dl*']);
199                list = [list; dir([dir1 '/qld.mex*'])];
200  end
201otherwise
202        if isunix
203                unix(['cp ' dir1 '/* ' dir2]);
204        else
205                list = dir([dir1 '/*']);
206        end
207
208end
209if ~isunix
210        k = length(list);
211        for i = 1:k
212                %disp(['File copy ' list(i).name]);
213                if ~list(i).isdir
214                        copyfile(fullfile(dir1,list(i).name),fullfile(dir2,list(i).name));
215                end
216        end
217end
218
219if strcmp(type,'%')
220        list = dir(dir2);
221        k = length(list);
222        for i=1:k
223                %disp(['File reduce ' list(i).name]);
224                if ~list(i).isdir
225                        r = gethf(fullfile(dir2,list(i).name));
226                        writf(fullfile(dir2,list(i).name),r);                   
227                end
228        end
229end
230
231%LISTN List lines specified by their line number
232%
233% t = listn(r,n)
234% Get the lines in r given by the line numbers in n.
235function t = listn(r,n)
236nlchar = setstr(10); % use Windows / Unix newline char
237k = [0,find(r==nlchar)];
238t = [];
239for j = n
240    t = [t,r(k(j)+1:k(j+1))];
241end
242return
243
244%GETHFT Create heading file from m-file
245%
246%       s = gethf(file)
247%
248% The heading of the given m-file consisting of all starting % lines
249% is isolated and returned in s.
250
251function s = gethf(file)
252[s,ns] = readf(file);
253p=grep(s,'%');
254if isempty(p), p = 0; end
255I = find(p - [0,p(1:length(p)-1)] ~= 1);
256if p(1) == 1 & isempty(I), I = length(p) + 1; end
257if length(I) > 0 & I(1) > 1
258        n = I(1) - 1;
259        s = listn(s,1:n);
260else
261        s = '';
262end
263
264%GREP Get line specific lines
265%
266% n = grep(r,s)
267% Get the numbers of all lines in the set of lines r
268% that contain s.
269
270function k = grep(r,s)
271n = [0,find(r==newline)];
272m = findstr(r,s);
273[i,j] = sort([n,m]);;
274q = [0,j(1:length(j)-1)]-j;
275k = j(find(q>0))-1;
276return
277
278function [s,n] = readf(file)
279fid = fopen(file);
280if fid < 0
281        error(['File ' file ' not found, probably wrong directory'])
282end
283[s,n] = fread(fid);
284if isempty(s)
285  error(['File ' file ' could not be read'])
286end
287s = s(:)';
288fclose(fid);
289
290function writf(file,s)
291filedir = fileparts(which(file));
292fid = fopen(fullfile(filedir,file),'w');
293if fid < 0
294        error(['File ' file ' could not be opened for writing'])
295end
296fwrite(fid,s);
297fclose(fid);
298
299function set_version_in_Contents(prtv)
300if ~isstr(prtv)
301        error('Version should be given as string, e.g. ''3.2.7''')
302end
303s = readf('Contents.m');
304n = findstr(s,newline);
305r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
306writf('Contents.m',r);
307disp('    Contents.m rewritten with new version number')
308
309function myedit(file)
310
311try
312  edit(file);
313catch
314  if isunix
315    s = input('    Could not find editor, OK to open vi? [yes]/no: ','s');
316    if isempty(s) | strcmp(s,'yes')
317      unix(['vi ' file]);
318    else
319      disp(['    Could not open ' file ' for editing']);
320    end
321  else
322    disp(['    Could not open ' file ' for editing']);
323  end
324end
Note: See TracBrowser for help on using the repository browser.