diff options
author | Norbert Preining <preining@logic.at> | 2017-10-13 01:41:42 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2017-10-13 01:41:42 +0000 |
commit | dedef3ec4c57627762b8203d36c6469e4a5c4a95 (patch) | |
tree | f19bb55c3faa7467b1b27a5f6097a266bef5f673 /Master/texmf-dist | |
parent | 4805e78bb8503ab861bad0e735912808345bf98a (diff) |
tlmgr info: allow for --data json
git-svn-id: svn://tug.org/texlive/trunk@45530 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rwxr-xr-x | Master/texmf-dist/scripts/texlive/tlmgr.pl | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/Master/texmf-dist/scripts/texlive/tlmgr.pl b/Master/texmf-dist/scripts/texlive/tlmgr.pl index 1894da1554f..eb0ed19d3e9 100755 --- a/Master/texmf-dist/scripts/texlive/tlmgr.pl +++ b/Master/texmf-dist/scripts/texlive/tlmgr.pl @@ -210,6 +210,7 @@ my %action_specification = ( "info" => { "options" => { "data" => "=s", + "all" => 1, "list" => 1, "only-installed" => 1, }, @@ -1403,7 +1404,28 @@ sub action_info { my $ret = $F_OK | $F_NOPOSTACTION; my @datafields; my $fmt = "list"; - if ($opts{'data'}) { + if ($opts{'data'} eq "json") { + eval { require JSON; }; + if ($@) { + # that didn't work out, give some usefull error message and stop + if ($^O =~ /^MSWin/i) { + # that should not happen, we are shipping Tk!! + require Win32; + my $msg = "Cannot load JSON:PP, that should not happen as we ship it!\n(Error message: $@)\n"; + Win32::MsgBox($msg, 1|Win32::MB_ICONSTOP(), "Warning"); + } else { + printf STDERR " +$prg: Cannot load JSON. +This module is shipped with core Perl unless you have a very old Perl, +in which case you cannot use the json option. +Goodbye. +"; + } + } + $fmt = 'json'; + # the 1 is the silent mode! + init_tlmedia_or_die(1); + } elsif ($opts{'data'}) { # output format is changed to csv with " as quotes # we need to determine the fields @datafields = split(',', $opts{'data'}); @@ -1431,14 +1453,21 @@ sub action_info { } # we are still here, so $what is defined and neither collection nor scheme, # so assume the arguments are package names - $fmt = ($opts{'data'} ? "csv" : "detail"); + if ($opts{'data'} ne "json") { + $fmt = ($opts{'data'} ? "csv" : "detail"); + } my @adds; if ($opts{'data'}) { @adds = @datafields; } + print "[\n" if ($fmt eq "json"); + my $first = 1; foreach my $ppp ($what, @todo) { + print "," if ($fmt eq "json" && !$first); + $first = 0; $ret |= show_one_package($ppp, $fmt, @adds); } + print "]\n" if ($fmt eq "json"); return ($ret); } @@ -3559,6 +3588,8 @@ sub show_one_package { $ret = show_one_package_detail($pkg, @rest); } elsif ($fmt eq "csv") { $ret = show_one_package_csv($pkg, @rest); + } elsif ($fmt eq "json") { + $ret = show_one_package_json($pkg); } else { tlwarn("$prg: show_one_package: unknown format: $fmt\n"); return($F_ERROR); @@ -3566,6 +3597,24 @@ sub show_one_package { return($ret); } +sub show_one_package_json { + my ($p) = @_; + my @out; + my $loctlp = $localtlpdb->get_package($p); + my $remtlp = $remotetlpdb->get_package($p); + my $is_installed = (defined($loctlp) ? 1 : 0); + my $is_available = (defined($remtlp) ? 1 : 0); + if (!($is_installed || $is_available)) { + tlwarn("$prg: package $p not found neither locally nor remote!\n"); + return($F_WARNING); + } + my $tlp = ($is_installed ? $loctlp : $remtlp); + my $str = $tlp->as_json(); + print $str, "\n"; + return($F_OK); +} + + sub show_one_package_csv { my ($p, @datafields) = @_; my @out; @@ -7632,6 +7681,10 @@ packages' information is listed in CSV format one package per line, and the column information is given by the C<itemN>. The C<depends> column contains the name of all dependencies separated by C<:>. +In case the only value passed to C<--data> is C<json>, the output is a +JSON encoded array where each array element is the JSON representation of +the internal object. + =back |