|
From: | Ben Abbott |
Subject: | Re: [changeset: ver.m] Distinguishing Octave from Matlab |
Date: | Tue, 19 Feb 2008 07:39:08 -0500 |
Same content as the prior diff, but produced by "hg export ..." # HG changeset patch # User Ben Abbott <address@hidden> # Date 1203423889 18000 # Node ID c1279a36706dbd1d0cbc99c1f679f01c0e7f3714 # Parent 6f6a8ddf86428fec6131b024ef2b014e603524d8 Added pkg version info and matlab compatibility. diff -r 6f6a8ddf8642 -r c1279a36706d scripts/ChangeLog --- a/scripts/ChangeLog Tue Feb 19 07:18:26 2008 -0500 +++ b/scripts/ChangeLog Tue Feb 19 07:24:49 2008 -0500 @@ -1,3 +1,8 @@ 2008-01-16 Ben Abbott <address@hidden +2008-02-18 Ben Abbott <address@hidden> + + * miscellaneous/ver: Added package version information, and + consistency with Matlab. + 2008-01-16 Ben Abbott <address@hidden> * miscellaneous/edit.m: Added control field "editinplace" to diff -r 6f6a8ddf8642 -r c1279a36706d scripts/miscellaneous/ver.m --- a/scripts/miscellaneous/ver.m Tue Feb 19 07:18:26 2008 -0500 +++ b/scripts/miscellaneous/ver.m Tue Feb 19 07:24:49 2008 -0500 @@ -19,37 +19,104 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} ver () ## Display a header containing the current Octave version -## number, license string and operating system. +## number, license string and operating system, followed by +## the installed package names, versions, and installation +## directories. +## @deftypefnx {Function File} {v = } ver () +## Return a vector of structures, respecting Octave and each installed package. +## The structure includes the following fields. +## +## @itemize @bullet +## @item v.Name - Package name. +## @item v.Version - Version of the package. +## @item v.Revision - Revision of the package. +## @item v.Date - Date respecting the version/revision. +## @end itemize +## @deftypefnx {Function File} {v = } ver ("Octave") +## Return the structure respecting Octave. +## @deftypefnx {Function File} {v = } ver (pkg) +## Return the structure respecting the specified package. ## @seealso{license, version} ## @end deftypefn ## Author: William Poetra Yoga Hadisoeseno <address@hidden> -function ver () +function varargout = ver (pack) - if (nargin > 0) + if nargin == 0 + pack = ""; + endif + + if (nargin > 1) print_usage (); endif - octave_license = license (); + ## Start with the version info for Octave + ret = struct ("Name", "Octave", "Version", version, + "Release", [], "Date", []); - [unm, status] = uname (); + ## Add the installed packages + lst = pkg("list"); + for i = 1 : length (lst) + ret(end+1) = struct ("Name", lst{i}.name, "Version", lst{i}.version, + "Release", [], "Date", lst{i}.date); + endfor - if (status < 0) - os_string = "unknown"; + if (nargout == 0) + octave_license = license (); + + [unm, status] = uname (); + + if (status < 0) + os_string = "unknown"; + else + os_string = sprintf ("%s %s %s %s", unm.sysname, unm.release, + unm.version, unm.machine); + endif + + hbar(1:70) = "-"; + ver_line1 = "GNU Octave Version "; + ver_line2 = "GNU Octave License: "; + ver_line3 = "Operating System: "; + + ver_desc = sprintf ("%s\n%s%s\n%s%s\n%s%s\n%s\n", hbar, ver_line1, version, + ver_line2, octave_license, ver_line3, os_string, hbar); + + puts (ver_desc); + + pkg ("list") else - os_string = sprintf ("%s %s %s %s", unm.sysname, unm.release, - unm.version, unm.machine); + if (!isempty (pack)) + n = []; + for r = 1:numel(ret) + if (strcmpi (ret(r).Name, pack)) + n = r; + break; + endif + endfor + ret = ret(n); + endif + varargout{1} = ret; endif - hbar(1:70) = "-"; - ver_line1 = "GNU Octave Version "; - ver_line2 = "GNU Octave License: "; - ver_line3 = "Operating System: "; +endfunction - ver_desc = sprintf ("%s\n%s%s\n%s%s\n%s%s\n%s\n", hbar, ver_line1, version, - ver_line2, octave_license, ver_line3, os_string, hbar); +%!test +%! result = ver; +%! assert (result(1).Name, "Octave") +%! assert (result(1).Version, version) +%! result = ver ("octave"); +%! assert (result(1).Name, "Octave") +%! assert (result(1).Version, version) - puts (ver_desc); +%!test +%! lst = pkg ("list"); +%! for n=1:numel(lst) +%! expected = lst{n}.name; +%! result = ver (expected); +%! assert (result.Name, expected); +%! assert (isfield (result, "Version"), true); +%! assert (isfield (result, "Release"), true); +%! assert (isfield (result, "Date"), true); +%! endfor -endfunction |
[Prev in Thread] | Current Thread | [Next in Thread] |