From dda627a1582626b9930c10097b18d0b1424855f4 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 1 Apr 2013 22:44:46 +0000 Subject: download (24mar13) git-svn-id: svn://tug.org/texlive/trunk@29588 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/download/download.sty | 131 ++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/download/download.sty (limited to 'Master/texmf-dist/tex/latex/download') diff --git a/Master/texmf-dist/tex/latex/download/download.sty b/Master/texmf-dist/tex/latex/download/download.sty new file mode 100644 index 00000000000..c6b607fa522 --- /dev/null +++ b/Master/texmf-dist/tex/latex/download/download.sty @@ -0,0 +1,131 @@ +%% This is file `download.sty', generated from `download.tex' (key `package'). +%% download - download files with LaTeX +%% +%% Copyright (C) 2012 by Simon Sigurdhsson +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3 +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3 or later is part of all distributions of LaTeX +%% version 2005/12/01 or later. +%% +%% This work has the LPPL maintenance status `maintained'. +%% +%% The Current Maintainer of this work is Simon Sigurdhsson. +%% +%% This work consists of the file download.tex +%% and the derived file download.sty. + +\RequirePackage{expl3,l3keys2e,pdftexcmds,xparse} +\ProvidesExplPackage{download} + {2012/12/31}{1.0}{download files with LaTeX} +\msg_new:nnnn{download}{no-write18}{Could~not~use~\string\write18!} + {Please~run~`latex`~with~the~`--shell-escape`~flag.} +\msg_new:nnnn{download}{no-engine}{Could~not~find~cURL~or~wget!} + {Please~make~sure~either~cURL~or~wget~is~installed~and~in~your~PATH.} +\msg_new:nnnn{download}{no-name}{Using~\string\download\space~with~no~filename!} + {This~means~I~will~download~the~file~even~if~it~already~exists.} +\msg_new:nnn{download}{use-curl}{Using~cURL.} +\msg_new:nnn{download}{use-wget}{Using~wget.} +\prg_new_conditional:Nnn\__download_if_shellescape:{F}{ + \if_cs_exist:N\pdf@shellescape + \if_int_compare:w\pdf@shellescape=\c_one + \prg_return_true: + \else: + \prg_return_false: + \fi: + \else: + \prg_return_true: + \fi: +} +\cs_new:Npn\__download_rm:n#1{ + \immediate\write18{rm~#1} +} +\prg_new_conditional:Nnn\__download_if_curl_test:{TF,T,F,p}{ + \immediate\write18{which~curl~&&~touch~\jobname.aex} + \bool_set:Nn\l_tmpa_bool{\c_false_bool} + \file_if_exist:nTF{\jobname.aex}{ + \__download_rm:n{\jobname.aex} + \bool_set:Nn\l_tmpa_bool{\c_true_bool} + }{} + \if_bool:N\l_tmpa_bool + \prg_return_true: + \else: + \prg_return_false: + \fi: +} +\prg_new_conditional:Nnn\__download_if_wget_test:{TF,T,F,p}{ + \immediate\write18{which~wget~&&~touch~\jobname.aex} + \bool_set:Nn\l_tmpa_bool{\c_false_bool} + \file_if_exist:nTF{\jobname.aex}{ + \__download_rm:n{\jobname.aex} + \bool_set:Nn\l_tmpa_bool{\c_true_bool} + }{} + \if_bool:N\l_tmpa_bool + \prg_return_true: + \else: + \prg_return_false: + \fi: +} +\cs_new:Npn\__download_curl_do:nn#1#2{ + \IfNoValueTF{#1}{ + \immediate\write18{curl~-s~#2} + }{ + \immediate\write18{curl~-s~-o~#1~#2} + } +} +\cs_new:Npn\__download_wget_do:nn#1#2{ + \IfNoValueTF{#1}{ + \immediate\write18{wget~-q~-nc~#2} + }{ + \immediate\write18{wget~-q~-nc~-O~#1~#2} + } +} +\prg_new_conditional:Nnn\__download_if_auto_test:{F}{ + \bool_set:Nn\l_tmpb_bool{\c_false_bool} + \__download_if_curl_test:T{\bool_set:Nn\l_tmpb_bool{\c_true_bool}} + \__download_if_wget_test:T{\bool_set:Nn\l_tmpb_bool{\c_true_bool}} + \if_bool:N\l_tmpb_bool + \prg_return_true: + \else: + \prg_return_false: + \fi: +} +\cs_new:Npn\__download_auto_do:nn#1#2{ + \__download_if_wget_test:TF{ + \msg_info:nn{download}{use-wget} + \__download_wget_do:nn{#1}{#2} + }{ + \msg_info:nn{download}{use-curl} + \__download_curl_do:nn{#1}{#2} + } +} +\keys_define:nn{download}{ + engine .choice:, + engine / auto .code:n = + {\cs_gset_eq:NN\__download_do:nn\__download_auto_do:nn + \prg_new_eq_conditional:NNn\__download_if_test:\__download_if_auto_test:{F}}, + engine / curl .code:n = + {\cs_gset_eq:NN\__download_do:nn\__download_curl_do:nn + \prg_new_eq_conditional:NNn\__download_if_test:\__download_if_curl_test:{F}}, + engine / wget .code:n = + {\cs_gset_eq:NN\__download_do:nn\__download_wget_do:nn + \prg_new_eq_conditional:NNn\__download_if_test:\__download_if_wget_test:{F}}, + engine .initial:n = auto, + engine .default:n = auto, +} +\ProcessKeysPackageOptions{download} +\__download_if_shellescape:F{\msg_fatal:nn{download}{no-write18}} +\__download_if_test:F{\msg_fatal:nn{download}{no-engine}} +\DeclareDocumentCommand\download{om}{ + \IfNoValueTF{#1}{ + \msg_warning:nn{download}{no-name} + \__download_do:nn{#1}{#2} + }{ + \file_if_exist:nTF{#1}{}{\__download_do:nn{#1}{#2}} + } +} +\endinput + -- cgit v1.2.3