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
10 // Delete an atoms package from the list of available package
11 // This function has an impact on the following files :
12 // -> ATOMSDIR/installed
13 // -> ATOMSDIR/installed_deps
15 function nbDel = atomsInstallUnregister(name,version,allusers)
20 // Check number of input arguments
21 // =========================================================================
23 if rhs < 2 | rhs > 3 then
24 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsInstallUnregister",2,3));
27 // Check input parameters type
28 // =========================================================================
30 if type(name) <> 10 then
31 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallUnregister",1));
34 if type(version) <> 10 then
35 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallUnregister",2));
38 // name and version must have the same size
39 // =========================================================================
41 if or( size(name) <> size(version) ) then
42 error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsInstallUnregister",1,2));
45 // Apply changes for all users or just for me ?
46 // =========================================================================
49 // By default, add the repository for all users (if we have write access
51 if atomsAUWriteAccess() then
58 // Just check if it's a boolean
59 if type(allusers) <> 4 then
60 error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsInstallUnregister",2));
63 // Check if we have the write access
64 if allusers & ~ atomsAUWriteAccess() then
65 error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsInstallUnregister",2,pathconvert(SCI+"/.atoms")));
69 // Define the path of the files that will record the change according to
70 // the "allusers" value and the existence of the latter
71 // =========================================================================
77 if fileinfo( pathconvert(SCIHOME+"/atoms/installed",%F) )<> [] then
78 atoms_files = [ atoms_files ; pathconvert(SCIHOME+"/atoms/installed",%F) ];
81 if allusers & (fileinfo( pathconvert(SCI+"/.atoms/installed",%F) )<>[]) then
82 atoms_files = [ atoms_files ; pathconvert(SCI+"/.atoms/installed",%F) ];
85 // installed_deps files
87 atoms_files_deps = [];
89 if fileinfo( pathconvert(SCIHOME+"/atoms/installed_deps",%F) )<> [] then
90 atoms_files_deps = [ atoms_files_deps ; pathconvert(SCIHOME+"/atoms/installed_deps",%F) ];
93 if allusers & (fileinfo( pathconvert(SCI+"/.atoms/installed_deps",%F) )<>[]) then
94 atoms_files_deps = [ atoms_files_deps ; pathconvert(SCI+"/.atoms/installed_deps",%F) ];
97 // Loop on each installed file specified as first input argument
98 // =========================================================================
100 for i=1:size(atoms_files,"*")
102 // Get the installed package list in this file
103 installed = mgetl(atoms_files(i));
105 // Loop on each URL specified as first input argument
106 for j=1:size(name,"*")
107 indice = grep(installed,"/^[AI]\s-\s"+name(j)+"\s-\s"+version(j)+"$/","r");
111 installed(indice) = [];
115 if installed == [] then
116 mdelete(atoms_files(i));
118 // Apply changes on this file
119 mputl(installed,atoms_files(i));
123 // Loop on each installed file specified as first input argument
124 // =========================================================================
126 for i=1:size(atoms_files_deps,"*")
130 // Get the installed package list in this file
131 installed_deps_in = mgetl(atoms_files_deps(i));
132 installed_deps_out = [];
134 // Loop on each URL specified as first input argument
135 for j=1:size(name,"*")
137 // Loop on each lines of the installed_deps file
138 for k=1:size(installed_deps_in,"*")
140 if installed_deps_in(k) == "["+name(j)+" - "+version(j)+"]" then
145 if regexp(installed_deps_in(k),"/^\[(.)*\]$/","o") <> [] then
154 installed_deps_out = [ installed_deps_out , installed_deps_in(k) ];
160 if installed_deps_out == [] then
161 mdelete(atoms_files_deps(i));
163 // Apply changes on this file
164 mputl(installed_deps_out,atoms_files_deps(i));