texlive[45791] Master: TLPDB: factorize json code, tlmgr: json for

commits+preining at tug.org commits+preining at tug.org
Tue Nov 14 02:55:52 CET 2017


Revision: 45791
          http://tug.org/svn/texlive?view=revision&revision=45791
Author:   preining
Date:     2017-11-14 02:55:52 +0100 (Tue, 14 Nov 2017)
Log Message:
-----------
TLPDB: factorize json code, tlmgr: json for option

Modified Paths:
--------------
    trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
    trunk/Master/tlpkg/TeXLive/TLPDB.pm
    trunk/Master/tlpkg/doc/JSON-formats.txt

Modified: trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-11-14 01:21:53 UTC (rev 45790)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-11-14 01:55:52 UTC (rev 45791)
@@ -4392,7 +4392,13 @@
   $what = "show" unless defined($what);
   init_local_db();
   my $ret = $F_OK;
+  my %json;
   if ($what =~ m/^show$/i) {
+    if ($opts{'json'}) {
+      my $json = $localtlpdb->options_as_json();
+      print("$json\n");
+      return($ret);
+    }
     for my $o (sort keys %{$localtlpdb->options}) {
       # ignore some things which are w32 specific
       next if ($o eq "desktop_integration" && !win32());
@@ -4414,6 +4420,11 @@
       }
     }
   } elsif ($what =~ m/^showall$/i) {
+    if ($opts{'json'}) {
+      my $json = $localtlpdb->options_as_json();
+      print("$json\n");
+      return($ret);
+    }
     my %loc = %{$localtlpdb->options};
     for my $o (sort keys %TLPDBOptions) {
       if ($::machinereadable) {
@@ -7833,9 +7844,9 @@
 
 =over 4
 
-=item B<option [show]>
+=item B<option [--json] [show]>
 
-=item B<option showall>
+=item B<option [--json] showall>
 
 =item B<option I<key> [I<value>]>
 
@@ -7848,6 +7859,11 @@
 The second form is similar, but also shows options which can be defined
 but are not currently set to any value.
 
+Both forms take an option C<--json> in which case the options are dumped
+in JSON format. In addition, with C<--json> the two forms dump the same
+data. For the format of JSON output see C<tlpkg/doc/JSON-formats.txt>,
+format definition C<TLOPTIONS>.
+
 In the third form, if I<value> is not given, the setting for I<key> is
 displayed.  If I<value> is present, I<key> is set to I<value>.
 

Modified: trunk/Master/tlpkg/TeXLive/TLPDB.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLPDB.pm	2017-11-14 01:21:53 UTC (rev 45790)
+++ trunk/Master/tlpkg/TeXLive/TLPDB.pm	2017-11-14 01:55:52 UTC (rev 45791)
@@ -496,12 +496,9 @@
   return($ret);
 }
 
-sub _as_json {
+sub options_as_json {
   my $self = shift;
   die("calling _as_json on virtual is not supported!") if ($self->is_virtual);
-  my $ret = "{";
-  # options
-  $ret .= '"options":';
   my $opts = $self->options;
   for my $k (keys %TeXLive::TLConfig::TLPDBOptions) {
     if ($TeXLive::TLConfig::TLPDBOptions{$k}[0] =~ m/^n/) {
@@ -519,8 +516,12 @@
     }
     # the last else is plain strings, nothing to do
   }
-  $ret .= TeXLive::TLUtils::encode_json($opts);
-  $ret .= ',"settings":';
+  return(TeXLive::TLUtils::encode_json($opts));
+}
+
+sub settings_as_json {
+  my $self = shift;
+  die("calling _as_json on virtual is not supported!") if ($self->is_virtual);
   my $sets = $self->settings;
   for my $k (keys %TeXLive::TLConfig::TLPDBSettings) {
     if ($TeXLive::TLConfig::TLPDBSettings{$k} eq "b") {
@@ -531,8 +532,12 @@
     }
     # else are strings
   }
-  $ret .= TeXLive::TLUtils::encode_json($sets);
-  $ret .= ',"configs":';
+  return(TeXLive::TLUtils::encode_json($sets));
+}
+
+sub configs_as_json {
+  my $self = shift;
+  die("calling _as_json on virtual is not supported!") if ($self->is_virtual);
   my %cfgs;
   $cfgs{'container_split_src_files'} = ($self->config_src_container ? TeXLive::TLUtils::True() : TeXLive::TLUtils::False());
   $cfgs{'container_split_doc_files'} = ($self->config_doc_container ? TeXLive::TLUtils::True() : TeXLive::TLUtils::False());
@@ -539,7 +544,19 @@
   $cfgs{'container_format'} = $self->config_container_format;
   $cfgs{'release'} = $self->config_release;
   $cfgs{'minrelease'} = $self->config_minrelease;
-  $ret .= TeXLive::TLUtils::encode_json(\%cfgs);
+  return(TeXLive::TLUtils::encode_json(\%cfgs));
+}
+
+sub _as_json {
+  my $self = shift;
+  die("calling _as_json on virtual is not supported!") if ($self->is_virtual);
+  my $ret = "{";
+  $ret .= '"options":';
+  $ret .= $self->options_as_json();
+  $ret .= ',"settings":';
+  $ret .= $self->settings_as_json();
+  $ret .= ',"configs":';
+  $ret .= $self->configs_as_json();
   $ret .= ',"tlpkgs": [';
   my $first = 1;
   foreach (keys %{$self->{'tlps'}}) {

Modified: trunk/Master/tlpkg/doc/JSON-formats.txt
===================================================================
--- trunk/Master/tlpkg/doc/JSON-formats.txt	2017-11-14 01:21:53 UTC (rev 45790)
+++ trunk/Master/tlpkg/doc/JSON-formats.txt	2017-11-14 01:55:52 UTC (rev 45791)
@@ -152,6 +152,34 @@
    }
 
 
+TLOPTIONS
+---------
+one object with keys are the option names and values are as follows:
+- String for options: sys_bin, sys_info, sys_man, backupdir
+- Boolean: install_srcfiles, install_docfiles, generate_updmap, 
+           w32_multi_user, desktop_integration, create_formats, post_code
+- Number: file_assocs, autobackup
+- Object: location: keys are tags, values are URLs (Strings)
+Example:
+{
+   "sys_bin" : "/usr/local/bin",
+   "sys_info" : "/usr/local/share/info",
+   "sys_man" : "/usr/local/share/man",
+   "file_assocs" : 1,
+   "location" : {
+      "main" : "/home/norbert/public_html/tlnet",
+      "tlcritical" : "/home/norbert/public_html/tlcritical",
+   },
+   "autobackup" : 1,
+   "install_srcfiles" : true,
+   "post_code" : true,
+   "create_formats" : true,
+   "backupdir" : "tlpkg/backups",
+   "w32_multi_user" : true,
+   "desktop_integration" : true,
+   "generate_updmap" : false,
+   "install_docfiles" : true
+}
 
 
 TODO



More information about the tex-live-commits mailing list