texlive[45543] Master: add install/available keys to JSON output,

commits+preining at tug.org commits+preining at tug.org
Sun Oct 15 02:47:23 CEST 2017


Revision: 45543
          http://tug.org/svn/texlive?view=revision&revision=45543
Author:   preining
Date:     2017-10-15 02:47:23 +0200 (Sun, 15 Oct 2017)
Log Message:
-----------
add install/available keys to JSON output, deal with unavailable packages

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-15 00:21:53 UTC (rev 45542)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-10-15 00:47:23 UTC (rev 45543)
@@ -3617,11 +3617,15 @@
   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);
+    # output proper JSON for unavailable packages
+    print "{ \"name\":\"$p\", \"available\":false }\n";
+    #tlwarn("$prg: package $p not found neither locally nor remote!\n");
+    #return($F_WARNING);
+    return($F_OK);
   }
   my $tlp = ($is_installed ? $loctlp : $remtlp);
-  my $str = $tlp->as_json();
+  my $str = $tlp->as_json(available => ($is_available ? $JSON::true : $JSON::false), 
+                          installed => ($is_installed ? $JSON::true : $JSON::false));
   print $str, "\n";
   return($F_OK);
 }

Modified: trunk/Master/tlpkg/TeXLive/TLPOBJ.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLPOBJ.pm	2017-10-15 00:21:53 UTC (rev 45542)
+++ trunk/Master/tlpkg/TeXLive/TLPOBJ.pm	2017-10-15 00:47:23 UTC (rev 45543)
@@ -422,6 +422,7 @@
 
 sub as_json {
   my $self = shift;
+  my %addargs = @_;
   require JSON;
   #my $json = JSON::PP->new->utf8;
   my %foo = %{$self};
@@ -441,6 +442,10 @@
       $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