texlive[45546] Master: more adjustments for json output
commits+preining at tug.org
commits+preining at tug.org
Mon Oct 16 15:30:52 CEST 2017
Revision: 45546
http://tug.org/svn/texlive?view=revision&revision=45546
Author: preining
Date: 2017-10-16 15:30:51 +0200 (Mon, 16 Oct 2017)
Log Message:
-----------
more adjustments for json output
Modified Paths:
--------------
trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
trunk/Master/tlpkg/TeXLive/TLPOBJ.pm
Modified: trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl 2017-10-16 00:17:54 UTC (rev 45545)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl 2017-10-16 13:30:51 UTC (rev 45546)
@@ -1448,6 +1448,15 @@
# 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
@@ -1454,13 +1463,23 @@
# 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 @@
}
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 @@
#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 @@
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
Modified: trunk/Master/tlpkg/TeXLive/TLPOBJ.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLPOBJ.pm 2017-10-16 00:17:54 UTC (rev 45545)
+++ trunk/Master/tlpkg/TeXLive/TLPOBJ.pm 2017-10-16 13:30:51 UTC (rev 45546)
@@ -426,8 +426,16 @@
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 @@
$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;
}
More information about the tex-live-commits
mailing list