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 |
|
---|
9 | function toolbox_export(toolbox,copyflag,exportdir,exclude)
|
---|
10 |
|
---|
11 | if nargin < 4, exclude = []; end
|
---|
12 | if nargin < 3, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
|
---|
13 | if nargin < 2 || isempty(copyflag); copyflag = false; end
|
---|
14 | if ischar(exclude), exclude = {exclude}; end
|
---|
15 |
|
---|
16 | % check toolbox
|
---|
17 | s = which([toolbox '/Contents.m']);
|
---|
18 | if isempty(s)
|
---|
19 | error(['Toolbox ' toolbox ' is not found or has no Contents.m file']);
|
---|
20 | end
|
---|
21 |
|
---|
22 | % create temp dir
|
---|
23 | zipdir = fullfile(fileparts(which(mfilename)),'tmp');
|
---|
24 | makedir(zipdir);
|
---|
25 |
|
---|
26 | % get names and version
|
---|
27 | today = datestr(date,'ddmmmyy');
|
---|
28 | toolboxpath = fileparts(which(fullfile(toolbox,'Contents')));
|
---|
29 | [~,toolboxname] = fileparts(toolboxpath);
|
---|
30 | toolboxver = ver(toolboxpath);
|
---|
31 |
|
---|
32 | % get and set possibly new version number in Content file
|
---|
33 | fprintf(1,' Present %s version is %s\n',toolbox,toolboxver(end).Version);
|
---|
34 | pver_new = input([' Give new version number: [' toolboxver(end).Version '] '],'s');
|
---|
35 | if isempty(pver_new)
|
---|
36 | pver_new = toolboxver(end).Version;
|
---|
37 | end
|
---|
38 | set_version_in_Contents(toolboxpath,pver_new);
|
---|
39 |
|
---|
40 | % zip
|
---|
41 | zfilename = [toolbox pver_new '_' today '.zip'];
|
---|
42 | ztoolbox = fullfile(zipdir,zfilename);
|
---|
43 | sdir = dirnames(toolboxpath);
|
---|
44 | if ~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
|
---|
52 | end
|
---|
53 | zip(ztoolbox,[{'*.m'} sdir{:}],toolboxpath);
|
---|
54 |
|
---|
55 | % create specific archdir for this toolbox
|
---|
56 | archdir = fullfile(exportdir,toolboxname);
|
---|
57 | makedir(archdir);
|
---|
58 |
|
---|
59 | if 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
|
---|
78 | else
|
---|
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']);
|
---|
83 | end
|
---|
84 | % cleanup
|
---|
85 | rmdir(zipdir,'s')
|
---|
86 |
|
---|
87 | function set_version_in_Contents(toolbox,prtv)
|
---|
88 |
|
---|
89 | if ~isstr(prtv)
|
---|
90 | error('Version should be given as string, e.g. ''3.2.7''')
|
---|
91 | end
|
---|
92 | contentfile = fullfile(toolbox,'Contents.m');
|
---|
93 | s = readf(contentfile);
|
---|
94 | n = findstr(s,newline);
|
---|
95 | r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
|
---|
96 | writf(contentfile,r);
|
---|
97 | disp(' Contents.m rewritten with new version number')
|
---|
98 |
|
---|
99 |
|
---|
100 | function [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 |
|
---|
108 | if nargin == 0
|
---|
109 | dirname = '.';
|
---|
110 | end
|
---|
111 |
|
---|
112 | if nargin > 1
|
---|
113 | allnames = dir([dirname '/*.' ext]);
|
---|
114 | else
|
---|
115 | allnames = dir(dirname);
|
---|
116 | end
|
---|
117 | n = length(allnames);
|
---|
118 | subdirs = cell(1,n);
|
---|
119 | files = cell(1,n);
|
---|
120 | ns = 0;
|
---|
121 | nf = 0;
|
---|
122 |
|
---|
123 | for 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
|
---|
134 | end
|
---|
135 |
|
---|
136 | if ns > 0
|
---|
137 | subdirs = char(subdirs(1:ns));
|
---|
138 | subdirs = cellstr(subdirs);
|
---|
139 | else
|
---|
140 | subdirs = [];
|
---|
141 | end
|
---|
142 | if nf > 0
|
---|
143 | files = char(files(1:nf));
|
---|
144 | files = cellstr(files);
|
---|
145 | else
|
---|
146 | files = [];
|
---|
147 | end
|
---|
148 |
|
---|
149 |
|
---|
150 | function makedir(name)
|
---|
151 | %MAKEDIR make directory if needed
|
---|
152 |
|
---|
153 | if exist(name,'dir') ~= 7
|
---|
154 | mkdir(name)
|
---|
155 | end
|
---|
156 |
|
---|
157 | function [s,n] = readf(file)
|
---|
158 | fid = fopen(file);
|
---|
159 | if fid < 0
|
---|
160 | error(['File ' file ' not found, probably wrong directory'])
|
---|
161 | end
|
---|
162 | [s,n] = fread(fid);
|
---|
163 | if isempty(s)
|
---|
164 | error(['File ' file ' could not be read'])
|
---|
165 | end
|
---|
166 | s = s(:)';
|
---|
167 | fclose(fid);
|
---|
168 |
|
---|
169 | function writf(file,s)
|
---|
170 | fid = fopen(file,'w');
|
---|
171 | if fid < 0
|
---|
172 | error(['File ' file ' could not be opened for writing'])
|
---|
173 | end
|
---|
174 | fwrite(fid,s);
|
---|
175 | fclose(fid);
|
---|