diff options
author | Norbert Preining <preining@logic.at> | 2017-11-13 17:05:14 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2017-11-13 17:05:14 +0000 |
commit | 3b7fca8248b6f2f73cb9d1dd6011c29fbc3b9f55 (patch) | |
tree | 95fbc2229db732cc2c41534fec180c347b4840b6 /Master | |
parent | 86830c3b1728a5ad4d946bc32b722762a9010439 (diff) |
tlmgr paper --json output
git-svn-id: svn://tug.org/texlive/trunk@45776 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rwxr-xr-x | Master/texmf-dist/scripts/texlive/tlmgr.pl | 19 | ||||
-rw-r--r-- | Master/tlpkg/TeXLive/TLPaper.pm | 39 | ||||
-rw-r--r-- | Master/tlpkg/doc/JSON-formats.txt | 20 |
3 files changed, 78 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/texlive/tlmgr.pl b/Master/texmf-dist/scripts/texlive/tlmgr.pl index d925cc0f3cf..5cfe48fe220 100755 --- a/Master/texmf-dist/scripts/texlive/tlmgr.pl +++ b/Master/texmf-dist/scripts/texlive/tlmgr.pl @@ -1213,6 +1213,19 @@ sub action_paper { } 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 @@ default. =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 @@ With a program given as the first argument and C<--list> given as the 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 diff --git a/Master/tlpkg/TeXLive/TLPaper.pm b/Master/tlpkg/TeXLive/TLPaper.pm index 8f2f469aac1..70bd55ef501 100644 --- a/Master/tlpkg/TeXLive/TLPaper.pm +++ b/Master/tlpkg/TeXLive/TLPaper.pm @@ -396,6 +396,17 @@ sub paper_pdftex { 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 @@ sub paper_dvips { 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 @@ sub paper_context { 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 @@ sub paper_do_simple { 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; diff --git a/Master/tlpkg/doc/JSON-formats.txt b/Master/tlpkg/doc/JSON-formats.txt index 9f0edd0762e..c2917098e67 100644 --- a/Master/tlpkg/doc/JSON-formats.txt +++ b/Master/tlpkg/doc/JSON-formats.txt @@ -131,5 +131,25 @@ Example: } ] + +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 |