Atoms 0.2
[scilab.git] / scilab / modules / atoms / macros / atoms_internals / atomsGetTOOLBOXES.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 // Internal function
11
12 // Return the full packages of the TOOLBOXES present in the differents repositories
13
14 function packages = atomsGetTOOLBOXES(update)
15         
16         // Initialize
17         packages = struct();
18         
19         // Operating system detection
20         // =========================================================================
21         
22         if ~MSDOS then
23                 OSNAME = unix_g('uname');
24                 MACOSX = (strcmpi(OSNAME,"darwin") == 0);
25                 LINUX  = (strcmpi(OSNAME,"linux") == 0);
26         else
27                 MACOSX = %F;
28                 LINUX  = %F;
29         end
30         
31         if MSDOS then
32                 OSNAME = "windows";
33         elseif LINUX then
34                 OSNAME = "linux";
35         elseif MACOSX then
36                 OSNAME = "macosx";
37         end
38         
39         // Check input parameters
40         // =========================================================================
41         
42         rhs  = argn(2);
43         
44         if rhs > 1 then
45                 error(msprintf(gettext("%s: Wrong number of input argument: at most %d expected.\n"),"atomsGetTOOLBOXES",1));
46         end
47         
48         if (rhs == 1) & (type(update) <> 4) then
49                 error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsGetTOOLBOXES",1));
50         end
51         
52         // If necessary, loop on available mirrors and download TOOLBOXES files
53         
54         if (fileinfo(pathconvert(SCIHOME+"/.atoms/packages",%F)) == []) | (rhs == 1 & update) then
55                 
56                 nb_TOOLBOXES = 0;
57                 TOOLBOXES    = []; // Liste des paths des fichiers TOOLBOXES
58                 
59                 mirrors = atomsRepositories();
60                 
61                 if ~isdir(pathconvert(TMPDIR+"/atoms")) then
62                         mkdir(pathconvert(TMPDIR+"/atoms"));
63                 end
64                 
65                 for i=1:size(mirrors,"*")
66                         
67                         url            = mirrors(i)+"/TOOLBOXES/"+OSNAME;
68                         file_out       = pathconvert(TMPDIR+"/atoms/"+sprintf("TOOLBOXES_%d",nb_TOOLBOXES),%f);
69                         
70                         if( fileinfo(file_out) <> [] ) then
71                                 mdelete(file_out);
72                         end
73                         
74                         [rep,stat,err] = unix_g("wget "+url + " -O " + file_out)
75                         if stat == 0 then
76                                 // Download successfull
77                                 nb_TOOLBOXES = nb_TOOLBOXES + 1;
78                                 TOOLBOXES    = [ TOOLBOXES ; file_out ];
79                         else
80                                 disp("wget "+url + " -O " + file_out);
81                                 disp(err);
82                         end
83                 end
84                 
85                 if nb_TOOLBOXES == 0 then
86                         error(msprintf(gettext("%s: Internal Error : No TOOLBOXES file has successfully been downloaded.\n"),"atomsGetTOOLBOXES"));
87                 end
88                 
89                 for i=1:size(TOOLBOXES,"*")
90                         packages = atomsReadTOOLBOXES( TOOLBOXES(i) , packages );
91                 end
92                 
93                 // Save the "packages" variable in a file
94                 
95                 if ~isdir(pathconvert(SCIHOME+"/.atoms")) then
96                         mkdir(pathconvert(SCIHOME+"/.atoms"));
97                 end
98                 
99                 save(pathconvert(SCIHOME+"/.atoms/packages",%F),packages)
100                 
101         else
102                 
103                 // Just load from file
104                 load(pathconvert(SCIHOME+"/.atoms/packages",%F),"packages");
105
106         end
107         
108 endfunction