ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] output filename with SHA256
@ 2024-02-23 13:32 Pablo Rodriguez via ntg-context
  2024-02-23 15:01 ` [NTG-context] " mf
  2024-02-23 22:58 ` Bruce Horrocks
  0 siblings, 2 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-02-23 13:32 UTC (permalink / raw)
  To: ConTeXt users; +Cc: Pablo Rodriguez

Dear list,

I have the following sample file:

\starttext
whatever

\startluacode
luatex.wrapup(
  function()
    local t = {}
    local pdf_file_name = tex.jobname..".pdf"
    local sha_pdf = utilities.sha2.hash256(io.loaddata(pdf_file_name))
    local c_r = environment.currentrun
    t[c_r] =  sha_pdf
    local exists_pdf = ("%s_%s-%s.pdf"):format(c_r-1, tex.jobname, t[c_r-1])
    if io.exists(exists_pdf) then os.remove(exists_pdf) end
    os.rename(pdf_file_name, ("%s_%s-%s.pdf"):format(c_r, tex.jobname,
sha_pdf))
  end
)
\stopluacode
\stoptext

In short, it adds its SHA256 to the final filename.

Since renames the PDF document in each run, I would like to remove the
output from the previous run.

The table seems not to store the value from a previous run.

I see now that I am creating it again with each run.

Is there any way to check if compilation needs any other run?

Many thanks for your help,

Pablo
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: output filename with SHA256
  2024-02-23 13:32 [NTG-context] output filename with SHA256 Pablo Rodriguez via ntg-context
@ 2024-02-23 15:01 ` mf
  2024-02-28 11:24   ` Pablo Rodriguez via ntg-context
  2024-02-23 22:58 ` Bruce Horrocks
  1 sibling, 1 reply; 5+ messages in thread
From: mf @ 2024-02-23 15:01 UTC (permalink / raw)
  To: ntg-context

Il 23/02/24 14:32, Pablo Rodriguez via ntg-context ha scritto:
> Dear list,
> 
> I have the following sample file:
> 
> \starttext
> whatever
> 
> \startluacode
> luatex.wrapup(
>    function()
>      local t = {}
>      local pdf_file_name = tex.jobname..".pdf"
>      local sha_pdf = utilities.sha2.hash256(io.loaddata(pdf_file_name))
>      local c_r = environment.currentrun
>      t[c_r] =  sha_pdf
>      local exists_pdf = ("%s_%s-%s.pdf"):format(c_r-1, tex.jobname, t[c_r-1])
>      if io.exists(exists_pdf) then os.remove(exists_pdf) end
>      os.rename(pdf_file_name, ("%s_%s-%s.pdf"):format(c_r, tex.jobname,
> sha_pdf))
>    end
> )
> \stopluacode
> \stoptext
> 
> In short, it adds its SHA256 to the final filename.
> 
> Since renames the PDF document in each run, I would like to remove the
> output from the previous run.
> 
> The table seems not to store the value from a previous run.
> 
> I see now that I am creating it again with each run.
> 
> Is there any way to check if compilation needs any other run?
> 
> Many thanks for your help,
> 
> Pablo
> ___________________________________________________________________________________

Hello Pablo,

you can keep the log, tuc and pdf file of every run with the --keeplog, 
--keeptuc and --keeppdf options (type "context --help --expert" to know 
about the file naming).

A new run is started unless:

- the maxruns number of runs has been reached

- the tuc file is identical to the one of the previous run

Massi
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: output filename with SHA256
  2024-02-23 13:32 [NTG-context] output filename with SHA256 Pablo Rodriguez via ntg-context
  2024-02-23 15:01 ` [NTG-context] " mf
@ 2024-02-23 22:58 ` Bruce Horrocks
  2024-02-27 10:08   ` Pablo Rodriguez via ntg-context
  1 sibling, 1 reply; 5+ messages in thread
From: Bruce Horrocks @ 2024-02-23 22:58 UTC (permalink / raw)
  To: ntg-context mailing list; +Cc: Pablo Rodriguez



> On 23 Feb 2024, at 13:32, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
> 
> Dear list,
> 
> I have the following sample file:
> 
> \starttext
> whatever
> 
> \startluacode
> luatex.wrapup(
>  function()
>    local t = {}
>    local pdf_file_name = tex.jobname..".pdf"
>    local sha_pdf = utilities.sha2.hash256(io.loaddata(pdf_file_name))
>    local c_r = environment.currentrun
>    t[c_r] =  sha_pdf
>    local exists_pdf = ("%s_%s-%s.pdf"):format(c_r-1, tex.jobname, t[c_r-1])
>    if io.exists(exists_pdf) then os.remove(exists_pdf) end
>    os.rename(pdf_file_name, ("%s_%s-%s.pdf"):format(c_r, tex.jobname,
> sha_pdf))
>  end
> )
> \stopluacode
> \stoptext
> 
> In short, it adds its SHA256 to the final filename.
> 
> Since renames the PDF document in each run, I would like to remove the
> output from the previous run.
> 
> The table seems not to store the value from a previous run.
> 
> I see now that I am creating it again with each run.
> 
> Is there any way to check if compilation needs any other run?
> 
> Many thanks for your help,

Rather than use the wrapup() hook can why not rename the file using a second job on the command line?

So your compile command might look like:

  $ context jobname.tex add_sha.tex

Jobname.tex is your main file and generates jobname.pdf as its output, while add_sha.tex contains the rename logic:

\starttext
\startluacode
   local pdf_file_name = "jobname.pdf"
   local sha_pdf = utilities.sha2.hash256(io.loaddata(pdf_file_name))
   os.rename(pdf_file_name, ("%s-%s.pdf"):format(pdf_file_name, sha_pdf))
\stopluacode
Done
\stoptext

—
Bruce Horrocks
Hampshire, UK

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: output filename with SHA256
  2024-02-23 22:58 ` Bruce Horrocks
@ 2024-02-27 10:08   ` Pablo Rodriguez via ntg-context
  0 siblings, 0 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-02-27 10:08 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

On 2/23/24 23:58, Bruce Horrocks wrote:
>> On 23 Feb 2024, at 13:32, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>> [...]
>> Is there any way to check if compilation needs any other run?
>> [...]
> Rather than use the wrapup() hook can why not rename the file using
> a second job on the command line?
>
> So your compile command might look like:
>
>   $ context jobname.tex add_sha.tex

Hi Bruce,

this totally makes sense to me.

But (shame on me!) this is the first time I will type context followed
by two files.

This is also the first time when I see that invoking ConTeXt with more
than a file makes sense to me.

Many thanks for your help,

Pablo
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: output filename with SHA256
  2024-02-23 15:01 ` [NTG-context] " mf
@ 2024-02-28 11:24   ` Pablo Rodriguez via ntg-context
  0 siblings, 0 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-02-28 11:24 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

On 2/23/24 16:01, mf wrote:
> [...]
> A new run is started unless:
> [...]
> - the tuc file is identical to the one of the previous run

Hi Massi,

many thanks for your reply.

If ConTeXt relies on that condition to stop compilation, then it would
be great to know how it is performed to invoke os.rename only on when
the condition takes place.

It would be as to write:

  if x or environment.currentrun >= environment.maxnofruns then
    os.rename(pdf_file, ("%s-%s.pdf"):format(tex.jobname, sha_pdf))
  end

"x" would be the condition where the .tua/.tuc files are identical.

Do you know where that condition is written in the code, so ConTeXt
doesn’t perform another run?

Many thanks for your help,

Pablo
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-28 11:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23 13:32 [NTG-context] output filename with SHA256 Pablo Rodriguez via ntg-context
2024-02-23 15:01 ` [NTG-context] " mf
2024-02-28 11:24   ` Pablo Rodriguez via ntg-context
2024-02-23 22:58 ` Bruce Horrocks
2024-02-27 10:08   ` Pablo Rodriguez via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).