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