- installed packages and dependencies are now saved into binary files
[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 // Output arguments :
13
14 //   insList  : . List  of the changes caused by the installation of one or
15 //                more packages
16 //              . matrix ( n x 4 ) 
17 //              . mandatory
18 //              . example :
19 //                 !~  U  toolbox_4  1.0  !
20 //                 !                      !
21 //                 !~     toolbox_2  1.3  !
22 //                 !                      !
23 //                 !~     toolbox_1  1.9  !
24 //                 !                      !
25 //                 !~  U  toolbox_5  1.0  !
26
27 //   tree_out : . Dependency tree of the package (returned by atomsDependencyTree)
28 //              . struct
29 //              . mandatory
30 //              . Example :
31 //                   tree_out  = 
32 //                   toolbox_5 - 1.0: [1x1 struct]
33 //                   toolbox_4 - 1.0: [1x1 struct]
34 //                   toolbox_2 - 1.3: [1x1 struct]
35 //                   toolbox_1 - 1.9: [1x1 struct]
36
37 function [insList,depTree] = atomsInstallList(packages)
38         
39         insList = [];
40         depTree = struct();
41         
42         // Save the initial path
43         // =========================================================================
44         initialpath = pwd();
45         
46         // Get scilab version (needed for later)
47         // =========================================================================
48         sciversion = strcat(string(getversion("scilab")) + ".");
49         
50         // Check input parameters
51         // =========================================================================
52         
53         rhs = argn(2);
54         
55         if rhs <> 1 then
56                 error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"atomsInstallList",1))
57         end
58         
59         if type(packages) <> 10 then
60                 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallList",1));
61         end
62         
63         packages = stripblanks(packages);
64         
65         // Loop on packages and to build the dependency tree
66         // =========================================================================
67         
68         for i=1:size(packages,"*")
69                 
70                 package = packages(i);
71                 
72                 if size(regexp(package,"/\s/") ,"*" ) > 1 then
73                         chdir(initialpath);
74                         error(msprintf(gettext("%s: Wrong value for input argument #%d: it must contain at most one space.\n"),"atomsInstallList",1));
75                 end
76                 
77                 if size(regexp(package,"/\s/") ,"*" ) == 0 then
78                         // install the most recent version of the package
79                         package_names(i)    = package;
80                         package_versions(i) = "";
81                 else
82                         // A version is specified
83                         space               = regexp(package,"/\s/");
84                         package_names(i)    = part(package,[1:space-1]);
85                         package_versions(i) = part(package,[space+1:length(package)]);
86                 end
87                 
88                 // Ok, The syntax is correct, Now check if it's a valid package
89                 if ~ atomsIsPackage(package_names(i),package_versions(i)) then
90                         if isempty(package_versions(i)) then
91                                 package_full_name = package_names(i);
92                         else
93                                 package_full_name = package_names(i)+" - "+package_versions(i);
94                         end
95                         chdir(initialpath);
96                         error(msprintf(gettext("%s: The package %s is not available.\n"),"atomsInstallList",package_full_name));
97                 end
98                 
99                 // Build the depencency tree
100                 [tree,version_out]  = atomsDependencyTree(package_names(i),package_versions(i));
101                 
102                 if (type(tree) == 4) & (~ tree) then
103                         chdir(initialpath);
104                         error(msprintf(gettext("%s: The dependency tree cannot be resolved.\n"),"atomsInstallList",1));
105                 end
106                 
107                 // Update the  package_versions(i) with the version returned by
108                 // atomsDependencyTree
109                 package_versions(i) = version_out;
110                 
111                 // Concatenate the tree with the existing one
112                 depTree = atomsCatTree( depTree , tree );
113         end
114         
115         // Add a field to detect later if it's the toolbox is automaticaly installed
116         // or if it's a user choice
117         // =========================================================================
118         
119         for i=1:size(package_names,"*")
120                 this_package_details                                = depTree(package_names(i)+" - "+package_versions(i));
121                 this_package_details("user_choice")                 = %T;
122                 depTree(package_names(i)+" - "+package_versions(i)) = this_package_details;
123         end
124         
125         // Now we have the list of package that have to be installed
126         // We have to check if
127         //  - each package is already installed
128         //  - If yes, Is it the most recent version
129         // =========================================================================
130         
131         mandatory_packages      = getfield(1,depTree);
132         mandatory_packages(1:2) = [];
133         
134         for i=1:size(mandatory_packages,"*")
135                 this_package_details = depTree(mandatory_packages(i));
136                 
137                 this_package_name    = this_package_details("Toolbox");
138                 this_package_version = this_package_details("Version");
139                 
140                 if isfield(this_package_details,"user_choice") & this_package_details("user_choice") then
141                         this_package_user_choice = "U"; // stand for User Choice
142                 else
143                         this_package_user_choice = ""; // stand for User Choice
144                 end
145                 
146                 to_install = %F;
147                 
148                 if atomsIsInstalled(this_package_name) then
149                         vers = atomsGetInstalledVers(this_package_name);
150                         if find( vers == this_package_version ) == [] then
151                                 to_install = %T;
152                         end
153                 else
154                         to_install = %T;
155                 end
156                 
157                 if to_install then
158                         insList = [ insList ; "+" this_package_user_choice this_package_name this_package_version ];
159                 else
160                         insList = [ insList ; "~" this_package_user_choice this_package_name this_package_version ];
161                 end
162                 
163         end
164         
165         // Go to the initial location
166         // =========================================================================
167         chdir(initialpath);
168         
169 endfunction