- installed packages and dependencies are now saved into binary files
[scilab.git] / scilab / modules / atoms / macros / atomsShow.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 // Show information on a package
11
12 function atomsShow(name,version)
13         
14         rhs = argn(2);
15         
16         // Check number of input arguments
17         // =========================================================================
18         
19         if rhs < 1 | rhs > 2 then
20                 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsShow",1,2));
21         end
22         
23         // Check input parameters type
24         // =========================================================================
25         
26         if type(name) <> 10 then
27                 error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsShow",1));
28         end
29         
30         if (rhs>1) & (type(version)<>10)  then
31                 error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsShow",2));
32         end
33         
34         // Check input parameters dimensions
35         // =========================================================================
36         
37         if size(name,"*") <> 1 then
38                 error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsShow",1));
39         end
40         
41         if (rhs>1) & (size(version,"*") <> 1) then
42                 error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsShow",2));
43         end
44         
45         // Get the details of this package
46         // =========================================================================
47         
48         details = atomsToolboxDetails(name,version);
49         
50         fields_map = [];
51         fields_map = [ fields_map ; "Toolbox"        gettext("Package")        ];
52         fields_map = [ fields_map ; "Title"          gettext("Title")          ];
53         fields_map = [ fields_map ; "Summary"        gettext("Summary")        ];
54         fields_map = [ fields_map ; "Version"        gettext("Version")        ];
55         fields_map = [ fields_map ; "Depends"        gettext("Depend")         ];
56         fields_map = [ fields_map ; "Category"       gettext("Category(ies)")  ];
57         fields_map = [ fields_map ; "Maintainer"     gettext("Maintainer(s)")  ];
58         fields_map = [ fields_map ; "Entity"         gettext("Entity")         ];
59         fields_map = [ fields_map ; "WebSite"        gettext("WebSite")        ];
60         fields_map = [ fields_map ; "License"        gettext("License")        ];
61         fields_map = [ fields_map ; "ScilabVersion"  gettext("Scilab Version") ];
62         
63         fields_map = [ fields_map ; "Status"         gettext("Status")         ];
64         
65         if atomsIsInstalled(name,version) then
66                 fields_map = [ fields_map ; "InstallAutomaticaly" gettext("Automaticaly Installed")];
67                 fields_map = [ fields_map ; "installPath"         gettext("Install Directory")];
68         end
69         
70         fields_map = [ fields_map ; "Description"    gettext("Description")    ];
71         
72         // Show it
73         // =========================================================================
74         
75         max_field_len = max( length(fields_map(:,2)) );
76         
77         for i=1:size(fields_map(:,1),"*")
78                 
79                 value = "";
80                 
81                 //
82                 // Status
83                 // 
84                 
85                 if fields_map(i,1)=="Status" then
86                         if atomsIsInstalled(name,version) then
87                                 value = "Installed";
88                         else
89                                 value = "Not installed";
90                         end
91                 end
92                 
93                 //
94                 // Automaticaly Installed ?
95                 // 
96                 
97                 if fields_map(i,1)=="InstallAutomaticaly" then
98                         if atomsGetInstalledStatus(name,version) == "A" then
99                                 value = "yes";
100                         else
101                                 value = "no";
102                         end
103                 end
104                 
105                 //
106                 // Scilab Version
107                 // 
108                 
109                 if fields_map(i,1)=="ScilabVersion" then
110                         if regexp( details(fields_map(i,1)) , "/^~/" , "o" )<>[] then
111                                 value = "any";
112                         else
113                                 value = details(fields_map(i,1));
114                         end
115                 end
116                 
117                 //
118                 // Dependences
119                 // 
120                 
121                 if fields_map(i,1)=="Depends" then
122                         value = dep2str(details(fields_map(i,1)));
123                 end
124                 
125                 //
126                 // Other
127                 //
128                 
129                 if isempty(value) then
130                         value = details(fields_map(i,1));
131                 end
132                 
133                 for j=1:size(value,"*")
134                         
135                         if j==1 then
136                                 mprintf("% "+string(max_field_len)+"s : %s\n",fields_map(i,2),value(j))
137                                 
138                         else
139                                 mprintf("% "+string(max_field_len)+"s   %s\n","",value(j))
140                         end
141                 end
142         end
143         
144 endfunction
145
146 // =============================================================================
147 // string = dep2str(string)
148 //
149 // Convert a technical dependence string (For ex. : ">= toolbox_1 1.3") to a
150 // display dependence string  (For ex. : "toolbox_1 (>= 1.3)" )
151 // 
152 // =============================================================================
153
154 function str = dep2str(dep)
155         
156         str = [];
157         
158         if isempty(dep) then
159                 return;
160         end
161         
162         for i=1:size(dep,"*")
163                 
164                 this_dep = dep(i);
165                 
166                 // direction part
167                 this_dep         = stripblanks(this_dep);
168                 direction_length = regexp(this_dep,"/\s/","o");
169                 direction        = stripblanks(part(this_dep,1:direction_length-1));
170                 
171                 // name part 
172                 this_dep         = stripblanks(part(this_dep,direction_length+1:length(this_dep)));
173                 name_length      = regexp(this_dep,"/\s/","o");
174                 name             = part(this_dep,1:name_length-1);
175                 
176                 // version part
177                 version          = stripblanks(part(this_dep,name_length:length(this_dep)));
178                 
179                 this_str         = name+" ";
180                 
181                 if direction == "~" then
182                         this_str = this_str + "(Any version)";
183                 else
184                         this_str = this_str + "("+direction+" "+version+")";
185                 end
186                 
187                 str = [ str ; this_str ];
188                 
189         end
190         
191 endfunction