ATOMS: cosmetic
[scilab.git] / scilab / modules / atoms / macros / atoms_internals / atomsUpdateDeps.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 // Update the dependencies with the installation of this new package
13
14 function packages_out = atomsUpdateDeps(package,section)
15         
16         rhs          = argn(2);
17         packages_out = [];
18         
19         // Check number of input arguments
20         // =========================================================================
21         
22         if rhs < 1 | rhs > 2 then
23                 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsUpdateDeps",1,2));
24         end
25         
26         // Check input parameters
27         // =========================================================================
28         
29         if type(package) <> 10 then
30                 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsUpdateDeps",1));
31         end
32         
33         if or( size(package) <> [1 2]) then
34                 error(msprintf(gettext("%s: Wrong size for input argument #%d: 1x2 string matrix expected.\n"),"atomsUpdateDeps",1));
35         end
36         
37         // All user management
38         // =========================================================================
39         
40         if rhs < 2 then
41                 section = "all";
42         
43         else
44         
45                 if type(section) <> 10 then
46                         error(msprintf(gettext("%s: Wrong type for input argument #%d: A single-string expected.\n"),"atomsUpdateDeps",2));
47                 end
48                 
49                 if size(section,"*")<>1 then
50                         error(msprintf(gettext("%s: Wrong size for input argument #%d: A single-string expected.\n"),"atomsUpdateDeps",2));
51                 end
52                 
53                 if and(section<>["user","allusers","all"]) then
54                         error(msprintf(gettext("%s: Wrong value for input argument #%d: ''user'',''allusers'' or ''all'' expected.\n"),"atomsUpdateDeps",2));
55                 end
56                 
57         end
58         
59         // The package designed by "name - version" must be installed
60         // =========================================================================
61         
62         if ~ atomsIsInstalled(package) then
63                 error(msprintf(gettext("%s: %s (%s) isn''t installed.\n"),"atomsUpdateDeps",package(1),package(2)));
64         end
65         
66         // If alluser, process the 2 list (allusers and user)
67         // =========================================================================
68         
69         allusers_mat = ["user"];
70         
71         if or(section == ["all","allusers"]) then
72                 allusers_mat = [ allusers_mat ; "allusers" ];
73         end
74         
75         name    = package(1);
76         version = package(2);
77         
78         for i=1:size(allusers_mat,"*")
79                 
80                 // Load the struct
81                 
82                 child_deps    = atomsLoadInstalleddeps(allusers_mat(i));
83                 packages      = getfield(1,child_deps);
84                 packages(1:2) = [];
85                 
86                 // Loop on packages
87                 
88                 for j=1:size(packages,"*")
89                         
90                         this_package_childs =  child_deps(packages(j));
91                         
92                         packages_concerned  = [ packages(j) ; this_package_childs ];
93                         concerned_names     = [];
94                         concerned_versions  = [];
95                         
96                         for k=1:size(packages_concerned,"*")
97                                 concerned_names(k)    =  part(packages_concerned(k),1:regexp(packages_concerned(k),"/\s-\s/")-1);
98                                 concerned_versions(k) =  part(packages_concerned(k),regexp(packages_concerned(k),"/\s-\s/")+3:length(packages_concerned(k)));
99                         end
100                         
101                         // Premier tri : on ne garde que les packages dont le package "<name>"
102                         // est un enfant direct 
103                         
104                         concerned_names_filt    = concerned_names(    atomsIsDirectChild([concerned_names concerned_versions],name));
105                         concerned_versions_filt = concerned_versions( atomsIsDirectChild([concerned_names concerned_versions],name));
106                         
107                         // if "name" is not the direct child of packages(j) or of one of the child
108                         // of packages(j) :
109                         // Job is done
110                         if isempty(concerned_names_filt) then
111                                 continue;
112                         end
113                         
114                         // Second tri : On regarde si tous les packages qui ont le package "<name>"
115                         // comme enfant direct accepte la version "<version>" de ce package
116                         // If it's not the case : Job is done
117                         if ~ and( atomsPackageIsCompatible(concerned_names_filt,concerned_versions_filt,name,version) ) then
118                                 continue;
119                         end
120                         
121                         // Now, we are sure "name - version" is compatible with  packages(j)
122                         // and all its child, check if this version is superior than the one
123                         // used by packages(j);
124                         
125                         // Get the current version used by packages(j)
126                         current_version = concerned_versions( find(concerned_names == name) );
127                         
128                         // Comparison
129                         if atomsVersionCompare(current_version,version) >= 0 then
130                                 continue;
131                         end
132                         
133                         // Ok : the <version> of <name> can now be used by packages(j)
134                         this_package_childs( grep(this_package_childs,"/^"+name+"\s-\s/","r") ) = name+" - "+version;
135                         
136                         // ... and finally : update the tree
137                         child_deps(packages(j)) = this_package_childs;
138                         
139                         // Fill the output matrix
140                         packages_out = [ packages_out ; concerned_names(1) concerned_versions(1) ];
141                         
142                 end
143                 
144                 // Save the struct
145                 atomsSaveInstalleddeps(child_deps,allusers_mat(i));
146         end
147         
148 endfunction