[145] | 1 | %TOOLBOX_EXPORT Prepare toolbox for export, archive and send to website
|
---|
| 2 | %
|
---|
[149] | 3 | % TOOLBOX_EXPORT(TOOLBOX,COPYFLAG,EXPORTDIR,EXCLUDE)
|
---|
[145] | 4 | %
|
---|
[149] | 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.
|
---|
[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
|
---|
| 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'
|
---|
[145] | 18 |
|
---|
[149] | 19 | % Copyright: R.P.W. Duin
|
---|
| 20 |
|
---|
[147] | 21 | function toolbox_export(toolbox,copyflag,exportdir,exclude)
|
---|
[145] | 22 |
|
---|
[147] | 23 | if nargin < 4, exclude = []; end
|
---|
[145] | 24 | if nargin < 3, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
|
---|
| 25 | if nargin < 2 || isempty(copyflag); copyflag = false; end
|
---|
[147] | 26 | if ischar(exclude), exclude = {exclude}; end
|
---|
[145] | 27 |
|
---|
[147] | 28 | % check toolbox
|
---|
| 29 | s = which([toolbox '/Contents.m']);
|
---|
| 30 | if isempty(s)
|
---|
| 31 | error(['Toolbox ' toolbox ' is not found or has no Contents.m file']);
|
---|
| 32 | end
|
---|
| 33 |
|
---|
[145] | 34 | % create temp dir
|
---|
| 35 | zipdir = fullfile(fileparts(which(mfilename)),'tmp');
|
---|
[147] | 36 | makedir(zipdir);
|
---|
[145] | 37 |
|
---|
[147] | 38 | % get names and version
|
---|
| 39 | today = datestr(date,'ddmmmyy');
|
---|
| 40 | toolboxpath = fileparts(which(fullfile(toolbox,'Contents')));
|
---|
[145] | 41 | [~,toolboxname] = fileparts(toolboxpath);
|
---|
[147] | 42 | toolboxver = ver(toolboxpath);
|
---|
| 43 |
|
---|
| 44 | % get and set possibly new version number in Content file
|
---|
[145] | 45 | fprintf(1,' Present %s version is %s\n',toolbox,toolboxver(end).Version);
|
---|
| 46 | pver_new = input([' Give new version number: [' toolboxver(end).Version '] '],'s');
|
---|
| 47 | if isempty(pver_new)
|
---|
| 48 | pver_new = toolboxver(end).Version;
|
---|
| 49 | end
|
---|
| 50 | set_version_in_Contents(toolboxpath,pver_new);
|
---|
| 51 |
|
---|
[147] | 52 | % zip
|
---|
| 53 | zfilename = [toolbox pver_new '_' today '.zip'];
|
---|
| 54 | ztoolbox = fullfile(zipdir,zfilename);
|
---|
| 55 | sdir = dirnames(toolboxpath);
|
---|
| 56 | if ~isempty(exclude)
|
---|
| 57 | for j=1:numel(exclude)
|
---|
| 58 | n = strmatch(exclude{j},sdir);
|
---|
| 59 | if isempty(n)
|
---|
[149] | 60 | warning(['Subdirectory ' exclude{j} ' does not exist and is skipped'])
|
---|
| 61 | else
|
---|
| 62 | sdir(n) = [];
|
---|
[147] | 63 | end
|
---|
| 64 | end
|
---|
| 65 | end
|
---|
| 66 | zip(ztoolbox,[{'*.m'} sdir{:}],toolboxpath);
|
---|
| 67 |
|
---|
| 68 | % create specific archdir for this toolbox
|
---|
| 69 | archdir = fullfile(exportdir,toolboxname);
|
---|
| 70 | makedir(archdir);
|
---|
| 71 |
|
---|
[145] | 72 | if copyflag
|
---|
[147] | 73 | % copy to website, use the @ftp package
|
---|
[145] | 74 | ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
|
---|
| 75 | cd(ftpsite,'httpdocs/files');
|
---|
| 76 | mput(ftpsite,ztoolbox);
|
---|
[147] | 77 | rename(ftpsite,zfilename,[toolboxname '.zip']);
|
---|
| 78 | disp(' Export files have been stored on the website.')
|
---|
[145] | 79 | disp(' Please check and adjust release notes and known problems on website')
|
---|
[147] | 80 | webversion(pver_new,toolboxname,ftpsite); % reset the version file
|
---|
[145] | 81 | close(ftpsite)
|
---|
| 82 |
|
---|
[147] | 83 | % backup in exportdir
|
---|
[145] | 84 | fprintf(1,' Storing backups of mfiles and export files ... \n');
|
---|
[147] | 85 | [s,mess] = copyfile(ztoolbox,archdir);
|
---|
[145] | 86 | if s
|
---|
[147] | 87 | disp([' export files have been backed-up in ' archdir])
|
---|
[145] | 88 | else
|
---|
| 89 | disp(mess);
|
---|
| 90 | end
|
---|
| 91 | else
|
---|
[147] | 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']);
|
---|
[145] | 96 | end
|
---|
[147] | 97 | % cleanup
|
---|
| 98 | rmdir(zipdir,'s')
|
---|
[145] | 99 |
|
---|
| 100 | function set_version_in_Contents(toolbox,prtv)
|
---|
[147] | 101 |
|
---|
[145] | 102 | if ~isstr(prtv)
|
---|
| 103 | error('Version should be given as string, e.g. ''3.2.7''')
|
---|
| 104 | end
|
---|
| 105 | contentfile = fullfile(toolbox,'Contents.m');
|
---|
| 106 | s = readf(contentfile);
|
---|
[147] | 107 | n = findstr(s,newline);
|
---|
[145] | 108 | r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
|
---|
| 109 | writf(contentfile,r);
|
---|
[147] | 110 | disp(' Contents.m rewritten with new version number')
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | function [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 |
|
---|
| 121 | if nargin == 0
|
---|
| 122 | dirname = '.';
|
---|
| 123 | end
|
---|
| 124 |
|
---|
| 125 | if nargin > 1
|
---|
| 126 | allnames = dir([dirname '/*.' ext]);
|
---|
| 127 | else
|
---|
| 128 | allnames = dir(dirname);
|
---|
| 129 | end
|
---|
| 130 | n = length(allnames);
|
---|
| 131 | subdirs = cell(1,n);
|
---|
| 132 | files = cell(1,n);
|
---|
| 133 | ns = 0;
|
---|
| 134 | nf = 0;
|
---|
| 135 |
|
---|
| 136 | for 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
|
---|
| 147 | end
|
---|
| 148 |
|
---|
| 149 | if ns > 0
|
---|
| 150 | subdirs = char(subdirs(1:ns));
|
---|
| 151 | subdirs = cellstr(subdirs);
|
---|
| 152 | else
|
---|
[149] | 153 | subdirs = {''};
|
---|
[147] | 154 | end
|
---|
| 155 | if nf > 0
|
---|
| 156 | files = char(files(1:nf));
|
---|
| 157 | files = cellstr(files);
|
---|
| 158 | else
|
---|
| 159 | files = [];
|
---|
| 160 | end
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | function makedir(name)
|
---|
| 164 | %MAKEDIR make directory if needed
|
---|
| 165 |
|
---|
| 166 | if exist(name,'dir') ~= 7
|
---|
| 167 | mkdir(name)
|
---|
| 168 | end
|
---|
| 169 |
|
---|
| 170 | function [s,n] = readf(file)
|
---|
| 171 | fid = fopen(file);
|
---|
| 172 | if fid < 0
|
---|
| 173 | error(['File ' file ' not found, probably wrong directory'])
|
---|
| 174 | end
|
---|
| 175 | [s,n] = fread(fid);
|
---|
| 176 | if isempty(s)
|
---|
| 177 | error(['File ' file ' could not be read'])
|
---|
| 178 | end
|
---|
| 179 | s = s(:)';
|
---|
| 180 | fclose(fid);
|
---|
| 181 |
|
---|
| 182 | function writf(file,s)
|
---|
| 183 | fid = fopen(file,'w');
|
---|
| 184 | if fid < 0
|
---|
| 185 | error(['File ' file ' could not be opened for writing'])
|
---|
| 186 | end
|
---|
| 187 | fwrite(fid,s);
|
---|
| 188 | fclose(fid);
|
---|