1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
// Internal function
// Return the full description of
// - TOOLBOXES file present in the differents repositories
// - DESCRIPTION file present in one package
// DESCRIPTION
// |
// |-- packages [1x1 struct]
// | |-- toolbox_1 [1x1 struct]
// | | |-- 2.0 [1x1 struct]
// | | | |-- Toolbox: "toolbox_2"
// | | | |-- Title: "Toolbox Test 2"
// | | | |-- Version: "2.0"
// | | | `-- ..
// | | `-- 1.0 [1x1 struct]
// | | | |-- Toolbox: "toolbox_2"
// | | | |-- Title: "Toolbox Test 2"
// | | | |-- Version: "1.0"
// | | | `-- ..
// | |-- module_lycee
// | `-- ..
// |
// |-- categories [1x1 struct]
// | |-- Optimization [1x1 struct]
// | | |-- Linear
// | | `-- General
// | `-- ..
// |
// |-- categories_flat [1x1 struct]
// |-- Optimization - Linear
// | |-- packages
// | | `-- ["simplex" "1.0" ; "lolimot" "0.9"]
// | `-- label
// | `-- [ "Optimization" "Linear" ]
// |-- Optimization
// | |-- packages
// | | `-- ["simplex" "1.0" ; "lolimot" "0.9"]
// | `-- label
// | `-- [ "Optimization" "Linear" ]
// `-- Education
// |-- packages
// | `-- ["module_lycee" "1.0" ; "module_lycee" "1.1"]
// `-- label
// `-- [ "Education" ]
function description_out = atomsDESCRIPTIONread(file_in,additional)
// Check input parameters
// =========================================================================
rhs = argn(2);
if and(rhs <> [1 2]) then
error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsDESCRIPTIONread",1,2));
end
if regexp( file_in,"/(TOOLBOXES|DESCRIPTION)/") == [] then
error(msprintf(gettext("%s: Wrong value for input argument #%d: String that contains ''TOOLBOXES'' or ''DESCRIPTION'' expected.\n"),"atomsDESCRIPTIONread",1));
end
if rhs < 2 then
additional = struct();
else
if type(additional) <> 17 then
error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsDESCRIPTIONread",2));
end
end
// Init the output argument
// =========================================================================
packages = struct();
categories_flat = struct();
categories = struct();
description_out = struct();
description_out("packages") = packages;
description_out("categories") = categories;
description_out("categories_flat") = categories_flat;
// Operating system detection + Architecture detection
// =========================================================================
[OSNAME, ARCH, LINUX, MACOSX, SOLARIS,BSD] = atomsGetPlatform();
// Start Read the file
// =========================================================================
if ~isfile(file_in) then
error(msprintf(gettext("%s: The file ""%s"" does not exist.\n"), ..
"atomsDESCRIPTIONread", ..
file_in));
end
lines_in = mgetl(file_in);
current_toolbox = struct();
current_field = "";
if isempty(lines_in) then
error(msprintf(gettext("%s: The file ""%s"" is empty.\n"), ..
"atomsDESCRIPTIONread", ..
file_in));
end
winId = atomsOpenProgressBar(_("Updating Atoms modules database..."), %t)
for i=1:(size(lines_in,"*")+1)
atomsUpdateProgressBar(winId, i / size(lines_in,"*"));
// File totally read : register the latest toolbox
if i == (size(lines_in,"*")+1) then
if and(isfield(current_toolbox,["Toolbox";"Version"])) then
if ~ isfield(packages,current_toolbox("Toolbox")) then
// This is the first version of the package
this_toolbox = struct();
else
// Get the version list of this package
this_toolbox = packages(current_toolbox("Toolbox"));
end
// Register the current toolbox : Check the mandatory fields
missingfield = atomsCheckFields( current_toolbox );
if ~ isempty(missingfield) then
atomsCloseProgressBar(winId);
error(msprintf(gettext("%s: The file ""%s"" is not well formated, the toolbox ""%s - %s"" does not contain the %s field\n"), ..
"atomsDESCRIPTIONread",..
file_in,current_toolbox("Toolbox"),..
current_toolbox("Version"),..
missingfield));
end
// Register the current toolbox : Check the scilab version
// comptability
if atomsIsCompatible(current_toolbox("ScilabVersion")) then
if isfield(current_toolbox,"PackagingVersion") then
current_toolbox("Version") = current_toolbox("Version") + "-" + current_toolbox("PackagingVersion");
this_toolbox(current_toolbox("Version")) = current_toolbox;
else
this_toolbox(current_toolbox("Version")) = current_toolbox;
end
end
// Register the current toolbox : Fill the packages struct
packages(current_toolbox("Toolbox")) = this_toolbox;
end
break;
end
// First case : new field
if regexp(lines_in(i),"/^[a-zA-Z0-9]*:\s/","o") == 1 then
// Start new version of toolbox
if regexp(lines_in(i),"/^Toolbox:\s/","o") == 1 then
if and(isfield(current_toolbox,["Toolbox";"Version"])) then
if ~ isfield(packages,current_toolbox("Toolbox")) then
// This is the first version of the package
this_toolbox = struct();
else
// Get the version list of this package
this_toolbox = packages(current_toolbox("Toolbox"));
end
// Register the current toolbox : Check the mandatory fields
missingfield = atomsCheckFields( current_toolbox );
if ~ isempty(missingfield) then
atomsCloseProgressBar(winId);
error(msprintf(gettext("%s: The file ""%s"" is not well formated, the toolbox ""%s - %s"" does not contain the %s field\n"), ..
"atomsDESCRIPTIONread",..
file_in,current_toolbox("Toolbox"),..
current_toolbox("Version"),..
missingfield));
end
// Register the current toolbox : Check the scilab version
// comptability
if atomsIsCompatible(current_toolbox("ScilabVersion")) then
if isfield(current_toolbox,"PackagingVersion") then
current_toolbox("Version") = current_toolbox("Version") + "-" + current_toolbox("PackagingVersion");
this_toolbox(current_toolbox("Version")) = current_toolbox;
else
this_toolbox(current_toolbox("Version")) = current_toolbox;
end
end
// Register the current toolbox : Fill the packages struct
packages(current_toolbox("Toolbox")) = this_toolbox;
end
// Reset the current_toolbox struct
current_toolbox = struct();
end
// process field
current_field_length = regexp(lines_in(i),"/:\s/","o")
current_field = part(lines_in(i),1:current_field_length-1);
current_value = part(lines_in(i),current_field_length+2:length(lines_in(i)));
// process binary files
if regexp(current_field,"/^(windows|linux|macosx|solaris|bsd)(32|64)?(Url|Name|Md5|Sha1|Id)$/","o")<>[] then
// This field doesn't concern this platform => Next line
if regexp(current_field,"/^"+OSNAME+ARCH+"/","o")==[] then
continue;
else
current_field = "binary"+part(current_field,length(OSNAME+ARCH)+1:length(current_field));
end
end
// process URLs
if isfield(additional,"repository") & ..
( regexp(current_field,"/^(source|binary|windows|linux|macosx|solaris|bsd)(32|64)?Url$/","o")<>[] | current_field=="URL" ) & ..
regexp(current_value,"/^(https?|ftps?|file):\/\//","o")==[] then
current_value = additional("repository") + current_value;
end
current_toolbox(current_field) = current_value;
// Category management
if current_field == "Category" then
if ~ isfield(categories_flat,current_value) then
[categories,categories_flat] = atomsCreateCategory(categories,categories_flat,current_value)
end
if and(isfield(current_toolbox,["Toolbox";"Version"])) then
categories_flat = atomsAddPackage2Cat( categories_flat , [current_toolbox("Toolbox") current_toolbox("Version")],current_value);
else
atomsCloseProgressBar(winId);
error(msprintf(gettext("%s: name and version are not both defined\n"),"atomsDESCRIPTIONread"));
end
end
continue;
end
// Second case : Current field continuation
if regexp(lines_in(i),"/^\s/","o") == 1 then
current_value = part(lines_in(i),2:length(lines_in(i)));
current_toolbox(current_field)($+1) = current_value;
// Category management
if current_field == "Category" then
if ~ isfield(categories_flat,current_value) then
[categories,categories_flat] = atomsCreateCategory(categories,categories_flat,current_value)
end
if and(isfield(current_toolbox,["Toolbox";"Version"])) then
categories_flat = atomsAddPackage2Cat( categories_flat , [current_toolbox("Toolbox") current_toolbox("Version")],current_value);
else
atomsCloseProgressBar(winId);
error(msprintf(gettext("%s: name and version are not both defined\n"),"atomsDESCRIPTIONread"));
end
end
continue;
end
// Third case : Blank line
if length(lines_in(i)) == 0 then
continue;
end
// Fourth case : Delimiter
if regexp(lines_in(i),"/^\/\//","o") == 1 then
continue;
end
// Else Error
atomsCloseProgressBar(winId);
error(msprintf(gettext("%s: The file ''%s'' is not well formated at line %d\n"),"atomsDESCRIPTIONread",file_in,i));
end
description_out("packages") = packages;
description_out("categories") = categories;
description_out("categories_flat") = categories_flat;
atomsCloseProgressBar(winId);
endfunction
// =============================================================================
// atomsCreateCategory
// =============================================================================
function [cat_out , cat_flat_out ] = atomsCreateCategory(cat_in,cat_flat_in,cat_id)
category_main = "";
category_sub = "";
cat_flat_out = cat_flat_in;
cat_out = cat_in;
// Build the skeleton of the category
cat_struct = struct();
cat_struct("label") = [];
cat_struct("packages") = [];
cat_struct("is_main") = %T;
// Is this category a main category or a sub category
pattern_index = regexp(cat_id,"/\s-\s/","o");
if pattern_index <> [] then
// Sub category
category_main = part(cat_id,1:pattern_index-1);
category_sub = part(cat_id,pattern_index+3:length(cat_id) );
cat_struct("label") = [ category_main category_sub ];
cat_struct("is_main") = %F;
else
// Main category
category_main = cat_id;
cat_struct("label") = [ category_main ];
cat_struct("is_main") = %T;
end
cat_flat_out(cat_id) = cat_struct;
if isfield(categories,category_main) then
if category_sub <> "" then
subcategories = cat_out(category_main);
subcategories = [ subcategories ; category_sub ];
cat_out(category_main) = subcategories;
end
else
if category_sub == "" then
cat_out(category_main) = [];
else
cat_out(category_main) = category_sub;
end
end
if ~cat_struct("is_main") & ~isfield(cat_flat_out,category_main) then
[cat_out , cat_flat_out ] = atomsCreateCategory(cat_out,cat_flat_out,category_main)
end
endfunction
// =============================================================================
// atomsAddPackage2Cat
// =============================================================================
function cat_flat_out = atomsAddPackage2Cat( cat_flat_in , package , category)
cat_flat_out = cat_flat_in;
if ~ isfield( cat_flat_out , category ) then
error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' is not a registered category"),"atomsAddPackage2Cat",2,category));
end
cat_struct = cat_flat_out(category);
package_mat = [ cat_struct("packages") ; package ];
cat_struct("packages") = package_mat;
cat_flat_out(category) = cat_struct;
if ~ cat_struct("is_main") then
label_mat = cat_struct("label");
cat_flat_out = atomsAddPackage2Cat( cat_flat_out , package , label_mat(1))
end
endfunction
// =============================================================================
// atomsCheckFields
// =============================================================================
function field = atomsCheckFields( module )
field = "";
mandatory = [ ..
"Toolbox" ; ..
"Title" ; ..
"Summary" ; ..
"Version" ; ..
"Author" ; ..
"Maintainer" ; ..
"Category" ; ..
"Entity" ; ..
"License" ; ..
"ScilabVersion" ; ..
"Depends" ; ..
"Date" ];
for i=1:size(mandatory,"*")
if ~ isfield(module,mandatory(i)) then
field = mandatory(i);
return;
end
end
endfunction
|