%TOOLBOX_EXPORT Prepare toolbox for export, archive and send to website % % TOOLBOX_EXPORT(TOOLBOX,COPYFLAG,EXCLUDE,ARCHIVE) % % zip and copy TOOLBOX to PRTools server and archive in ARCHIVE. In case % COPYFLAG is false (default) copying to the server is skipped. % % The tooolbox version as stored in the Contents.m file is interactively % updated. In addition a TOOLBOX_version.txt file is created or updated on % the server. Sub-directories of TOOLBOX given as a cell array in EXCLUDE % will not be stored in the zip-file. Other sub-directories will be % compressed as they are. In the main toolbox directory just the m-files % are used. % % TOOLBOX should be in the search path and has to be given by the name % only. % % The default for ARCHIVE is the prtools_export dir in the group server: % \\srv051.tudelft.net\staff-groups-ewi\insy\PRLab\Matlab\prtools_export % Copyright: R.P.W. Duin function toolbox_export(toolbox,copyflag,exclude,archive) if nargin < 4 || isempty(archive) archive = '\\srv051.tudelft.net\staff-groups-ewi\insy\PRLab\Matlab\prtools_export'; end if nargin < 3, exclude = []; end if nargin < 2 || isempty(copyflag); copyflag = false; end if ischar(exclude), exclude = {exclude}; end if exist(archive,'dir') ~= 7 error(['Archive directory .\insy\PRLab\Matlab\prtools_export not found.' ... newline 'Define it in the ARCHIVE parameter.']) end % check toolbox s = which([toolbox '/Contents.m']); if isempty(s) error(['Toolbox ' toolbox ' is not found in the path or it has no proper Contents.m file']); end % create temp dir zipdir = fullfile(fileparts(which(mfilename)),'tmp'); makedir(zipdir); if exist(fullfile(zipdir,toolbox),'dir') == 7 rmdir(fullfile(zipdir,toolbox),'s'); end % get names and version today = datestr(date,'ddmmmyy'); toolboxdir = fileparts(which(fullfile(toolbox,'Contents'))); [~,toolboxname] = fileparts(toolboxdir); toolboxver = ver(toolboxdir); % get and set possibly new version number in Content file fprintf(1,' Present %s version is %s\n',toolbox,toolboxver(end).Version); pver_new = input([' Give new version number: [' toolboxver(end).Version '] '],'s'); if isempty(pver_new) pver_new = toolboxver(end).Version; else set_version_in_Contents(toolboxdir,pver_new); end % use a copy of TOOLBOX for cleaning and compression disp(' Copying, cleaning and compression make take some time ...') copyfile(toolboxdir,fullfile(zipdir,toolbox)); toolboxdir = fullfile(zipdir,toolbox); % zip zfilename = [toolbox pver_new '_' today '.zip']; ztoolbox = fullfile(zipdir,zfilename); sdir = dirnames(toolboxdir); for j=1:numel(sdir) % remove all hidden dirs (.svn) rmdir(fullfile(fullfile(toolboxdir,sdir{j}),'.svn'),'s'); end if ~isempty(exclude) for j=1:numel(exclude) n = strmatch(exclude{j},sdir); if isempty(n) warning(['Subdirectory ' exclude{j} ' does not exist. Exclusion is skipped']) else sdir(n) = []; end end end zip(ztoolbox,[{'*.m'} sdir{:}],toolboxdir); % use or create specific archdir for this toolbox archdir = fullfile(archive,toolboxname); makedir(archdir); if copyflag % copy to website, use the @ftp package ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c'); cd(ftpsite,'httpdocs/files'); mput(ftpsite,ztoolbox); rename(ftpsite,zfilename,[toolboxname '.zip']); disp(' Export files have been stored on the website.') disp(' Please check and adjust release notes and known problems on website') webversion(pver_new,toolboxname,ftpsite); % reset the version file close(ftpsite) % backup in exportdir fprintf(1,' Storing backups of mfiles and export files ... \n'); [s,mess] = copyfile(ztoolbox,archdir); if s disp([' Export files have been archived in' newline ' ' archdir]) else disp(mess); end else copyfile(ztoolbox,archdir); disp([' The zip-files have been created in ' archdir]); disp([' They have not been copied to the website!']); disp([' If needed, rerun with flag set']); end % cleanup rmdir(zipdir,'s') function set_version_in_Contents(toolbox,prtv) if ~isstr(prtv) error('Version should be given as string, e.g. ''3.2.7''') end contentfile = fullfile(toolbox,'Contents.m'); s = readf(contentfile); n = findstr(s,newline); r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)]; writf(contentfile,r); disp(' Contents.m rewritten with new version number') function [subdirs,files] = dirnames(dirname,ext) %DIRNAMES % % [SUBDIRS,FILES]= DIRNAMES(DIR,EXT) % %Get names of all subdirs and files in direcotory DIR. %Hidden files, . and .. and Thumbs.db neglected if nargin == 0 dirname = '.'; end if nargin > 1 allnames = dir([dirname '/*.' ext]); else allnames = dir(dirname); end n = length(allnames); subdirs = cell(1,n); files = cell(1,n); ns = 0; nf = 0; for j=1:n name = deblank(allnames(j).name); if (name(1) ~= '.') && ~strcmp(name,'Thumbs.db') % skip hidden files if allnames(j).isdir ns = ns+1; subdirs{ns} = name; else nf = nf+1; files{nf} = name; end end end if ns > 0 subdirs = char(subdirs(1:ns)); subdirs = cellstr(subdirs); else subdirs = {''}; end if nf > 0 files = char(files(1:nf)); files = cellstr(files); else files = []; end function makedir(name) %MAKEDIR make directory if needed if exist(name,'dir') ~= 7 mkdir(name) end function [s,n] = readf(file) fid = fopen(file); if fid < 0 error(['File ' file ' not found, probably wrong directory']) end [s,n] = fread(fid); if isempty(s) error(['File ' file ' could not be read']) end s = s(:)'; fclose(fid); function writf(file,s) fid = fopen(file,'w'); if fid < 0 error(['File ' file ' could not be opened for writing']) end fwrite(fid,s); fclose(fid);