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