summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2017-10-27 05:26:10 +0000
committerNorbert Preining <preining@logic.at>2017-10-27 05:26:10 +0000
commit0bd7e97c405a4efd80b8e304486b4d35825c277c (patch)
treebeeee0027651ed1eeac28a6cdd0410d5d7ac4451 /Master/tlpkg/TeXLive
parentbd41846f4f09f09f3bcc3efa0f49795a63461035 (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')
-rw-r--r--Master/tlpkg/TeXLive/TLPDB.pm77
-rw-r--r--Master/tlpkg/TeXLive/TLPOBJ.pm20
2 files changed, 82 insertions, 15 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
diff --git a/Master/tlpkg/TeXLive/TLPOBJ.pm b/Master/tlpkg/TeXLive/TLPOBJ.pm
index 6ff4908c0f8..0ca7ebb6d19 100644
--- a/Master/tlpkg/TeXLive/TLPOBJ.pm
+++ b/Master/tlpkg/TeXLive/TLPOBJ.pm
@@ -450,7 +450,25 @@ sub as_json {
$foo{'relocated'} = $JSON::false;
}
}
- my $utf8_encoded_json_text = JSON::encode_json(\%foo); # $json->encode(\%foo);
+ # adjust the docfiles entry to the specification in JSON-formats
+ my @docf = $self->docfiles;
+ my $dfd = $self->docfiledata;
+ my @newdocf;
+ for my $f ($self->docfiles) {
+ my %newd;
+ $newd{'file'} = $f;
+ if (defined($dfd->{$f})) {
+ # TODO should we check that there are actually only "details"
+ # and "language" as key?
+ for my $k (keys %{$dfd->{$f}}) {
+ $newd{$k} = $dfd->{$f}->{$k};
+ }
+ }
+ push @newdocf, \%newd;
+ }
+ $foo{'docfiles'} = [ @newdocf ];
+ delete($foo{'docfiledata'});
+ my $utf8_encoded_json_text = JSON::encode_json(\%foo);
return $utf8_encoded_json_text;
}