diff options
author | Norbert Preining <preining@logic.at> | 2017-10-16 13:30:51 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2017-10-16 13:30:51 +0000 |
commit | 7897147d3438f4a13492c780041c65ac7723184d (patch) | |
tree | d9a97850bc19e34bb9e63932aaded9b6b47dfe03 | |
parent | 0fc3099d15c927418f2c91d42485cb7a619a2b2f (diff) |
more adjustments for json output
git-svn-id: svn://tug.org/texlive/trunk@45546 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-x | Master/texmf-dist/scripts/texlive/tlmgr.pl | 75 | ||||
-rw-r--r-- | Master/tlpkg/TeXLive/TLPOBJ.pm | 14 |
2 files changed, 41 insertions, 48 deletions
diff --git a/Master/texmf-dist/scripts/texlive/tlmgr.pl b/Master/texmf-dist/scripts/texlive/tlmgr.pl index 9354d9f8658..e3e9af9c597 100755 --- a/Master/texmf-dist/scripts/texlive/tlmgr.pl +++ b/Master/texmf-dist/scripts/texlive/tlmgr.pl @@ -1448,19 +1448,38 @@ Goodbye. # the 1 is the silent mode! init_tlmedia_or_die(1); } + my $tlm; + if ($opts{"only-installed"}) { + $tlm = $localtlpdb; + } else { + # silent mode + init_tlmedia_or_die(1); + $tlm = $remotetlpdb; + } + # # tlmgr info # tlmgr info collection # tlmgr info scheme # these commands just list the packages/collections/schemes installed with # a short list + my @whattolist; $what = ($what || "-all"); - if ($what =~ m/^(collections|schemes|-all)$/i) { - $ret |= show_list_of_packages($fmt, $what, @datafields); - return ($ret); + if ($what =~ m/^collections$/i) { + @whattolist = $tlm->collections; + } elsif ($what =~ m/^schemes$/i) { + @whattolist = $tlm->schemes; + } elsif ($what =~ m/^-all$/i) { + if ($tlm->is_virtual) { + @whattolist = $tlm->list_packages("-all"); + } else { + @whattolist = $tlm->list_packages; + } + # add also the local packages + TeXLive::TLUtils::push_uniq(@whattolist, $localtlpdb->list_packages); + } else { + @whattolist = ($what, @todo); } - # we are still here, so $what is defined and neither collection nor scheme, - # so assume the arguments are package names if ($opts{'data'}) { if ($opts{'data'} ne "json") { $fmt = "csv"; @@ -1474,7 +1493,8 @@ Goodbye. } print "[\n" if ($fmt eq "json"); my $first = 1; - foreach my $ppp ($what, @todo) { + foreach my $ppp (@whattolist) { + next if ($ppp =~ m/^00texlive\./); print "," if ($fmt eq "json" && !$first); $first = 0; $ret |= show_one_package($ppp, $fmt, @adds); @@ -3623,9 +3643,13 @@ sub show_one_package_json { #return($F_WARNING); return($F_OK); } - my $tlp = ($is_installed ? $loctlp : $remtlp); + my $tlp = ($is_available ? $remtlp : $loctlp); + # add available, installed, lrev, rrev fields and remove revision field my $str = $tlp->as_json(available => ($is_available ? $JSON::true : $JSON::false), - installed => ($is_installed ? $JSON::true : $JSON::false)); + installed => ($is_installed ? $JSON::true : $JSON::false), + lrev => ($is_installed ? $loctlp->revision : 0), + rrev => ($is_available ? $remtlp->revision : 0), + revision => undef); print $str, "\n"; return($F_OK); } @@ -3990,41 +4014,6 @@ sub show_one_package_detail { return($ret); } -sub show_list_of_packages { - init_local_db(); - my ($fmt, $what, @datafields) = @_; - my $ret = $F_OK; - my $tlm; - if ($opts{"only-installed"}) { - $tlm = $localtlpdb; - } else { - # silent mode - init_tlmedia_or_die(1); - $tlm = $remotetlpdb; - } - my @whattolist; - if ($what =~ m/^collections/i) { - @whattolist = $tlm->collections; - } elsif ($what =~ m/^schemes/i) { - @whattolist = $tlm->schemes; - } elsif ($what =~ m/^-all/i) { - if ($tlm->is_virtual) { - @whattolist = $tlm->list_packages("-all"); - } else { - @whattolist = $tlm->list_packages; - } - } else { - tlwarn("$prg: show_list_of_package: don't know what to list: $what\n"); - return($F_ERROR); - } - my @extra; - foreach (@whattolist) { - next if ($_ =~ m/^00texlive/); - $ret |= show_one_package($_, $fmt, @datafields); - } - return($ret); -} - # PINNING # # this action manages the pinning file diff --git a/Master/tlpkg/TeXLive/TLPOBJ.pm b/Master/tlpkg/TeXLive/TLPOBJ.pm index 95c5adeffbf..1530c1a06c8 100644 --- a/Master/tlpkg/TeXLive/TLPOBJ.pm +++ b/Master/tlpkg/TeXLive/TLPOBJ.pm @@ -426,8 +426,16 @@ sub as_json { require JSON; #my $json = JSON::PP->new->utf8; my %foo = %{$self}; + # set the additional args + for my $k (keys %addargs) { + if (defined($addargs{$k})) { + $foo{$k} = $addargs{$k}; + } else { + delete($foo{$k}); + } + } # make sure numbers are encoded as numbers - for my $k (qw/revision runsize docsize srcsize containersize + for my $k (qw/revision runsize docsize srcsize containersize lrev rrev srccontainersize doccontainersize runcontainersize/) { $foo{$k} += 0 if exists($foo{$k}); } @@ -442,10 +450,6 @@ sub as_json { $foo{'relocated'} = $JSON::false; } } - # set the additional args - for my $k (keys %addargs) { - $foo{$k} = $addargs{$k}; - } my $utf8_encoded_json_text = JSON::encode_json(\%foo); # $json->encode(\%foo); return $utf8_encoded_json_text; } |