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
14 // - package -> childs : give the list of packages needed by "package"
15 // - package -> parents : give the list of packages used by "package"
17 // The two trees are saved in two formats :
18 // - text file : installed_deps.txt
19 // - binary file : installed_deps.bin
24 // child_deps : .list of packages needed by "package"
28 // allusers : . Tell where will be record the change
32 function atomsSaveInstalleddeps(child_deps,allusers)
36 // Check number of input arguments
37 // =========================================================================
40 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsSaveInstalleddeps",2));
43 // Check type of input argument type
44 // =========================================================================
46 if type(child_deps) <> 17 then
47 error(msprintf(gettext("%s: Wrong type for input argument #%d: A struct expected.\n"),"atomsSaveInstalleddeps",1));
50 if type(allusers) <> 4 then
51 error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsSaveInstalleddeps",2));
54 // Define the path of the file that will record the change according to
55 // the "allusers" value
56 // =========================================================================
59 atoms_directory = pathconvert(SCI+"/.atoms");
61 atoms_directory = pathconvert(SCIHOME+"/atoms");
64 // Does the atoms_directory exist, if not create it
65 // =========================================================================
67 if ~ isdir(atoms_directory) then
68 mkdir(atoms_directory);
71 // Define the path of the file that will record the change according to
72 // =========================================================================
73 installed_deps_txt = atoms_directory+"installed_deps.txt";
74 installed_deps_bin = atoms_directory+"installed_deps.bin";
77 // List of installed packages
78 // =========================================================================
79 parents_packages = getfield(1,child_deps);
80 parents_packages(1:2) = [];
83 // Build the package->parents struct
84 // =========================================================================
86 parent_deps = struct();
88 for i=1:size(parents_packages,"*")
90 this_package_parents = [];
92 for j=1:size(parents_packages,"*")
94 child_packages = child_deps( parents_packages(j) );
95 if find(parents_packages(i) == child_packages) <> [] then
96 this_package_parents = [ this_package_parents ; parents_packages(j) ];
101 parent_deps( parents_packages(i) ) = this_package_parents;
105 // Build the string matrix (=> text file)
106 // =========================================================================
111 // -------------------------------------------------------------------------
113 string_matrix = [ string_matrix ; "# ==============================================================================" ];
114 string_matrix = [ string_matrix ; "# Packages childs" ];
115 string_matrix = [ string_matrix ; "# ==============================================================================" ];
116 string_matrix = [ string_matrix ; "" ];
118 for i=1:size(parents_packages,"*")
121 string_matrix = [ string_matrix ; "["+parents_packages(i)+"]" ];
124 child_package = child_deps( parents_packages(i) );
125 for j=1:size(child_package,"*")
126 string_matrix = [ string_matrix ; " "+child_package(j) ];
130 string_matrix = [ string_matrix ; "" ];
135 // -------------------------------------------------------------------------
137 string_matrix = [ string_matrix ; "" ];
138 string_matrix = [ string_matrix ; "# ==============================================================================" ];
139 string_matrix = [ string_matrix ; "# Packages parents" ];
140 string_matrix = [ string_matrix ; "# ==============================================================================" ];
141 string_matrix = [ string_matrix ; "" ];
143 for i=1:size(parents_packages,"*")
146 string_matrix = [ string_matrix ; "["+parents_packages(i)+"]" ];
149 parent_package = parent_deps( parents_packages(i) );
150 for j=1:size(parent_package,"*")
151 string_matrix = [ string_matrix ; " "+parent_package(j) ];
155 string_matrix = [ string_matrix ; "" ];
159 // If parents_packages is empty, no need to keep the files
160 // =========================================================================
162 if isempty(parents_packages) then
163 mdelete(installed_deps_txt);
164 mdelete(installed_deps_bin);
169 // =========================================================================
171 mputl(string_matrix,installed_deps_txt);
172 save(installed_deps_bin,child_deps,parent_deps);