texlive[45776] Master: tlmgr paper --json output
commits+preining at tug.org
commits+preining at tug.org
Mon Nov 13 18:05:15 CET 2017
Revision: 45776
http://tug.org/svn/texlive?view=revision&revision=45776
Author: preining
Date: 2017-11-13 18:05:14 +0100 (Mon, 13 Nov 2017)
Log Message:
-----------
tlmgr paper --json output
Modified Paths:
--------------
trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
trunk/Master/tlpkg/TeXLive/TLPaper.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-13 17:05:00 UTC (rev 45775)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl 2017-11-13 17:05:14 UTC (rev 45776)
@@ -1213,6 +1213,19 @@
} elsif (!defined($newpaper)) { # tlmgr paper => show all current sizes.
my $ret = $F_OK;
+ if ($opts{'json'}) {
+ my @foo;
+ for my $prog (keys %TeXLive::TLPaper::paper) {
+ my $pkg = $TeXLive::TLPaper::paper{$prog}{'pkg'};
+ if ($localtlpdb->get_package($pkg)) {
+ my $val = TeXLive::TLPaper::do_paper($prog,$texmfconfig,"--json");
+ push @foo, $val;
+ }
+ }
+ my $json = TeXLive::TLUtils::encode_json(\@foo);
+ print "$json\n";
+ return $ret;
+ }
for my $prog (sort keys %TeXLive::TLPaper::paper) {
my $pkg = $TeXLive::TLPaper::paper{$prog}{'pkg'};
if ($localtlpdb->get_package($pkg)) {
@@ -7922,6 +7935,8 @@
=item B<S<[xdvi|pdftex|dvips|dvipdfmx|context|psutils] paper [I<papersize>|--list]>>
+=item B<paper --json>
+
=back
With no arguments (C<tlmgr paper>), shows the default paper size setting
@@ -7942,6 +7957,10 @@
last argument (e.g., C<tlmgr dvips paper --list>), shows all valid paper
sizes for that program. The first size shown is the default.
+If no argument is given but C<--json> is specified, the current status is
+outputed in JSON. For the format of JSON output see C<tlpkg/doc/JSON-formats.txt>,
+format definition C<TLPAPER>.
+
Incidentally, this syntax of having a specific program name before the
C<paper> keyword is unusual. It is inherited from the longstanding
C<texconfig> script, which supports other configuration settings for
Modified: trunk/Master/tlpkg/TeXLive/TLPaper.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLPaper.pm 2017-11-13 17:05:00 UTC (rev 45775)
+++ trunk/Master/tlpkg/TeXLive/TLPaper.pm 2017-11-13 17:05:14 UTC (rev 45776)
@@ -396,6 +396,17 @@
for my $p (keys %pdftex_papersize) {
info("$p\n") unless ($p eq $currentpaper);
}
+ } elsif ($newpaper eq "--json") {
+ my @ret = ();
+ push @ret, "$currentpaper";
+ for my $p (keys %pdftex_papersize) {
+ push @ret, $p unless ($p eq $currentpaper);
+ }
+ my %foo;
+ $foo{'program'} = "pdftex";
+ $foo{'file'} = $inp;
+ $foo{'options'} = \@ret;
+ return \%foo;
} elsif ($newpaper eq "--returnlist") {
my @ret = ();
push @ret, "$currentpaper";
@@ -542,6 +553,12 @@
for my $p (@papersizes) {
info("$p\n"); # first is already the selected one
}
+ } elsif ($newpaper eq "--json") {
+ my %foo;
+ $foo{'program'} = "dvips";
+ $foo{'file'} = $inp;
+ $foo{'options'} = \@papersizes;
+ return \%foo;
} elsif ($newpaper eq "--returnlist") {
return(\@papersizes);
} else {
@@ -703,6 +720,17 @@
for my $p (keys %pdftex_papersize) {
info("$p\n") unless ($p eq $currentpaper);
}
+ } elsif ($newpaper eq "--json") {
+ my @ret = ();
+ push @ret, "$currentpaper";
+ for my $p (keys %pdftex_papersize) {
+ push @ret, $p unless ($p eq $currentpaper);
+ }
+ my %foo;
+ $foo{'program'} = "context";
+ $foo{'file'} = $inp;
+ $foo{'options'} = \@ret;
+ return \%foo;
} elsif ($newpaper eq "--returnlist") {
my @ret = ();
push @ret, "$currentpaper";
@@ -862,6 +890,17 @@
for my $p (@$paplist) {
info("$p\n") unless ($p eq $currentpaper);
}
+ } elsif ($newpaper eq "--json") {
+ my @ret = ();
+ push @ret, "$currentpaper";
+ for my $p (@$paplist) {
+ push @ret, $p unless ($p eq $currentpaper);
+ }
+ my %foo;
+ $foo{'program'} = $prog;
+ $foo{'file'} = $inp;
+ $foo{'options'} = \@ret;
+ return \%foo;
} elsif ($newpaper eq "--returnlist") {
my @ret = ();
push @ret, $currentpaper;
Modified: trunk/Master/tlpkg/doc/JSON-formats.txt
===================================================================
--- trunk/Master/tlpkg/doc/JSON-formats.txt 2017-11-13 17:05:00 UTC (rev 45775)
+++ trunk/Master/tlpkg/doc/JSON-formats.txt 2017-11-13 17:05:14 UTC (rev 45776)
@@ -131,5 +131,25 @@
}
]
+
+TLPAPER
+-------
+array of objects, each one having three keys: program, file, options.
+`program' gives the program name, `file' the place where the configuration
+has been found, and `options' is an array of strings with the first
+one being the currently selected paper.
+Example for one element of the array:
+ {
+ "options" : [
+ "a4",
+ "letter"
+ ],
+ "file" : "/usr/local/texlive/2017/texmf-config/tex/generic/config/pdftexconfig.tex",
+ "program" : "pdftex"
+ }
+
+
+
+
TODO
UPDATE JSON format
More information about the tex-live-commits
mailing list