source: prextra/toolbox_export.m @ 155

Last change on this file since 155 was 149, checked in by bduin, 5 years ago
File size: 5.0 KB
Line 
1%TOOLBOX_EXPORT Prepare toolbox for export, archive and send to website
2%
3% TOOLBOX_EXPORT(TOOLBOX,COPYFLAG,EXPORTDIR,EXCLUDE)
4%
5% zip and copy TOOLBOX to PRTools server and archive in EXPORTDIR. In case
6% COPYFLAG is false (default) copying to the server is skipped.
7%
8% The tooolbox version as stored in the Contents.m file is interactively
9% updated. In addition a TOOLBOX_version.txt file is created or updated on
10% the server. Sub-directories of TOOLBOX given as a cell array in EXCLUDE
11% will not be stored in the zip-file. Other sub-directories will compressed
12% as they are. In the main toolbox directory just the m-files are used.
13%
14% TOOLBOX should be in the search path and has to be given by the name
15% only.
16%
17% The default for EXPORTDIR is 'K:\insy\PRLab\Matlab\prtools_export'
18
19% Copyright: R.P.W. Duin
20
21function toolbox_export(toolbox,copyflag,exportdir,exclude)
22
23if nargin < 4, exclude = []; end
24if nargin < 3, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
25if nargin < 2 || isempty(copyflag); copyflag = false; end
26if ischar(exclude), exclude = {exclude}; end
27
28% check toolbox
29s = which([toolbox '/Contents.m']);
30if isempty(s)
31  error(['Toolbox ' toolbox ' is not found or has no Contents.m file']);
32end
33
34% create temp dir
35zipdir = fullfile(fileparts(which(mfilename)),'tmp');
36makedir(zipdir);
37
38% get names and version
39today           = datestr(date,'ddmmmyy');
40toolboxpath     = fileparts(which(fullfile(toolbox,'Contents')));
41[~,toolboxname] = fileparts(toolboxpath);
42toolboxver      = ver(toolboxpath);
43
44% get and set possibly new version number in Content file
45fprintf(1,'    Present %s version is %s\n',toolbox,toolboxver(end).Version);
46pver_new = input(['    Give new version number: [' toolboxver(end).Version '] '],'s');
47if isempty(pver_new)
48  pver_new = toolboxver(end).Version;
49end
50set_version_in_Contents(toolboxpath,pver_new);
51
52% zip
53zfilename = [toolbox pver_new '_' today '.zip'];
54ztoolbox  = fullfile(zipdir,zfilename);
55sdir      = dirnames(toolboxpath);
56if ~isempty(exclude)
57  for j=1:numel(exclude)
58    n = strmatch(exclude{j},sdir);
59    if isempty(n)
60      warning(['Subdirectory ' exclude{j} ' does not exist and is skipped'])
61    else
62      sdir(n) = [];
63    end
64  end
65end
66zip(ztoolbox,[{'*.m'} sdir{:}],toolboxpath);
67
68% create specific archdir for this toolbox
69archdir = fullfile(exportdir,toolboxname);
70makedir(archdir);
71
72if copyflag
73  % copy to website, use the @ftp package
74  ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
75  cd(ftpsite,'httpdocs/files');
76  mput(ftpsite,ztoolbox);
77  rename(ftpsite,zfilename,[toolboxname '.zip']);
78  disp('    Export files have been stored on the website.')
79  disp('    Please check and adjust release notes and known problems on website')
80  webversion(pver_new,toolboxname,ftpsite); % reset the version file
81  close(ftpsite)
82 
83  % backup in exportdir
84  fprintf(1,'    Storing backups of mfiles and export files ... \n');
85  [s,mess] = copyfile(ztoolbox,archdir);
86  if s
87    disp(['    export files have been backed-up in ' archdir])
88  else
89    disp(mess);
90  end
91else
92  copyfile(ztoolbox,archdir);
93  disp(['    The zip-files have been created in ' archdir]);
94  disp(['    They have not been copied to the website!']);
95  disp(['    If needed, rerun with flag set']);
96end
97% cleanup
98rmdir(zipdir,'s')
99
100function set_version_in_Contents(toolbox,prtv)
101
102if ~isstr(prtv)
103        error('Version should be given as string, e.g. ''3.2.7''')
104end
105contentfile = fullfile(toolbox,'Contents.m');
106s = readf(contentfile);
107n = findstr(s,newline);
108r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
109writf(contentfile,r);
110disp('    Contents.m rewritten with new version number')
111
112
113function [subdirs,files] = dirnames(dirname,ext)
114%DIRNAMES
115%
116%       [SUBDIRS,FILES]= DIRNAMES(DIR,EXT)
117%
118%Get names of all subdirs and files in direcotory DIR.
119%Hidden files, . and .. and Thumbs.db neglected
120
121if nargin == 0
122  dirname = '.';
123end
124
125if nargin > 1
126  allnames = dir([dirname '/*.' ext]);
127else
128  allnames = dir(dirname);
129end
130n = length(allnames);
131subdirs = cell(1,n);
132files = cell(1,n);
133ns = 0;
134nf = 0;
135
136for j=1:n
137  name = deblank(allnames(j).name);
138        if (name(1) ~= '.') && ~strcmp(name,'Thumbs.db') % skip hidden files
139                if allnames(j).isdir
140                        ns = ns+1;
141                        subdirs{ns} = name;
142                else
143                        nf = nf+1;
144                        files{nf} = name;
145                end
146        end
147end
148
149if ns > 0
150        subdirs = char(subdirs(1:ns));
151  subdirs = cellstr(subdirs);
152else
153        subdirs = {''};
154end
155if nf > 0
156        files = char(files(1:nf));
157  files = cellstr(files);
158else
159        files = [];
160end
161
162
163function makedir(name)
164%MAKEDIR make directory if needed
165
166if exist(name,'dir') ~= 7
167  mkdir(name)
168end
169
170function [s,n] = readf(file)
171fid = fopen(file);
172if fid < 0
173        error(['File ' file ' not found, probably wrong directory'])
174end
175[s,n] = fread(fid);
176if isempty(s)
177  error(['File ' file ' could not be read'])
178end
179s = s(:)';
180fclose(fid);
181
182function writf(file,s)
183fid = fopen(file,'w');
184if fid < 0
185        error(['File ' file ' could not be opened for writing'])
186end
187fwrite(fid,s);
188fclose(fid);
Note: See TracBrowser for help on using the repository browser.