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