f003086835fd3bd110200d9017793904107ee7b2
[scilab.git] / scilab / modules / atoms / macros / atomsGetInstalled.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 // End user function
11
12 function packages = atomsGetInstalled(allusers)
13         
14         rhs      = argn(2);
15         packages = [];
16         
17         // Check number of input arguments
18         // =========================================================================
19         
20         if rhs > 1 then
21                 error(msprintf(gettext("%s: Wrong number of input argument: at most %d expected.\n"),"atomsGetInstalled",1));
22         end
23         
24         // Apply changes for all users or just for me ?
25         // =========================================================================
26         
27         if rhs == 0 then
28                 allusers = %T;
29         else
30                 // Just check if it's a boolean
31                 if type(allusers) <> 4 then
32                         error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsGetInstalled",1));
33                 end
34         end
35         
36         // Define the differents path of the file where are installed
37         // =========================================================================
38         
39         installed_files = [];
40         user_file       = pathconvert(SCIHOME+"/atoms/installed",%F);
41         alluser_file    = pathconvert(SCI+"/.atoms/installed",%F);
42         
43         if fileinfo(user_file)<>[] then
44                 installed_files = [ installed_files ; user_file "user" ];
45         end
46         
47         if allusers & (fileinfo(alluser_file)<>[]) then
48                 installed_files = [ installed_files ; alluser_file "alluser"];
49         end
50         
51         // Loop on each "installed" file specified as first input argument
52         // =========================================================================
53         
54         for i=1:size(installed_files(:,1),"*")
55                 
56                 // Get the installed package list in this file
57                 installed = mgetl(installed_files(i,1));
58                 
59                 // Loop on each URL specified as first input argument
60                 for j=1:size(installed,"*")
61                         current_name_length  = regexp(installed(j),"/\s-\s/","o");
62                         current_name         = part(installed(j),1:current_name_length-1);
63                         current_version      = part(installed(j),current_name_length+3:length(installed(j)));
64                         
65                         if installed_files(i,2) == "user" then
66                                 // user
67                                 current_path  = pathconvert(SCIHOME+"/atoms/contrib/"+current_name+"/"+current_version,%F); 
68                         else
69                                 // all users
70                                 current_path = pathconvert(SCI+"/contrib/"+current_name+"/"+current_version,%F);
71                         end
72                         
73                         packages = [ packages ; current_name current_version installed_files(i,2) current_path];
74                 end
75         end
76         
77 endfunction