bug-texinfo
[Top][All Lists]
Advanced

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

Re: epub generation depends on perl Archive::ZIP module


From: Patrice Dumas
Subject: Re: epub generation depends on perl Archive::ZIP module
Date: Sun, 7 Aug 2022 20:12:24 +0200

On Fri, Aug 05, 2022 at 11:11:10PM +0100, Gavin Smith wrote:
> On Sun, Jul 31, 2022 at 09:22:01AM +0200, Patrice Dumas wrote:
> 
> * Call functions in the module as it is being loaded to register
> errors.
> 
> A patch for the second approach is at the end of this email.  I'm
> sure you'll have ideas for how this could be improved.

The approach looks perfect to me.

> It would be better if we could avoid loading the rest of the module
> once the problem is detected, although I don't know if this is
> possible without calling "die".

I don't think this is very important.

> Unlike the current code, this makes Archive::Zip a hard requirement
> for EPUB output - it does not allow creating the unzipped folder.  This
> could easily be changed, I expect.

Indeed, I will add some customization variables to be able to do
flexibly container folder and/or epub file.

> A separate issue, but is it worth outputting the unzipped folder at
> all?  Wouldn't it be cleaner to delete the unzipped folder when
> done and just leave the zipped EPUB file?

Yes, I agree, I'll add some customization variable, to keep the
container folder, and have TEST set it and unset the one which requires
Archive.

> Test it by changing "require Archive::Zip" to "require Archive::Zipx" or
> some other module that doesn't exist.
> 
> diff --git a/tp/Texinfo/Config.pm b/tp/Texinfo/Config.pm
> index afe4dd81f2..b068166c77 100644
> --- a/tp/Texinfo/Config.pm
> +++ b/tp/Texinfo/Config.pm
> @@ -119,6 +119,12 @@ sub _GNUT_document_warn($) {
>                     "%s: warning: %s\n"), $real_command_name, $text)));
>  }
>  
> +my @module_errors;
> +sub GNUT_config_failed($) {
> +  my $error = shift;
> +  push @module_errors, $error;
> +}
> +
>  # called from texi2any.pl main program.
>  # eval $FILE in the Texinfo::Config namespace. $FILE should be a binary 
> string.
>  sub GNUT_load_init_file($) {
> @@ -133,6 +139,13 @@ sub GNUT_load_init_file($) {
>      _GNUT_document_warn(sprintf(__("error loading %s: %s"),
>                  _GNUT_decode_input($file), $e));
>    }
> +  for my $error (@module_errors) {
> +    warn sprintf(__("error loading %s: %s"),
> +                _GNUT_decode_input($file), $error)."\n";
> +  }
> +  if (@module_errors) {
> +    exit 1;
> +  }
>  }
>  
>  # L2H removed in 2021
> diff --git a/tp/ext/epub3.pm b/tp/ext/epub3.pm
> index 0767c7daea..0e61fce15d 100644
> --- a/tp/ext/epub3.pm
> +++ b/tp/ext/epub3.pm
> @@ -78,6 +78,12 @@ use Texinfo::Common;
>  use Texinfo::Convert::Utils;
>  use Texinfo::Convert::Text;
>  
> +eval { require Archive::Zip; };
> +
> +if ($@) {
> +  GNUT_config_failed("Archive::Zip is required for EPUB output");
> +}
> +
>  # 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
>  # version.
> @@ -830,8 +836,6 @@ EOT
>    }
>  
>    if ($self->get_conf('EPUB_CREATE_CONTAINER_FILE')) {
> -    require Archive::Zip;
> -
>      # this is needed if there are non ascii file names, otherwise, for 
> instance
>      # with calibre the files cannot be read, one get
>      # "There is no item named 'EPUB/osé.opf' in the archive"
> 



reply via email to

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