texlive[45726] Master/texmf-dist/scripts/texlive/tlmgr.pl: move JSON

commits+preining at tug.org commits+preining at tug.org
Thu Nov 9 05:44:14 CET 2017


Revision: 45726
          http://tug.org/svn/texlive?view=revision&revision=45726
Author:   preining
Date:     2017-11-09 05:44:14 +0100 (Thu, 09 Nov 2017)
Log Message:
-----------
move JSON loading to the front, remove from other places

Modified Paths:
--------------
    trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl

Modified: trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-11-09 04:18:50 UTC (rev 45725)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-11-09 04:44:14 UTC (rev 45726)
@@ -578,6 +578,19 @@
     tldie("$prg: Try --help if you need it.\n");
   }
 
+  if ($opts{'json'}) {
+    eval { require TeXLive::JSON; };
+    if ($@) {
+      # that didn't work out, give some usefull error message and stop
+      if ($^O =~ /^MSWin/i) {
+        require Win32;
+        my $msg = "Cannot load JSON, that should not happen as we ship it!\n(Error message: $@)\nStopping here.\n";
+        Win32::MsgBox($msg, 1|Win32::MB_ICONSTOP(), "Warning");
+      }
+      tldie("Cannot load JSON module, this should not happen, please report!\n");
+    }
+  }
+
   #
   # the main tree we will be working on
   $::maintree = $Master;
@@ -1419,17 +1432,6 @@
     delete($opts{'data'});
   }
   if ($opts{'json'}) {
-    eval { require TeXLive::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, that should not happen as we ship it!\n(Error message: $@)\nStopping here.\n";
-        Win32::MsgBox($msg, 1|Win32::MB_ICONSTOP(), "Warning");
-      }
-      tldie("Cannot load JSON module, this should not happen, please report!\n");
-    }
     $fmt = 'json';
     # the 1 is the silent mode!
     init_tlmedia_or_die(1);
@@ -1838,21 +1840,24 @@
       if ($mode eq "json") {
         $jsonkeys{'rev'} = "$rs";
         $jsonkeys{'date'} = $dstr;
-        push @outarr, TeXLive::TLUtils::simple_hash_to_json(\%jsonkeys);
+        push @outarr, \%jsonkeys;
       } else {
         push @outarr, "$rs ($dstr)";
       }
     }
-    join(($mode eq "json" ? "," : " "), @outarr);
+    if ($mode eq "json") {
+      return @outarr;
+    } else {
+      return ( join(" ", @outarr));
+    }
   }
   # end sub
   if (!defined($pkg)) {
     if (keys %backups) {
       if ($opts{'json'}) {
-        my $str = "[";
-        $str .= join(",", map { report_backup_revdate($_, "json", %{$backups{$_}}) } keys %backups);
-        $str .= "]\n";
-        print $str;
+        my @bla = map { report_backup_revdate($_, "json", %{$backups{$_}}) } keys %backups;
+        my $str = JSON::encode_json(\@bla);
+        print "$str\n";
       } else {
         print "Available backups:\n";
         foreach my $p (sort keys %backups) {
@@ -1868,10 +1873,9 @@
   }
   if (!defined($rev)) {
     if ($opts{'json'}) {
-      my $str = "[";
-      $str .= report_backup_revdate($pkg, "json", %{$backups{$pkg}});
-      $str .= "]\n";
-      print $str;
+      my @bla = report_backup_revdate($pkg, "json", %{$backups{$pkg}});
+      my $str = JSON::encode_json(\@bla);
+      print "$str\n";
     } else {
       print "Available backups for $pkg: ";
       print(report_backup_revdate($pkg, "text", %{$backups{$pkg}}));



More information about the tex-live-commits mailing list