Changeset 147


Ignore:
Timestamp:
01/08/20 19:13:06 (5 years ago)
Author:
bduin
Message:
 
Location:
prextra
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • prextra/toolbox_export.m

    r145 r147  
    77% COPYFLAG:  TRUE: copy, FALSE: just zip. default TRUE
    88
    9 function toolbox_export(toolbox,copyflag,exportdir)
     9function toolbox_export(toolbox,copyflag,exportdir,exclude)
    1010
    11 
     11if nargin < 4, exclude = []; end
    1212if nargin < 3, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
    1313if nargin < 2 || isempty(copyflag); copyflag = false; end
     14if ischar(exclude), exclude = {exclude}; end
     15
     16% check toolbox
     17s = which([toolbox '/Contents.m']);
     18if isempty(s)
     19  error(['Toolbox ' toolbox ' is not found or has no Contents.m file']);
     20end
    1421
    1522% create temp dir
    1623zipdir = fullfile(fileparts(which(mfilename)),'tmp');
    17 if exist(zipdir,'dir') ~= 7
    18   mkdir(zipdir);
    19 end
     24makedir(zipdir);
    2025
    21 toolboxpath = fileparts(which(fullfile(toolbox,'Contents')));
     26% get names and version
     27today           = datestr(date,'ddmmmyy');
     28toolboxpath     = fileparts(which(fullfile(toolbox,'Contents')));
    2229[~,toolboxname] = fileparts(toolboxpath);
    23 toolboxver = ver(toolboxpath);
     30toolboxver      = ver(toolboxpath);
     31
     32% get and set possibly new version number in Content file
    2433fprintf(1,'    Present %s version is %s\n',toolbox,toolboxver(end).Version);
    2534pver_new = input(['    Give new version number: [' toolboxver(end).Version '] '],'s');
     
    2837end
    2938set_version_in_Contents(toolboxpath,pver_new);
    30 ztoolbox = fullfile(zipdir,[toolbox pver_new '.' today '.zip']);
    31 zip(ztoolbox,{'*.m'},toolboxpath);
    32 copyfile(ztoolbox,exportdir);
     39
     40% zip
     41zfilename = [toolbox pver_new '_' today '.zip'];
     42ztoolbox  = fullfile(zipdir,zfilename);
     43sdir      = dirnames(toolboxpath);
     44if ~isempty(exclude)
     45  for j=1:numel(exclude)
     46    n = strmatch(exclude{j},sdir);
     47    if isempty(n)
     48      error(['Subdirectory ' exclude{j} ' does not exist'])
     49    end
     50    sdir(n) = [];
     51  end
     52end
     53zip(ztoolbox,[{'*.m'} sdir{:}],toolboxpath);
     54
     55% create specific archdir for this toolbox
     56archdir = fullfile(exportdir,toolboxname);
     57makedir(archdir);
    3358
    3459if copyflag
     60  % copy to website, use the @ftp package
    3561  ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
    3662  cd(ftpsite,'httpdocs/files');
    3763  mput(ftpsite,ztoolbox);
    38   rename(ftpsite,ztoolbox,[toolboxname '.zip']);
    39   disp('    export files have been stored on the website.')
     64  rename(ftpsite,zfilename,[toolboxname '.zip']);
     65  disp('    Export files have been stored on the website.')
    4066  disp('    Please check and adjust release notes and known problems on website')
     67  webversion(pver_new,toolboxname,ftpsite); % reset the version file
    4168  close(ftpsite)
    4269 
    43   % backup p-files and m-files
     70  % backup in exportdir
    4471  fprintf(1,'    Storing backups of mfiles and export files ... \n');
    45   [s,mess] = copyfile(ztoolbox,fullfile(exportdir,toolboxname));
     72  [s,mess] = copyfile(ztoolbox,archdir);
    4673  if s
    47     delete(exppfiles);
    48     disp(['    export files have been backed-up in ' exportdir])
     74    disp(['    export files have been backed-up in ' archdir])
    4975  else
    5076    disp(mess);
    5177  end
    5278else
    53   fprintf(1,'    The zip-files have been created in exportdir.\n');
    54   fprintf(1,'    They have not been copied to the website!\n');
    55   fprintf(1,'    If needed, rerun with flag set.\n');
     79  copyfile(ztoolbox,archdir);
     80  disp(['    The zip-files have been created in ' archdir]);
     81  disp(['    They have not been copied to the website!']);
     82  disp(['    If needed, rerun with flag set']);
    5683end
     84% cleanup
     85rmdir(zipdir,'s')
    5786
    5887function set_version_in_Contents(toolbox,prtv)
     88
    5989if ~isstr(prtv)
    6090        error('Version should be given as string, e.g. ''3.2.7''')
     
    6292contentfile = fullfile(toolbox,'Contents.m');
    6393s = readf(contentfile);
    64 n = findstr(s,prnewline);
     94n = findstr(s,newline);
    6595r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
    6696writf(contentfile,r);
    6797disp('    Contents.m rewritten with new version number')
     98
     99
     100function [subdirs,files] = dirnames(dirname,ext)
     101%DIRNAMES
     102%
     103%       [SUBDIRS,FILES]= DIRNAMES(DIR,EXT)
     104%
     105%Get names of all subdirs and files in direcotory DIR.
     106%Hidden files, . and .. and Thumbs.db neglected
     107
     108if nargin == 0
     109  dirname = '.';
     110end
     111
     112if nargin > 1
     113  allnames = dir([dirname '/*.' ext]);
     114else
     115  allnames = dir(dirname);
     116end
     117n = length(allnames);
     118subdirs = cell(1,n);
     119files = cell(1,n);
     120ns = 0;
     121nf = 0;
     122
     123for j=1:n
     124  name = deblank(allnames(j).name);
     125        if (name(1) ~= '.') && ~strcmp(name,'Thumbs.db') % skip hidden files
     126                if allnames(j).isdir
     127                        ns = ns+1;
     128                        subdirs{ns} = name;
     129                else
     130                        nf = nf+1;
     131                        files{nf} = name;
     132                end
     133        end
     134end
     135
     136if ns > 0
     137        subdirs = char(subdirs(1:ns));
     138  subdirs = cellstr(subdirs);
     139else
     140        subdirs = [];
     141end
     142if nf > 0
     143        files = char(files(1:nf));
     144  files = cellstr(files);
     145else
     146        files = [];
     147end
     148
     149
     150function makedir(name)
     151%MAKEDIR make directory if needed
     152
     153if exist(name,'dir') ~= 7
     154  mkdir(name)
     155end
     156
     157function [s,n] = readf(file)
     158fid = fopen(file);
     159if fid < 0
     160        error(['File ' file ' not found, probably wrong directory'])
     161end
     162[s,n] = fread(fid);
     163if isempty(s)
     164  error(['File ' file ' could not be read'])
     165end
     166s = s(:)';
     167fclose(fid);
     168
     169function writf(file,s)
     170fid = fopen(file,'w');
     171if fid < 0
     172        error(['File ' file ' could not be opened for writing'])
     173end
     174fwrite(fid,s);
     175fclose(fid);
  • prextra/webversion.m

    r144 r147  
    11%WEBVERSION Set version on website
    22%
    3 %  OUT = WEBVERSION(VERSION,TOOLBOX,FTPSITE,DIR)
     3%  OUT = WEBVERSION(VERSION,TOOLBOX,FTPSITE)
    44%
    5 %Creates a file TOOLBOX_version.txt containing just the VERSION number in a
    6 %directory DIR of FTPSITE.
     5%Creates a file TOOLBOX_version.txt containing just the VERSION number on
     6%FTPSITE. FTPSITE should be created by the @FTP package andchanged to the
     7%proper directory.
    78
    89function out = webversion(version,varargin)
    910
    10 [toolbox,ftpsite,dir] = setdefaults(varargin,'prtools',[],'httpdocs/files');
     11[toolbox,ftpsite] = setdefaults(varargin,'prtools',[]);
    1112if isempty(ftpsite)
    1213  ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
     14  cd(ftpsite,'httpdocs/files')
    1315end
    1416
    1517versionfile = fullfile(fileparts(which(mfilename)),[toolbox '_version.txt']);
    1618fid = fopen(versionfile,'w');
    17 fprintf(fid,version);
     19fprintf(fid,['Version ' version ' ' date]);
    1820fclose(fid);
    19 cd(ftpsite,dir);
    2021s = mput(ftpsite,versionfile);
    2122delete(versionfile)
Note: See TracChangeset for help on using the changeset viewer.