f1c2d30f5983a61e10de875b95c89e3aa25fb8ed
[scilab.git] / scilab / modules / atoms / macros / atoms_internals / atomsInstallList.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
3 //
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
9
10 // Internal function
11
12 // Give the matrix of the toolbox to install :
13
14 // !+  toolbox_3  1.6  !
15 // !                   !
16 // !~  toolbox_2  1.5  !
17 // !                   !
18 // !~  toolbox_1  1.9  !
19
20 function [insList,depTree] = atomsInstallList(packages)
21         
22         insList = [];
23         depTree = struct();
24         
25         // Save the initial path
26         // =========================================================================
27         initialpath = pwd();
28         
29         // Get scilab version (needed for later)
30         // =========================================================================
31         sciversion = strcat(string(getversion("scilab")) + ".");
32         
33         // Check input parameters
34         // =========================================================================
35         
36         rhs = argn(2);
37         
38         if rhs <> 1 then
39                 error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"atomsInstallList",1))
40         end
41         
42         if type(packages) <> 10 then
43                 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallList",1));
44         end
45         
46         packages = stripblanks(packages);
47         
48         // Loop on packages and to build the dependency tree
49         // =========================================================================
50         
51         for i=1:size(packages,"*")
52                 
53                 package = packages(i);
54                 
55                 if size(regexp(package,"/\s/") ,"*" ) > 1 then
56                         chdir(initialpath);
57                         error(msprintf(gettext("%s: Wrong value for input argument #%d: it must contain at most one space.\n"),"atomsInstallList",1));
58                 end
59                 
60                 if size(regexp(package,"/\s/") ,"*" ) == 0 then
61                         // install the most recent version of the package
62                         package_names(i)    = package;
63                         package_versions(i) = "";
64                 else
65                         // A version is specified
66                         space               = regexp(package,"/\s/");
67                         package_names(i)    = part(package,[1:space-1]);
68                         package_versions(i) = part(package,[space+1:length(package)]);
69                 end
70                 
71                 // Ok, The syntax is correct, Now check if it's a valid package
72                 if ~ atomsIsPackage(package_names(i),package_versions(i)) then
73                         if isempty(package_versions(i)) then
74                                 package_full_name = package_names(i);
75                         else
76                                 package_full_name = package_names(i)+" - "+package_versions(i);
77                         end
78                         chdir(initialpath);
79                         error(msprintf(gettext("%s: The package %s is not available.\n"),"atomsInstallList",package_full_name));
80                 end
81                 
82                 // Build the depencency tree
83                 tree = atomsDependencyTree(package_names(i),package_versions(i));
84                 
85                 if (type(depTree) == 4) & (~ depTree) then
86                         chdir(initialpath);
87                         error(msprintf(gettext("%s: The dependency tree cannot be resolved.\n"),"atomsInstallList",1));
88                 end
89                 
90                 // Concatenate the tree with the existing one
91                 depTree = atomsCatTree( depTree , tree );
92                 
93         end
94         
95         // Now we have the list of package that have to be installed
96         // We have to check if
97         //  - each package is already installed
98         //  - If yes, Is it the most recent version
99         // =========================================================================
100         
101         mandatory_packages      = getfield(1,depTree);
102         mandatory_packages(1:2) = [];
103         
104         for i=1:size(mandatory_packages,"*")
105                 this_package_details = depTree(mandatory_packages(i));
106                 
107                 this_package_name    = this_package_details("Toolbox");
108                 this_package_version = this_package_details("Version");
109                 
110                 to_install = %F; 
111                 
112                 if atomsIsInstalled(this_package_name) then
113                         vers = atomsGetInstalledVers(mandatory_packages(i));
114                         if atomsVersionCompare( vers(1) , this_package_version ) < 0 then
115                                 to_install = %T;
116                         end
117                 else
118                         to_install = %T;
119                 end
120                 
121                 if to_install then
122                         insList = [ insList ; "+" this_package_name this_package_version ];
123                 else
124                         insList = [ insList ; "~" this_package_name this_package_version ];
125                 end
126                 
127         end
128         
129         // Go to the initial location
130         // =========================================================================
131         chdir(initialpath);
132         
133 endfunction