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