diff options
author | Norbert Preining <preining@logic.at> | 2017-11-14 01:55:52 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2017-11-14 01:55:52 +0000 |
commit | a8aab6a5879b5e2b6f0668647d1e90bdbff98cdb (patch) | |
tree | 78fc836c6766136b7f45bbf33d331916ebc68172 | |
parent | 30ec8ba376ce0f3583a35183357fdf318fc45608 (diff) |
TLPDB: factorize json code, tlmgr: json for option
git-svn-id: svn://tug.org/texlive/trunk@45791 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-x | Master/texmf-dist/scripts/texlive/tlmgr.pl | 20 | ||||
-rw-r--r-- | Master/tlpkg/TeXLive/TLPDB.pm | 35 | ||||
-rw-r--r-- | Master/tlpkg/doc/JSON-formats.txt | 28 |
3 files changed, 72 insertions, 11 deletions
diff --git a/Master/texmf-dist/scripts/texlive/tlmgr.pl b/Master/texmf-dist/scripts/texlive/tlmgr.pl index d49075b42e6..75fe0a2e5f2 100755 --- a/Master/texmf-dist/scripts/texlive/tlmgr.pl +++ b/Master/texmf-dist/scripts/texlive/tlmgr.pl @@ -4392,7 +4392,13 @@ sub action_option { $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 @@ sub action_option { } } } 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 @@ from the local keyring. =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 @@ parentheses. 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>. diff --git a/Master/tlpkg/TeXLive/TLPDB.pm b/Master/tlpkg/TeXLive/TLPDB.pm index b4e79bd8711..68644527b6b 100644 --- a/Master/tlpkg/TeXLive/TLPDB.pm +++ b/Master/tlpkg/TeXLive/TLPDB.pm @@ -496,12 +496,9 @@ sub as_json { 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 @@ sub _as_json { } # 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,15 +532,31 @@ sub _as_json { } # 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()); $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'}}) { diff --git a/Master/tlpkg/doc/JSON-formats.txt b/Master/tlpkg/doc/JSON-formats.txt index d9a1259443e..3447a819f4d 100644 --- a/Master/tlpkg/doc/JSON-formats.txt +++ b/Master/tlpkg/doc/JSON-formats.txt @@ -152,6 +152,34 @@ Example for one element of the array: } +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 |