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
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
// Copyright (C) 2011-2012 - DIGITEO - Allan CORNET
// Copyright (C) 2012 - Samuel GOUGEON
//
// 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 the packages present in the differents
// repositories and the installed packages
function [packages,categories_flat,categories] = atomsDESCRIPTIONget(update)
// Check input parameters
// =========================================================================
rhs = argn(2);
if rhs > 1 then
error(msprintf(gettext("%s: Wrong number of input argument: at most %d expected.\n"),"atomsDESCRIPTIONget",1));
end
if (rhs == 1) & (type(update) <> 4) then
error(msprintf(gettext("%s: Wrong type for input argument #%d: Boolean expected.\n"),"atomsDESCRIPTIONget",1));
end
// packages file path definition
// =========================================================================
atoms_path_all_users = atomsPath("system", "allusers");
atoms_path_user = atomsPath("system", "user");
filename_test_rw = "__ATOMS_RW__";
if isfile(atoms_path_all_users + filename_test_rw) then
mdelete(atoms_path_all_users + filename_test_rw);
end
// Have the user write access to the Scilab distribution ?
[id, err] = mopen(atoms_path_all_users + filename_test_rw, "wt");
if err == 0 then // The user has write access to the Scilab distribution
mclose(id);
mdelete(atoms_path_all_users + filename_test_rw);
packages_path = atoms_path_all_users + "packages";
packages_path_user = atoms_path_user + "packages";
// Then, we must test if there is also a user defined packages file
if isfile(packages_path_user) then // We use it if it is newer
kdiff = newest([packages_path, packages_path_user])
if ~isfile(packages_path) | kdiff == 2 then
copyfile(packages_path_user, packages_path)
end
end
else // The user is not a Scilab admin => default user profile used
packages_path = atoms_path_user + "packages";
end
categories_path = atoms_path_user + "categories";
packages_path_info = fileinfo(packages_path);
// in offline mode we use only DESCRIPTION file of the module
if (atomsGetConfig("offLine") == "True" | atomsGetConfig("offline") == "True") then
if isfile(atomsPath("system", "session") + "/DESCRIPTION_archives") then
this_description = atomsDESCRIPTIONread(atomsPath("system","session") + "/DESCRIPTION_archives");
inst_description_files = [ ..
atomsPath("system","allusers") + "DESCRIPTION_installed" "" ; ..
atomsPath("system","user") + "DESCRIPTION_installed" "" ; ..
atomsPath("system","session") + "DESCRIPTION_installed" "" ; ..
atomsPath("system","session") + "DESCRIPTION_archives" "" ];
for i=1:size(inst_description_files(:,1),"*")
file_out = inst_description_files(i,1);
this_repository = inst_description_files(i,2);
if ~isfile(file_out) then
continue;
end
// Read the download description file
// ----------------------------------------
if this_repository <> "" then
additional("repository") = this_repository;
else
additional = struct();
end
installed_description = atomsDESCRIPTIONread(file_out,additional);
this_description = atomsDESCRIPTIONcat(installed_description,this_description);
end
packages = this_description("packages");
categories_flat = this_description("categories_flat");
categories = this_description("categories");
global %_atoms_cache; // /!\ Do not rename this variable. Name is tracked/ignored by Variable Browser
%_atoms_cache(1) = packages;
%_atoms_cache(2) = categories;
%_atoms_cache(3) = categories_flat;
else
load(packages_path, "packages", "categories", "categories_flat");
end
return
end
// If necessary, rebuild the struct
// =========================================================================
TIME_BEFORE_NEW_UPDATE = strtod(atomsGetConfig("updateTime"))*86400;
if isnan(TIME_BEFORE_NEW_UPDATE) then // Value not found in config file, give the default one
TIME_BEFORE_NEW_UPDATE = 86400*30; // One month, in seconds
end
if (packages_path_info == []) ..
| (getdate("s") - packages_path_info(6) > TIME_BEFORE_NEW_UPDATE) ..
| (rhs == 1 & update) then
// Initialize
packages = struct();
categories_flat = struct();
categories = struct();
description = struct();
description("packages") = packages;
description("categories") = categories;
description("categories_flat") = categories_flat;
// Operating system detection + Architecture detection
// =========================================================================
[OSNAME, ARCH, LINUX, MACOSX, SOLARIS, BSD] = atomsGetPlatform();
description_files = [ ..
atomsPath("system","allusers") + "DESCRIPTION_installed" "" ; ..
atomsPath("system","user") + "DESCRIPTION_installed" "" ; ..
atomsPath("system","session") + "DESCRIPTION_installed" "" ; ..
atomsPath("system","session") + "DESCRIPTION_archives" "" ];
// 1st step : Loop on available repositories
// ---------------------------------------------------------------------
repositories = atomsRepositoryList();
repositories = repositories(:,1);
atoms_tmp_directory = atomsPath("system","session");
if ~isdir(atoms_tmp_directory) then
mkdir(atoms_tmp_directory);
end
nbRepoError = 0;
allRepoError = [];
for i=1:size(repositories,"*")
// Building url & file_out
// ----------------------------------------
url = repositories(i)+"/TOOLBOXES/"+ARCH+"/"+OSNAME+".gz";
file_out = pathconvert(getshortpathname(fullpath(atoms_tmp_directory))+string(i)+"_TOOLBOXES.gz",%f);
// Remove the existing file
// ----------------------------------------
if fileinfo(file_out) <> [] then
mdelete(file_out);
end
// Launch the download
// ----------------------------------------
try
atomsDownload(url, file_out);
// We check that file_out exists
// ----------------------------------------
if ~isfile(file_out) then
error(msprintf(gettext("%s: DESCRIPTION file (''%s'') does not exist.\n"),"atomsDESCRIPTIONget", file_out));
end
// Extract It
// ----------------------------------------
if LINUX | MACOSX | SOLARIS | BSD then
extract_cmd = "gunzip "+ file_out;
else
gzip_path = getshortpathname(fullpath(pathconvert(SCI+"/tools/gzip/gzip.exe",%F)));
if ~isfile(gzip_path) then
error(msprintf(gettext("%s: gzip not found.\n"), "atomsDESCRIPTIONget"));
end
extract_cmd = """" + gzip_path + """" + " -d """ + file_out + """";
end
[rep, stat ,err] = unix_g(extract_cmd);
if stat ~= 0 then
disp(err);
error(msprintf(gettext("%s: Extraction of the DESCRIPTION file (''%s'') has failed.\n"),"atomsDESCRIPTIONget",file_out));
end
description_files = [ description_files ; strsubst(file_out,"/\.gz$/","","r") repositories(i) ];
mprintf(_("Scanning repository") + " " + repositories(i) + " ... " + _("Done") + "\n\n");
catch
[msg, ierr] = lasterror();
nbRepoError = nbRepoError + 1;
allRepoError = [allRepoError ; msg]
// If failed downloading latest repository and all previous failed => error
if nbRepoError == size(repositories, "*") then
warning(msg);
mprintf(_("Scanning repository") + " " + repositories(i) + " ... " + _("Skipped") + "\n\n");
error("All ATOMS repositories scan failed.");
else
warning(msg);
mprintf(_("Scanning repository") + " " + repositories(i) + " ... " + _("Skipped") + "\n\n");
end
end
end
// 2nd step : Loop on available Description files
// ---------------------------------------------------------------------
for i=1:size(description_files(:,1),"*")
file_out = description_files(i,1);
this_repository = description_files(i,2);
if ~isfile(file_out) then
continue;
end
// Read the download description file
// ----------------------------------------
if this_repository <> "" then
additional("repository") = this_repository;
else
additional = struct();
end
this_description = atomsDESCRIPTIONread(file_out,additional);
// Add information about the repository
// ----------------------------------------
if this_repository <> "" then
this_description = atomsDESCRIPTIONaddField(this_description,"*","*","repository",this_repository);
this_description = atomsDESCRIPTIONaddField(this_description,"*","*","fromRepository","1");
end
// concatenate the description with the
// global struct
// ----------------------------------------
description = atomsDESCRIPTIONcat(description,this_description);
// file_out is no more needed, delete it
// but only if it's named TOOLBOXES
// DESCRIPTION_installed must be keeped
// ----------------------------------------
if regexp( file_out , "/TOOLBOXES$/" , "o" ) <> [] then
mdelete(file_out);
end
end
// Save the "packages" variable in a file
// ---------------------------------------------------------------------
if ~isdir(atomsPath("system","user")) then
mkdir(atomsPath("system","user"));
end
packages = description("packages");
categories = description("categories");
categories_flat = description("categories_flat");
wMode = warning("query");
warning("off");
commandToExec = "save(packages_path, packages, categories, categories_flat)";
ierr = execstr(commandToExec, "errcatch");
warning(wMode);
if ierr <> 0 then
error(msprintf(gettext("%s: save (''%s'') has failed.\n"),"atomsDESCRIPTIONget", packages_path));
end
clearglobal %_atoms_cache;
// Just load from file
// =========================================================================
else
global %_atoms_cache; // /!\ Do not rename this variable. Name is tracked/ignored by Variable Browser
if isempty(%_atoms_cache) then
load(packages_path,"packages","categories","categories_flat");
%_atoms_cache = list(packages, categories, categories_flat);
else
packages = %_atoms_cache(1);
categories = %_atoms_cache(2);
categories_flat = %_atoms_cache(3);
end
end
endfunction
|