texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Sun, 7 Aug 2022 17:33:22 -0400 (EDT)

branch: master
commit aff083251f17a407f32f9c4cbcc473ca68062bf6
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 7 22:24:06 2022 +0200

    Do not keep EPUB container directory in the default case
    
    * doc/texinfo.texi (Other Customization Variables)
    (Generating EPUB, Output File and Directory),
    tp/Texinfo/Common.pm (@variable_string_settables),
    tp/ext/epub3.pm (_epub_remove_container_folder)
    (epub_setup, epub_finish): remove the EPUB directory
    container unless EPUB_KEEP_CONTAINER_FOLDER is set.
    Set EPUB_KEEP_CONTAINER_FOLDER if undef and TEST or DEBUG.
    
    * tp/ext/epub3.pm (epub_setup): do not error out at loading
    if Archive::Zip could not be loaded, do it at the beginning
    of epub_setup() to be able to determine EPUB_CREATE_CONTAINER_FILE
    based on other customization variable.
---
 ChangeLog            | 17 +++++++++++
 doc/texinfo.texi     | 37 +++++++++++++++++-----
 tp/Texinfo/Common.pm |  1 +
 tp/ext/epub3.pm      | 86 ++++++++++++++++++++++++++++++++++++++--------------
 4 files changed, 110 insertions(+), 31 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5df412fd02..f3b67da913 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2022-08-07  Patrice Dumas  <pertusus@free.fr>
+
+       Do not keep EPUB container directory in the default case
+
+       * doc/texinfo.texi (Other Customization Variables)
+       (Generating EPUB, Output File and Directory),
+       tp/Texinfo/Common.pm (@variable_string_settables),
+       tp/ext/epub3.pm (_epub_remove_container_folder)
+       (epub_setup, epub_finish): remove the EPUB directory
+       container unless EPUB_KEEP_CONTAINER_FOLDER is set.
+       Set EPUB_KEEP_CONTAINER_FOLDER if undef and TEST or DEBUG.
+
+       * tp/ext/epub3.pm (epub_setup): do not error out at loading
+       if Archive::Zip could not be loaded, do it at the beginning
+       of epub_setup() to be able to determine EPUB_CREATE_CONTAINER_FILE
+       based on other customization variable.
+
 2022-08-06  Gavin Smith  <gavinsmith0123@gmail.com>
 
        Add a interface to register errors from init files
diff --git a/doc/texinfo.texi b/doc/texinfo.texi
index 9126336471..af0e9f9fc3 100644
--- a/doc/texinfo.texi
+++ b/doc/texinfo.texi
@@ -16916,9 +16916,13 @@ document is output to standard error; default false.
 
 @item EPUB_CREATE_CONTAINER_FILE
 If set to 0, do not generate the EPUB output file.  Default is set
-to 1.  The directory containing the directories and files needed for
-EPUB is always output.  The EPUB output file is a ZIP archive of the
-container directory.  @xref{EPUB Output File and Directory}.
+to 1.
+
+@item EPUB_KEEP_CONTAINER_FOLDER
+If set, keep the directory containing the directories and files
+needed for EPUB.   The EPUB output file is a ZIP archive of this
+directory.  Default is not defined.  Set if not defined and @code{TEST} or
+@code{DEBUG} is set. @xref{EPUB Output File and Directory}.
 
 @item EXTENSION
 The extension added to the output file name.  The default is different
@@ -18422,6 +18426,20 @@ devices.  @command{texi2any} generated EPUB 3.2 in 
2022.  An EPUB
 file is a ZIP archive container, holding informative files as
 well as the manual rendered in HTML.
 
+@cindex @code{Archive::Zip}, for EPUB file output
+The generation of the EPUB file depends on the @code{Archive::Zip}
+Perl module being installed.  This dependency is checked at runtime.
+In the default case, trying to output EPUB without that dependency raises an
+error.  However, if the EPUB output file is not generated, with the
+customization variable @code{EPUB_CREATE_CONTAINER_FILE} set to 0, it is
+not an error if @code{Archive::Zip} is not installed.
+
+The @command{texi2any} tests related to EPUB generation do not require the
+installation of @code{Archive::Zip}, as they set
+@code{EPUB_CREATE_CONTAINER_FILE} set to 0 and keep the directory containing
+the files and directories needed for the EPUB file by setting the
+@code{EPUB_KEEP_CONTAINER_FOLDER} customization variable to 1.
+
 @node EPUB Output File and Directory
 @subsection Container Directory and Output Files
 A directory containing the files and directories needed for the
@@ -18433,8 +18451,8 @@ or with the @code{SUBDIR} customization function,
 the container directory is created in that directory instead of
 the current directory.  At the beginning of a new run, the container
 directory and all its contents are removed.  The container directory
-is not removed even after the final EPUB file has been generated,
-to be able to look at the EPUB output file content.
+is also removed after the final EPUB file has been generated in the
+default case.
 
 The HTML files produced from the Texinfo manual are output in subdirectories
 of the container directory.  Image files referred to from the Texinfo manual,
@@ -18446,9 +18464,12 @@ extension postpended.  If an output file is specified, 
with
 @option{--output}, or with the @code{OUTFILE} customization function,
 this file name is used instead.  The output EPUB file is never placed
 in the directory specified by @option{--output} or @code{SUBDIR},
-the container directory only is placed there as explained just above.  The EPUB
-output file is not generated if the customization variable
-@code{EPUB_CREATE_CONTAINER_FILE} is set to 0.
+the container directory only is placed there as explained just above.
+
+The EPUB output file is not generated if the customization variable
+@code{EPUB_CREATE_CONTAINER_FILE} is set to 0.  The container directory
+is left after the final EPUB file has been generated if
+@code{EPUB_KEEP_CONTAINER_FOLDER} is set.
 
 @xref{Invoking @command{texi2any}}.
 
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 6d2cc15d6e..f39191b266 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -292,6 +292,7 @@ my @variable_string_settables = (
 'DOC_ENCODING_FOR_OUTPUT_FILE_NAME',
 'DOCTYPE',
 'EPUB_CREATE_CONTAINER_FILE', # for ext/epub3.pm
+'EPUB_KEEP_CONTAINER_FOLDER', # for ext/epub3.pm
 'EXTENSION',
 'EXTERNAL_CROSSREF_EXTENSION',
 'EXTERNAL_CROSSREF_SPLIT',
diff --git a/tp/ext/epub3.pm b/tp/ext/epub3.pm
index a27f6de5eb..014ed14681 100644
--- a/tp/ext/epub3.pm
+++ b/tp/ext/epub3.pm
@@ -74,11 +74,11 @@ use Texinfo::Common;
 use Texinfo::Convert::Utils;
 use Texinfo::Convert::Text;
 
+# try to load here, but only complain and return an error later
+# when the customization variables are known.
 eval { require Archive::Zip; };
 
-if ($@) {
-  texinfo_register_init_loading_failure("Archive::Zip is required for EPUB 
output");
-}
+my $archive_zip_loading_error = $@;
 
 # the 3.2 spec was used for the implementation.  However, it seems to be
 # designed to be backward compatible with 3.0 and mandates to use 3.0 as
@@ -201,6 +201,7 @@ sub epub_noop($$)
 # at the beginning of epub_setup for multi input Texinfo manual cases.
 my $epub_destination_directory;
 my $epub_document_destination_directory;
+my $encoded_epub_destination_directory;
 
 my $epub_document_dir_name = 'EPUB';
 
@@ -334,6 +335,32 @@ sub epub_convert_tree_unit_type($$$$)
                                       $type, $element, $content);
 }
 
+sub _epub_remove_container_folder($$)
+{
+  my $self = shift;
+  my $encoded_epub_destination_directory = shift;
+  my $err_remove_tree;
+  File::Path::remove_tree($encoded_epub_destination_directory,
+                          {'error' => $err_remove_tree});
+  if ($err_remove_tree and scalar(@$err_remove_tree)) {
+    for my $diag (@$err_remove_tree) {
+      my ($file, $message) = %$diag;
+      if ($file eq '') {
+        $self->document_error($self,
+           sprintf(__("error removing directory: %s: %s"),
+                   $epub_destination_directory, $message));
+      }
+      else {
+        $self->document_error($self,
+          sprintf(__("error removing directory: %s: unlinking %s: %s"),
+                  $epub_destination_directory, $file, $message));
+      }
+    }
+    return 0;
+  }
+  return 1;
+}
+
 my $epub_xhtml_dir = 'xhtml';
 # should not clash with generated files.  Could clash with
 # OUTFILE but it is explicitly handled.
@@ -351,10 +378,30 @@ sub epub_setup($)
   $epub_outfile = undef;
   $epub_destination_directory = undef;
   $epub_document_destination_directory = undef;
+  $encoded_epub_destination_directory = undef;
   @epub_output_filenames = ();
   %epub_images = ();
   $nav_filename = $default_nav_filename;
   $epub_file_nr = 1;
+
+  if (not defined($self->get_conf('EPUB_CREATE_CONTAINER_FILE'))) {
+    if (not $self->get_conf('TEST')) {
+      $self->set_conf('EPUB_CREATE_CONTAINER_FILE', 1);
+    }
+  }
+
+  if ($self->get_conf('EPUB_CREATE_CONTAINER_FILE')
+      and $archive_zip_loading_error) {
+    $self->document_error($self,
+       __("Archive::Zip is required for EPUB file output"));
+    return 0;
+  }
+
+  if (not defined($self->get_conf('EPUB_KEEP_CONTAINER_FOLDER'))) {
+    if ($self->get_conf('TEST') or $self->get_conf('DEBUG')) {
+      $self->set_conf('EPUB_KEEP_CONTAINER_FOLDER', 1);
+    }
+  }
   
   $epub_info_js_dir_name = undef;
   if ($self->get_conf('INFO_JS_DIR')) {
@@ -418,27 +465,14 @@ sub epub_setup($)
      File::Spec->catfile($epub_document_destination_directory, 
$xhtml_output_file));
   }
 
-  my $err_remove_tree;
-  my ($encoded_epub_destination_directory, $epub_destination_dir_encoding)
+  my $epub_destination_dir_encoding;
+  ($encoded_epub_destination_directory, $epub_destination_dir_encoding)
     = $self->encoded_output_file_name($epub_destination_directory);
-  File::Path::remove_tree($encoded_epub_destination_directory,
-                          {'error' => $err_remove_tree});
-  if ($err_remove_tree and scalar(@$err_remove_tree)) {
-    for my $diag (@$err_remove_tree) {
-      my ($file, $message) = %$diag;
-      if ($file eq '') {
-        $self->document_error($self,
-           sprintf(__("error removing directory: %s: %s"),
-                   $epub_destination_directory, $message));
-      }
-      else {
-        $self->document_error($self,
-          sprintf(__("error removing directory: %s: unlinking %s: %s"),
-                  $epub_destination_directory, $file, $message));
-      }
-    }
-    return 0;
-  }
+
+  my $status = _epub_remove_container_folder($self,
+                                       $encoded_epub_destination_directory);
+  return $status if (!$status);
+
   my $err_make_path;
   my ($encoded_epub_document_destination_directory, 
$epub_doc_dest_dir_encoding)
     = $self->encoded_output_file_name($epub_document_destination_directory);
@@ -881,6 +915,12 @@ EOT
       return 0;
     }
   }
+
+  if (not $self->get_conf('EPUB_KEEP_CONTAINER_FOLDER')) {
+    my $status = _epub_remove_container_folder($self,
+                                       $encoded_epub_destination_directory);
+    return $status if (!$status);
+  }
   return 1;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]