source: prextra/toolbox_export.m @ 147

Last change on this file since 147 was 147, checked in by bduin, 5 years ago
File size: 4.4 KB
Line 
1%TOOLBOX_EXPORT Prepare toolbox for export, archive and send to website
2%
3% TOOLBOX_EXPORT(TOOLBOX,COPYFLAG,EXPORTDIR)
4%
5% zip and copy toolbox to PRTools server and erchive in EXPORTDIR
6%
7% COPYFLAG:  TRUE: copy, FALSE: just zip. default TRUE
8
9function toolbox_export(toolbox,copyflag,exportdir,exclude)
10
11if nargin < 4, exclude = []; end
12if nargin < 3, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
13if 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
21
22% create temp dir
23zipdir = fullfile(fileparts(which(mfilename)),'tmp');
24makedir(zipdir);
25
26% get names and version
27today           = datestr(date,'ddmmmyy');
28toolboxpath     = fileparts(which(fullfile(toolbox,'Contents')));
29[~,toolboxname] = fileparts(toolboxpath);
30toolboxver      = ver(toolboxpath);
31
32% get and set possibly new version number in Content file
33fprintf(1,'    Present %s version is %s\n',toolbox,toolboxver(end).Version);
34pver_new = input(['    Give new version number: [' toolboxver(end).Version '] '],'s');
35if isempty(pver_new)
36  pver_new = toolboxver(end).Version;
37end
38set_version_in_Contents(toolboxpath,pver_new);
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);
58
59if copyflag
60  % copy to website, use the @ftp package
61  ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
62  cd(ftpsite,'httpdocs/files');
63  mput(ftpsite,ztoolbox);
64  rename(ftpsite,zfilename,[toolboxname '.zip']);
65  disp('    Export files have been stored on the website.')
66  disp('    Please check and adjust release notes and known problems on website')
67  webversion(pver_new,toolboxname,ftpsite); % reset the version file
68  close(ftpsite)
69 
70  % backup in exportdir
71  fprintf(1,'    Storing backups of mfiles and export files ... \n');
72  [s,mess] = copyfile(ztoolbox,archdir);
73  if s
74    disp(['    export files have been backed-up in ' archdir])
75  else
76    disp(mess);
77  end
78else
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']);
83end
84% cleanup
85rmdir(zipdir,'s')
86
87function set_version_in_Contents(toolbox,prtv)
88
89if ~isstr(prtv)
90        error('Version should be given as string, e.g. ''3.2.7''')
91end
92contentfile = fullfile(toolbox,'Contents.m');
93s = readf(contentfile);
94n = findstr(s,newline);
95r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
96writf(contentfile,r);
97disp('    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);
Note: See TracBrowser for help on using the repository browser.