[latex3-commits] [git/LaTeX3-latex3-latex3] master: First set of shell utilities (see #468) (7b62e64)

Joseph Wright joseph.wright at morningstar2.co.uk
Thu Jul 26 23:36:04 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/7b62e64dde239f9cb6ae0f08400c0b5ccde815d8

>---------------------------------------------------------------

commit 7b62e64dde239f9cb6ae0f08400c0b5ccde815d8
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Thu Jul 26 22:35:47 2018 +0100

    First set of shell utilities (see #468)


>---------------------------------------------------------------

7b62e64dde239f9cb6ae0f08400c0b5ccde815d8
 l3kernel/l3candidates.dtx               |  159 +++++++++++++++++++++++++++++++
 l3kernel/testfiles/m3expl001.luatex.tlg |    5 +
 l3kernel/testfiles/m3expl001.ptex.tlg   |    5 +
 l3kernel/testfiles/m3expl001.tlg        |    5 +
 l3kernel/testfiles/m3expl001.uptex.tlg  |    5 +
 l3kernel/testfiles/m3expl001.xetex.tlg  |    5 +
 l3kernel/testfiles/m3expl003.luatex.tlg |    5 +
 l3kernel/testfiles/m3expl003.ptex.tlg   |    5 +
 l3kernel/testfiles/m3expl003.tlg        |    5 +
 l3kernel/testfiles/m3expl003.uptex.tlg  |    5 +
 l3kernel/testfiles/m3expl003.xetex.tlg  |    5 +
 11 files changed, 209 insertions(+)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 0bc5668..68c3cbe 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -965,6 +965,53 @@
 %   Execute \meta{tokens} through shell escape at shipout.
 % \end{function}
 %
+% \begin{function}[added = 2018-07-27]{\sys_shell_cp:nn}
+%   \begin{syntax}
+%     \cs{sys_shell_cp:nn} \Arg{source} \Arg{dest}
+%   \end{syntax}
+%   Copies the files specified in the \meta{source} (which may include
+%   wildcards) to the \meat{dest}. The file paths should be specified using
+%   |/| as a path separator.  If unrestricted shell escape is not enabled, no
+%   action is attempted.
+% \end{function}
+%
+% \begin{function}[added = 2018-07-27]{\sys_shell_mkdir:n}
+%   \begin{syntax}
+%     \cs{sys_shell_mkdir:n} \Arg{directory}
+%   \end{syntax}
+%   Creates the \meta{directory}, which should should  be specified using |/| as
+%   a path separator.  If unrestricted shell escape is not enabled, no action is
+%   attempted.
+% \end{function}
+%
+% \begin{function}[added = 2018-07-27]{\sys_shell_ren:nnn}
+%   \begin{syntax}
+%     \cs{sys_shell_ren:nnn} \Ag{path} \Arg{old} \Arg{new}
+%   \end{syntax}
+%   Renames the files in the meta{\path} from the \meta{old} to \meta{new}
+%   name (which may include wildcards). The \meta{path} should be specified using
+%   |/| as a path separator.  If unrestricted shell escape is not enabled, no
+%   action is attempted.
+% \end{function}
+%
+% \begin{function}[added = 2018-07-27]{\sys_shell_rm:n}
+%   \begin{syntax}
+%     \cs{sys_shell_rm:n} \Arg{files}
+%   \end{syntax}
+%   Removes the \meta{files} (which may include wildcards). The file path should
+%   be specified using |/| as a path separator.  If unrestricted shell escape is
+%   not enabled, no action is attempted.
+% \end{function}
+%
+% \begin{function}[added = 2018-07-27]{\sys_shell_rmdir:n}
+%   \begin{syntax}
+%     \cs{sys_shell_rmdir:n} \Arg{directory}
+%   \end{syntax}
+%   Removes the \meta{directory}, which should should  be specified using |/| as
+%   a path separator.  If unrestricted shell escape is not enabled, no action is
+%   attempted.
+% \end{function}
+%
 % \section{Additions to \pkg{l3tl}}
 %
 % \begin{function}[EXP,pTF]{\tl_if_single_token:n}
@@ -3032,6 +3079,118 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}{\sys_shell_cp:nn}
+%   Simple Unix-like file copying: at some stage we may need a directory-only
+%   version as Windows and Unix have different requirements here.
+%    \begin{macrocode}
+\cs_new_protected:Npx \sys_shell_cp:nn #1#2
+  {
+    \sys_if_shell_unrestricted:T
+      {
+        \sys_shell_now:x
+          {
+            \sys_if_platform_unix:T
+              { cp~-RLf~ \exp_not:N \tl_to_str:n {#1} ~ \tl_to_str:n {#2} }
+            \sys_if_platform_windows:T
+              {
+                xcopy~/y~ \exp_not:N \@@_path_to_win:n {#1} ~
+                  \exp_not:N \@@_path_to_win:n {#2}
+              }
+          }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\sys_shell_mkdir:n}
+%   Windows (with the extensions) will automatically make directory trees but
+%   issues a warning if the directory already exists: avoid by including a
+%   test.
+%    \begin{macrocode}
+\cs_new_protected:Npx \sys_shell_mkdir:n #1
+  {
+    \sys_if_shell_unrestricted:T
+      {
+        \sys_shell_now:x
+          {
+            \sys_if_platform_unix:T
+              { mkdir~-p~ \exp_not:N \tl_to_str:n {#1} }
+            \sys_if_platform_windows:T
+              {
+                if~not~exist~
+                  \exp_not:N \@@_path_to_win:n { #1 / nul } ~
+                  mkdir~ \exp_not:N \@@_path_to_win:n {#1}
+              }
+          }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\sys_shell_ren:nnn}
+%   The differences in syntax between Unix and Windows mean that it's not easy
+%   to provide |mv|: instead we go with |ren|-like syntax but with arguments
+%   set up to work with Unix too.
+%    \begin{macrocode}
+\cs_new_protected:Npx \sys_shell_ren:nnn #1#2#3
+  {
+    \sys_if_shell_unrestricted:T
+      {
+        \sys_shell_now:x
+          {
+            \sys_if_platform_unix:T
+              { mv~-f~ \tl_to_str:n { #1 / #2 } ~ \tl_to_str:n { #1 / #3 } }
+            \sys_if_platform_windows:T
+              {
+                ren~ \exp_not:N \@@_path_to_win:n { #1 / #2 } ~
+                  \exp_not:N \tl_to_str:n {#3}
+              }
+          }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\sys_shell_rm:n}
+%   Deletion: obviously a big health warning here!
+%    \begin{macrocode}
+\cs_new_protected:Npx \sys_shell_rm:n #1
+  {
+    \sys_if_shell_unrestricted:T
+      {
+        \sys_shell_now:x
+          {
+            \sys_if_platform_unix:T
+              { rm~-f~ \exp_not:N \tl_to_str:n {#1}  }
+            \sys_if_platform_windows:T
+              { del~/f~/q~ \exp_not:N \@@_path_to_win:n {#1} }
+          }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\sys_shell_rmdir:n}
+%   When removing a directory, we create it first as that avoids errors in
+%   the Windows case.
+%    \begin{macrocode}
+\cs_new_protected:Npx \sys_shell_rmdir:n #1
+  {
+    \sys_if_shell_unrestricted:T
+      {
+        \sys_shell_mkdir:n {#1}
+        \sys_shell_now:x
+          {
+            \sys_if_platform_unix:T
+              { rm~-r~ \exp_not:N \tl_to_str:n {#1} }
+            \sys_if_platform_windows:T
+              { rmdir~/s~/q~ \exp_not:N \@@_path_to_win:n {#1} }
+          }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{Additions to \pkg{l3tl}}
 %
 %    \begin{macrocode}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 2136175..90701c4 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -5853,6 +5853,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 8f1a560..d6b43f2 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5887,6 +5887,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 5b72b23..885e024 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -5887,6 +5887,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 95ed152..a2b4e5c 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -5884,6 +5884,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index e647653..385185b 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5857,6 +5857,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 2136175..90701c4 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -5853,6 +5853,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 8f1a560..d6b43f2 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5887,6 +5887,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 5b72b23..885e024 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -5887,6 +5887,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 95ed152..a2b4e5c 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -5884,6 +5884,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index e647653..385185b 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5857,6 +5857,11 @@ Defining \sys_shell_shipout:x on line ...
 Defining \__sys_path_to_win:n on line ...
 Defining \__sys_path_to_win:w on line ...
 Defining \__sys_path_to_win:N on line ...
+Defining \sys_shell_cp:nn on line ...
+Defining \sys_shell_mkdir:n on line ...
+Defining \sys_shell_ren:nnn on line ...
+Defining \sys_shell_rm:n on line ...
+Defining \sys_shell_rmdir:n on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...





More information about the latex3-commits mailing list