From: Bruce Horrocks <ntg@scorecrow.com>
To: ntg-context mailing list <ntg-context@ntg.nl>
Cc: Pablo Rodriguez <oinos@gmx.es>
Subject: [NTG-context] Re: output filename with SHA256
Date: Fri, 23 Feb 2024 22:58:24 +0000 [thread overview]
Message-ID: <32E9F0AB-980E-4871-8718-36E344FA0774@scorecrow.com> (raw)
In-Reply-To: <269aab33-7bea-dc17-04f5-0b89342a425d@gmx.es>
> 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
___________________________________________________________________________________
next prev parent reply other threads:[~2024-02-23 23:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-23 13:32 [NTG-context] " 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 [this message]
2024-02-27 10:08 ` Pablo Rodriguez via ntg-context
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32E9F0AB-980E-4871-8718-36E344FA0774@scorecrow.com \
--to=ntg@scorecrow.com \
--cc=ntg-context@ntg.nl \
--cc=oinos@gmx.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).