source: prextra/toolbox_export.m @ 156

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