1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - 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-en.txt
10 // Add toolboxes to the list of installed packages
11 // This function has an impact on the following files :
12 // -> ATOMSDIR/installed.txt, ATOMSDIR/installed.bin
13 // -> ATOMSDIR/installed_deps.txt, ATOMSDIR/installed_deps.bin
15 function nbAdd = atomsInstallRegister(name,version,status,allusers)
20 // Check number of input arguments
21 // =========================================================================
23 if rhs < 3 | rhs > 4 then
24 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsInstallRegister",3,4));
27 // Check input parameters type
28 // =========================================================================
30 if type(name) <> 10 then
31 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallRegister",1));
34 if type(version) <> 10 then
35 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallRegister",2));
38 if type(status) <> 10 then
39 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallRegister",3));
43 // =========================================================================
45 if ~ and((status == "A") | (status == "I")) then
46 error(msprintf(gettext("%s: Wrong value for input argument #%d: Letters ''A'' or ''I'' expected.\n"),"atomsInstallRegister",3));
49 // name,version and status must have the same size
50 // =========================================================================
52 if or( size(name) <> size(version) ) then
53 error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsInstallRegister",1,2));
56 if or( size(name) <> size(status) ) then
57 error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsInstallRegister",1,3));
60 // Apply changes for all users or just for me ?
61 // =========================================================================
64 // By default, The toolbox is installed for all users (if we have write access of course !)
65 if atomsAUWriteAccess() then
72 // Just check if it's a boolean
73 if type(allusers) <> 4 then
74 error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsInstallRegister",4));
77 // Check if we have the write access
78 if allusers & ~ atomsAUWriteAccess() then
79 error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsInstallRegister",2,pathconvert(SCI+"/.atoms")));
84 // load installed packages (a struct)
85 // =========================================================================
86 installed = atomsLoadInstalledStruct(allusers);
88 // Load the installed_deps (a struct)
89 // =========================================================================
90 installed_deps = atomsLoadInstalleddeps(allusers);
92 // Loop on each URL specified as input argument
93 // =========================================================================
94 for i=1:size(name,"*")
96 if isfield(installed,name(i)+" - "+version(i)) then
97 // This package is already registered
100 // We have at least one change
105 // ---------------------------------------------------------------------
110 this_package_path = pathconvert(SCI+"/contrib/"+name(i)+"/"+version(i),%F);
111 this_package_uservar = "allusers";
113 this_package_path = pathconvert(SCIHOME+"/atoms/"+name(i)+"/"+version(i),%F);
114 this_package_uservar = "user";
117 // Add this package to the struct
118 installed(name(i)+" - "+version(i)) = [ ..
120 version(i) ; .. // version
121 this_package_path ; .. // path
122 this_package_uservar ; .. // allusers / user
123 status(i) ]; // I / A
125 // installed_deps file
126 // Get the depencency tree & and child package
127 // ---------------------------------------------------------------------
129 childs_tree = atomsDependencyTree(name(i),version(i));
130 childs_mat = getfield(1,childs_tree);
131 childs_mat(1:2) = [];
132 childs_mat( find(childs_mat == name(i)+" - "+version(i)) ) = [];
133 installed_deps(name(i)+" - "+version(i)) = childs_mat';
137 // =========================================================================
140 atomsSaveInstalled(installed,allusers);
141 atomsSaveInstalleddeps(installed_deps,allusers);