texlive[45793] Master: option/setting json: change format, all

commits+preining at tug.org commits+preining at tug.org
Tue Nov 14 07:51:52 CET 2017


Revision: 45793
          http://tug.org/svn/texlive?view=revision&revision=45793
Author:   preining
Date:     2017-11-14 07:51:51 +0100 (Tue, 14 Nov 2017)
Log Message:
-----------
option/setting json: change format, all strings, document format

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 06:51:37 UTC (rev 45792)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-11-14 06:51:51 UTC (rev 45793)
@@ -7862,7 +7862,7 @@
 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>.
+format definition C<TLOPTION>.
 
 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 06:51:37 UTC (rev 45792)
+++ trunk/Master/tlpkg/TeXLive/TLPDB.pm	2017-11-14 06:51:51 UTC (rev 45793)
@@ -500,23 +500,49 @@
   my $self = shift;
   die("calling _as_json on virtual is not supported!") if ($self->is_virtual);
   my $opts = $self->options;
+  my @opts;
   for my $k (keys %TeXLive::TLConfig::TLPDBOptions) {
-    if ($TeXLive::TLConfig::TLPDBOptions{$k}[0] =~ m/^n/) {
-      $opts->{$k} += 0 if (exists($opts->{$k}));
-    } elsif ($TeXLive::TLConfig::TLPDBOptions{$k}[0] eq "b") {
-      $opts->{$k} = ($opts->{$k} ? TeXLive::TLUtils::True() : TeXLive::TLUtils::False()) if (exists($opts->{$k}));
-    } elsif ($k eq "location") {
+    my %foo;
+    $foo{'name'} = $k;
+    $foo{'tlmgrname'} = $TeXLive::TLConfig::TLPDBOptions{$k}[2];
+    $foo{'description'} = $TeXLive::TLConfig::TLPDBOptions{$k}[3];
+    $foo{'format'} = $TeXLive::TLConfig::TLPDBOptions{$k}[0];
+    $foo{'default'} = "$TeXLive::TLConfig::TLPDBOptions{$k}[1]";
+    # if ($TeXLive::TLConfig::TLPDBOptions{$k}[0] =~ m/^n/) {
+    #   if (exists($opts->{$k})) {
+    #     $foo{'value'} = $opts->{$k};
+    #     $foo{'value'} += 0;
+    #   }
+    #   $foo{'default'} += 0;
+    # } elsif ($TeXLive::TLConfig::TLPDBOptions{$k}[0] eq "b") {
+    #   if (exists($opts->{$k})) {
+    #     $foo{'value'} = ($opts->{$k} ? TeXLive::TLUtils::True() : TeXLive::TLUtils::False());
+    #   }
+    #   $foo{'default'} = ($foo{'default'} ? TeXLive::TLUtils::True() : TeXLive::TLUtils::False());
+    # } elsif ($k eq "location") {
+    #   my %def;
+    #   $def{'main'} = $TeXLive::TLConfig::TLPDBOptions{$k}[1];
+    #   $foo{'default'} = \%def;
+    #   if (exists($opts->{$k})) {
+    #     my %repos = TeXLive::TLUtils::repository_to_array($opts->{$k});
+    #     $foo{'value'} = \%repos;
+    #   }
+    # } elsif ($TeXLive::TLConfig::TLPDBOptions{$k}[0] eq "p") {
+    #   # strings/path
+    #   if (exists($opts->{$k})) {
+    #     $foo{'value'} = $opts->{$k};
+    #   }
+    # } else {
+    
+    # TREAT ALL VALUES AS STRINGS, otherwise not parsable JSON
+      # treat as strings
       if (exists($opts->{$k})) {
-        my %foo = TeXLive::TLUtils::repository_to_array($opts->{$k});
-        delete($opts->{$k});
-        for my $u (keys %foo) {
-          $opts->{$k}{$u} = $foo{$u};
-        }
+        $foo{'value'} = $opts->{$k};
       }
-    }
-    # the last else is plain strings, nothing to do
+    #  }
+    push @opts, \%foo;
   }
-  return(TeXLive::TLUtils::encode_json($opts));
+  return(TeXLive::TLUtils::encode_json(\@opts));
 }
 
 sub settings_as_json {
@@ -523,16 +549,29 @@
   my $self = shift;
   die("calling _as_json on virtual is not supported!") if ($self->is_virtual);
   my $sets = $self->settings;
+  my @json;
   for my $k (keys %TeXLive::TLConfig::TLPDBSettings) {
-    if ($TeXLive::TLConfig::TLPDBSettings{$k} eq "b") {
-      $sets->{$k} = ($sets->{$k} ? TeXLive::TLUtils::True() : TeXLive::TLUtils::False()) if (exists($sets->{$k}));
-    } elsif ($TeXLive::TLConfig::TLPDBSettings{$k} eq "available_architectures") {
-      delete($sets->{$k});
-      @{$sets->{$k}} = $self->available_architectures;
-    }
-    # else are strings
+    my %foo;
+    $foo{'name'} = $k;
+    $foo{'type'} = $TeXLive::TLConfig::TLPDBSettings{$k}[0];
+    $foo{'description'} = $TeXLive::TLConfig::TLPDBSettings{$k}[1];
+    # if ($TeXLive::TLConfig::TLPDBSettings{$k}[0] eq "b") {
+    #   if (exists($sets->{$k})) {
+    #     $foo{'value'} = ($sets->{$k} ? TeXLive::TLUtils::True() : TeXLive::TLUtils::False());
+    #   }
+    # } elsif ($TeXLive::TLConfig::TLPDBSettings{$k} eq "available_architectures") {
+    #   if (exists($sets->{$k})) {
+    #     my @lof = $self->available_architectures;
+    #     $foo{'value'} = \@lof;
+    #   }
+    # } else {
+      if (exists($sets->{$k})) {
+        $foo{'value'} = "$sets->{$k}";
+      }
+    # }
+    push @json, \%foo;
   }
-  return(TeXLive::TLUtils::encode_json($sets));
+  return(TeXLive::TLUtils::encode_json(\@json));
 }
 
 sub configs_as_json {

Modified: trunk/Master/tlpkg/doc/JSON-formats.txt
===================================================================
--- trunk/Master/tlpkg/doc/JSON-formats.txt	2017-11-14 06:51:37 UTC (rev 45792)
+++ trunk/Master/tlpkg/doc/JSON-formats.txt	2017-11-14 06:51:51 UTC (rev 45793)
@@ -65,34 +65,11 @@
 -----------
 JSON object with the following fields:
 * Object type:
-  - options: keys are the tlmgr names of %TLConfig::TLPDBOptions, that is
-    . Number type: autobackup, fileassocs
-    . Boolean type: formats, desktop_integration, generate_updmap, docfiles, 
-                    srcfiles, postcode, w32_multi_user
-    . String type: backupdir, location, sys_bin, sys_info, sys_man
-    . Object type: repository: keys are tags, values are Strings
-       if there is only one location then the tag is "main"
-    Example:
-      "options": {
-        "autobackup": 2,
-        "formats": false,
-        "postcode": true,
-        "backupdir": "/backup/tl",
-        "repository": {
-          "main": "http://mirror.ctan.org/systems/texlive/tlnet",
-          "tlcontrib": "..."
-        }
-      }
-
-  - settings: keys are the names of %TLConfig::TLPDBSettings, that is
-    . Boolean type: usertree
-    . String type: platform
-    . Array type: available_architectures (Strings)
-
+  - options: see TLOPTION below
+  - settings: see TLSETTING below
   - configs: keys are the names of %TLConfig::TLPDBConfigs, that is
     . Boolean type: container_split_src_files, container_split_doc_files
     . String type: container_format, minrelease, release
-
 * Array type:
   - tlpkgs: JSON array of TLPOBJs in JSON format
 
@@ -152,35 +129,29 @@
    }
 
 
-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
-}
+TLOPTION / TLSETTING
+--------------------
+each option/setting is an object with the following keys, values
+are all strings(!)
+for TLOPTIONS:
+  name, tlmgrname, description, format, default, value (optional)
+for TLSETTING:
+  name, description, format, value (optional)
+Example TLOPTIONS:
+         {
+            "format" : "b",
+            "description" : "Install source files",
+            "tlmgrname" : "srcfiles",
+            "value" : "1",
+            "default" : "1",
+            "name" : "install_srcfiles"
+         },
+Example TLSETTING
+         {
+            "type" : "b",
+            "description" : "This tree acts as user tree",
+            "name" : "usertree"
+         },
 
 
-TODO
-  UPDATE JSON format
+



More information about the tex-live-commits mailing list