diff options
author | Norbert Preining <preining@logic.at> | 2017-10-27 05:26:10 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2017-10-27 05:26:10 +0000 |
commit | 0bd7e97c405a4efd80b8e304486b4d35825c277c (patch) | |
tree | beeee0027651ed1eeac28a6cdd0410d5d7ac4451 /Master/tlpkg/TeXLive/TLPDB.pm | |
parent | bd41846f4f09f09f3bcc3efa0f49795a63461035 (diff) |
update JSON format, add documentation on formats
git-svn-id: svn://tug.org/texlive/trunk@45620 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/TeXLive/TLPDB.pm')
-rw-r--r-- | Master/tlpkg/TeXLive/TLPDB.pm | 77 |
1 files changed, 63 insertions, 14 deletions
diff --git a/Master/tlpkg/TeXLive/TLPDB.pm b/Master/tlpkg/TeXLive/TLPDB.pm index cff1cfad2b7..9176a04e715 100644 --- a/Master/tlpkg/TeXLive/TLPDB.pm +++ b/Master/tlpkg/TeXLive/TLPDB.pm @@ -479,28 +479,77 @@ the tag of the sub-database, and C<tlpdb> giving the JSON of the database. sub as_json { my $self = shift; - my $ret; + require JSON; + my $ret = "{"; if ($self->is_virtual) { - $ret = "[\n"; my $firsttlpdb = 1; for my $k (keys %{$self->{'tlpdbs'}}) { $ret .= ",\n" if (!$firsttlpdb); - $ret .= "{ \"tag\" : \"$k\", \"tlpdb\" : "; + $ret .= "\"$k\":"; $firsttlpdb = 0; - $ret .= $self->{'tlpdbs'}{$k}->as_json; - $ret .= " }"; + $ret .= $self->{'tlpdbs'}{$k}->_as_json; } - $ret .= "\n]"; } else { - $ret = "[\n"; - my $first = 1; - foreach (keys %{$self->{'tlps'}}) { - $ret .= ",\n" if (!$first); - $first = 0; - $ret .= $self->{'tlps'}{$_}->as_json; - } - $ret .= "\n]"; + $ret .= "\"main\":"; + $ret .= $self->_as_json; } + $ret .= "}\n"; + return($ret); +} + +sub _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/) { + $opts->{$k} += 0 if (exists($opts->{$k})); + } elsif ($TeXLive::TLConfig::TLPDBOptions{$k}[0] eq "b") { + $opts->{$k} = ($opts->{$k} ? $JSON::true : $JSON::false) if (exists($opts->{$k})); + } elsif ($k eq "location") { + 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}; + } + } + } + # the last else is plain strings, nothing to do + } + $ret .= JSON::encode_json($opts); + $ret .= ',"settings":'; + my $sets = $self->settings; + for my $k (keys %TeXLive::TLConfig::TLPDBSettings) { + if ($TeXLive::TLConfig::TLPDBSettings{$k} eq "b") { + $sets->{$k} = ($sets->{$k} ? $JSON::true : $JSON::false) if (exists($sets->{$k})); + } elsif ($TeXLive::TLConfig::TLPDBSettings{$k} eq "available_architectures") { + delete($sets->{$k}); + @{$sets->{$k}} = $self->available_architectures; + } + # else are strings + } + $ret .= JSON::encode_json($sets); + $ret .= ',"configs":'; + my %cfgs; + $cfgs{'container_split_src_files'} = ($self->config_src_container ? $JSON::true : $JSON::false); + $cfgs{'container_split_doc_files'} = ($self->config_doc_container ? $JSON::true : $JSON::false); + $cfgs{'container_format'} = $self->config_container_format; + $cfgs{'release'} = $self->config_release; + $cfgs{'minrelease'} = $self->config_minrelease; + $ret .= JSON::encode_json(\%cfgs); + $ret .= ',"tlpkgs": ['; + my $first = 1; + foreach (keys %{$self->{'tlps'}}) { + $ret .= ",\n" if (!$first); + $first = 0; + $ret .= $self->{'tlps'}{$_}->as_json; + } + $ret .= "]}"; + return($ret); } =pod |