1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009-2010 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
12 // Load one or several toolboxes
14 function result = atomsLoad(packages)
16 // Load Atoms Internals lib if it's not already loaded
17 // =========================================================================
18 if ~ exists("atomsinternalslib") then
19 load("SCI/modules/atoms/macros/atoms_internals/lib");
22 // Init the output argument
23 // =========================================================================
26 // Check ATOMSAUTOLOAD variable
27 // =========================================================================
28 if ~isdef("ATOMSAUTOLOAD") | (ATOMSAUTOLOAD<>%T) then
32 // Check input parameters
33 // =========================================================================
38 error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"atomsLoad",1,2))
41 if type(packages) <> 10 then
42 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsLoad",1));
45 if size(packages(1,:),"*") > 3 then
46 error(msprintf(gettext("%s: Wrong size for input argument #%d: mx1,mx2 or mx3 string matrix expected.\n"),"atomsLoad",1));
49 packages = stripblanks(packages);
51 // Complete packages matrix with empty columns
52 // =========================================================================
54 if size(packages(1,:),"*") == 1 then
55 packages = [ packages emptystr(size(packages(:,1),"*"),1) emptystr(size(packages(:,1),"*"),1) ];
57 elseif size(packages(1,:),"*") == 2 then
58 packages = [ packages emptystr(size(packages(:,1),"*"),1) ];
62 // Plan the path → 4th column
63 // =========================================================================
64 packages = [ packages emptystr(size(packages(:,1),"*"),1) ];
67 // =========================================================================
68 if strcmpi(atomsGetConfig("Verbose"),"True") == 0 then
74 // Already loaded modules :
75 // =========================================================================
76 loaded = atomsLoadLoad();
79 // Remove duplicate packages (name - version)
80 // =========================================================================
82 [matout,index] = unique([packages(:,1) packages(:,2)],"r");
83 packages = packages(gsort(index,"g","i"),:);
85 // Loop on input parameter
86 // =========================================================================
88 for i=1:size(packages(:,1),"*")
90 // The module's installed version hasn't been specified or is empty
91 // → Set the MRV available
92 // =====================================================================
94 if isempty(packages(i,2)) then
96 if ~ isempty(packages(i,3)) then
97 section = packages(i,3);
104 this_module_versions = atomsGetInstalledVers(packages(i,1),section);
106 if isempty(this_module_versions) then
107 if section == "all" then
108 error(msprintf(gettext("%s: Module ''%s'' is not installed.\n"),"atomsLoad",packages(i,1)));
110 error(msprintf(gettext("%s: Module ''%s'' is not installed (''%s'' section).\n"),"atomsLoad",packages(i,1),section));
113 packages(i,2) = this_module_versions(1);
118 if ~atomsIsInstalled([packages(i,1) packages(i,2)]) then
119 error(msprintf(gettext("%s: Module ''%s - %s'' is not installed.\n"),"atomsLoad",packages(i,1),packages(i,2)));
122 // If the packaging version is not mentioned, define it
123 if isempty(strindex(packages(i,2),"-")) then
124 this_package_details = atomsGetInstalledDetails([packages(i,1) packages(i,2) packages(i,3)]);
125 packages(i,2) = this_package_details(2);
130 // The module's installed section hasn't been specified or is empty
131 // → If the module (same name/same version) is installed in both sections,
132 // module installed in the "user" section is taken
133 // =====================================================================
135 if isempty(packages(i,3)) then
137 sections = ["user","allusers"];
139 for j=1:size(sections,"*")
140 if atomsIsInstalled([packages(i,1) packages(i,2)],sections(j)) then
141 packages(i,3) = sections(j);
148 // Check if modules are installed
149 if ~ atomsIsInstalled([packages(i,1) packages(i,2)],packages(i,3)) then
150 mprintf(gettext("%s: The following modules are not installed:\n"),"atomsAutoloadAdd");
151 mprintf("\t - ''%s - %s'' (''%s'' section)\n",packages(i,1),packages(i,2),packages(i,3));
157 // Get the installed path
158 // =====================================================================
159 packages(i,4) = atomsGetInstalledPath([packages(i,1) packages(i,2) packages(i,3)]);
163 // Loop on packages gived by the user
164 // =========================================================================
166 mandatory_packages = struct();
167 mandatory_packages_name = struct();
168 mandatory_packages_mat = [];
170 for i=1:size(packages(:,1),"*")
172 this_package_name = packages(i,1);
173 this_package_version = packages(i,2);
174 this_package_section = packages(i,3);
175 this_package_path = packages(i,4);
177 // Check if the user try to load 2 versions of the same toolbox at the
179 // =====================================================================
180 if size( find( this_package_name == packages(:,1) ) > 1 ) then
181 this_versions = packages( find( this_package_name == packages(:,1) ) , 2 );
182 for j=2:size(this_versions,"*")
183 if this_versions(j) <> this_versions(1) then
184 mprintf(gettext("%s: Several versions of a package (%s) cannot be loaded at the same scilab session :\n"),"atomsLoad",this_package_name);
185 mprintf(gettext("\t - You''ve asked ''%s - %s''\n"),this_package_name,this_versions(1));
186 mprintf(gettext("\t - You''ve asked ''%s - %s''\n"),this_package_name,this_versions(j));
189 if ATOMSAUTOLOAD then
198 // Check if this toolbox is already loaded
199 // =====================================================================
200 if atomsIsLoaded([this_package_name this_package_version]) then
201 atomsDisp(msprintf("\tThe package %s (%s) is already loaded",this_package_name,this_package_version));
205 // Check if another version of this toolbox is already loaded
206 // =====================================================================
207 [is_loaded,loaded_version] = atomsIsLoaded(this_package_name);
209 if ATOMSAUTOLOAD then
210 mprintf(gettext("%s: Another version of the package %s is already loaded : %s\n"),"atomsLoad",this_package_name,loaded_version);
212 error(msprintf(gettext("%s: Another version of the package %s is already loaded : %s\n"),"atomsLoad",this_package_name,loaded_version));
217 mandatory_packages(this_package_name+" - "+this_package_version) = "asked_by_user";
218 mandatory_packages_name(this_package_name) = this_package_version;
219 mandatory_packages_mat = [ mandatory_packages_mat ; this_package_name this_package_version this_package_section this_package_path ];
223 // Fill the list of package to load
224 // =========================================================================
226 for i=1:size(packages(:,1),"*")
228 this_package_name = packages(i,1);
229 this_package_version = packages(i,2);
230 this_package_section = packages(i,3);
231 this_package_path = packages(i,4);
233 childs = atomsGetDepChilds([this_package_name this_package_version]);
235 for j=1:size( childs(:,1) , "*")
237 // Check if it is already loaded
238 // -------------------------------------------------------
239 if atomsIsLoaded(childs(j,:)) then
243 // Check if another version of this package is already loaded
244 // -------------------------------------------------------
245 [is_loaded,loaded_version] = atomsIsLoaded(childs(j,1));
247 mprintf(gettext("%s: Several versions of a package (%s) cannot be loaded at the same scilab session :\n"),"atomsLoad",childs(j,1));
248 mprintf(gettext("\t - ''%s - %s'' is already loaded\n"),childs(j,1),loaded_version);
249 mprintf(gettext("\t - ''%s - %s'' is needed by ''%s - %s''\n"),childs(j,1),childs(j,2),this_package_name,this_package_version);
252 if ATOMSAUTOLOAD then
259 // Check if it is already in the list
260 // -------------------------------------------------------
261 if isfield( mandatory_packages , childs(j,1)+" - "+childs(j,2) ) then
265 // Check if another version is already in the list
266 // -------------------------------------------------------
267 if isfield( mandatory_packages_name , childs(j,1) ) then
269 // if it's not the name version => error
270 if mandatory_packages_name(childs(j,1)) <> childs(j,2) then
272 mprintf(gettext("%s: Several versions of a package (%s) cannot be loaded at the same scilab session :\n"),"atomsLoad",childs(j,1));
273 mprintf(gettext("\t - ''%s - %s'' is needed by ''%s - %s''\n"),childs(j,1),childs(j,2),packages(i,1),packages(i,2));
275 // The other version of the package is asked by the user
276 if mandatory_packages(childs(j,1)+" - "+mandatory_packages_name(childs(j,1))) == "asked_by_user" then
277 mprintf(gettext("\t - You''ve asked ''%s - %s''\n"),childs(j,1),mandatory_packages_name(childs(j,1)));
279 // The other version of the package is a need by another package
281 mprintf(gettext("\t - ''%s - %s'' is needed by ''%s''\n"), ..
282 childs(j,1), .. // name
283 mandatory_packages_name(childs(j,1)), .. // version
284 mandatory_packages(childs(j,1)+" - "+mandatory_packages_name(childs(j,1))) .. // name - version
289 if ATOMSAUTOLOAD then
297 // The child has passed the test, add it to the mandatory
299 // -------------------------------------------------------
301 mandatory_packages(childs(j,1)+" - "+childs(j,2)) = packages(i,1)+" - "+packages(i,2);
302 mandatory_packages_name(childs(j,1)) = childs(j,2);
303 mandatory_packages_mat = [ childs(j,1) childs(j,2) this_package_section atomsGetInstalledPath(childs(j,:),this_package_section) ; mandatory_packages_mat ];
307 // Libraries to resume
308 // =========================================================================
311 if ~ isempty(mandatory_packages_mat) then
315 for i=1:size(mandatory_packages_mat(:,1),"*")
317 this_package_name = mandatory_packages_mat(i,1);
318 this_package_version = mandatory_packages_mat(i,2);
319 this_package_section = mandatory_packages_mat(i,3);
320 this_package_path = mandatory_packages_mat(i,4);
322 // Get the list of lib
323 // =====================================================================
324 libs_before = librarieslist();
327 // =====================================================================
329 loader_file = pathconvert(this_package_path) + "loader.sce";
331 if fileinfo(loader_file)==[] then
332 msg = _("%s: The file ''%s'' from (%s - %s) doesn''t exist or is not read accessible.\n")
333 mprintf(msg, "atomsLoad", loader_file, this_package_name, this_package_version);
334 if ATOMSAUTOLOAD then
339 ierr = execstr("exec(loader_file,-1)","errcatch");
342 mprintf(gettext("%s: An error occurred while loading ''%s-%s'':\n"),"atomsLoad",this_package_name,this_package_version);
343 errormsg = lasterror(%T);
344 mprintf("\t%s\n",errormsg);
345 if ATOMSAUTOLOAD then
354 // Get the list of libraries (macros)
355 // =====================================================================
356 libs_after = librarieslist();
358 // Loop on libs_after
359 // =====================================================================
360 for j=1:size(libs_after,"*")
362 if find(libs_after(j) == libs_before) == [] then
363 libs_resume = [ libs_resume ; libs_after(j) ];
367 // Fill the output argument
368 // =====================================================================
369 result = [ result ; mandatory_packages_mat(i,:) ];
371 // fill the loaded matrix
372 // =====================================================================
374 if and(loaded(:,1) <> this_package_name) then
376 loaded = [ loaded ; this_package_name this_package_version this_package_section ];
382 // =========================================================================
384 atomsLoadSave(loaded);
387 // If libs_resume is empty, the job is done
388 // =========================================================================
389 if isempty(libs_resume) then
393 // Build the resume cmd
394 // =========================================================================
398 for i=1:size(libs_resume,"*")
399 resume_cmd = resume_cmd + libs_resume(i);
400 if i<size(libs_resume,"*") then
401 resume_cmd = resume_cmd + ",";
403 resume_cmd = resume_cmd + "] = resume(";
407 for i=1:size(libs_resume,"*")
408 resume_cmd = resume_cmd + libs_resume(i);
409 if i<size(libs_resume,"*") then
410 resume_cmd = resume_cmd + ",";
412 resume_cmd = resume_cmd + ");";
416 // Exec the resume cmd
417 // =========================================================================