Re: [NTG-context] slashes in paths (Lua code)

2017-06-01 Thread Pablo Rodriguez
On 06/01/2017 05:47 AM, Akira Kakuto wrote:
>> Directories are a problem here. I mean, 
>> \shatwo{Desktop/i-context.pdf}
>> cannot work in Windows.
> 
> Here both of your example and an example by Hans
> worked fine on Windows.
> Note that
> \shatwo{Desktop/i-context.pdf}
> works only if the current directory is your %USERPROFILE%.

Many thanks for your reply, Akira.

I didn’t check my code on Windows (all my computers at home run Linux).
I’m suprised that it worked.

And thanks for warning about the path and %USERPROFILE%. Of course,
ConTeXt and LuaTeX do magic, but organizing files is a task that belongs
to the user ;-).

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] slashes in paths (Lua code)

2017-06-01 Thread Pablo Rodriguez
On 05/31/2017 10:00 PM, Hans Hagen wrote:
> On 5/31/2017 8:51 PM, Pablo Rodriguez wrote:
>> Dear list,
>>
>> I need to add checksums to files I attach to PDF documents.
>> [...]
>> Directories are a problem here. I mean, \shatwo{Desktop/i-context.pdf}
>> cannot work in Windows.
>>
>> Which would be the way to make it work in Windows?

Many thanks for your code, Hans.

Pablo

> \starttext
>  \startluacode
>  local function sha(cmd,name)
>  local f = io.popen(string.format("%s -b %q",cmd,name),"rb")
>  if f then
>  local s = f:read("*a")
>  f:close()
>   -- s = string.longtostring(s)
>  return string.match(s,"%s*([A-Fa-f0-9]+)")
>  end
>  end
> 
>  function document.sha256(name)
>  local ok = sha("sha256sum",name)
>  if ok then
>  context(ok)
>  end
>  end
> 
>  function document.sha512(name)
>  local ok = sha("sha512sum",name)
>  if ok then
>  context(ok)
>  end
>  end
> \stopluacode
> 
> \def\shatwo #1{\ctxlua{document.sha256("#1")}}
> \def\shafive#1{\ctxlua{document.sha512("#1")}}
> 
> \shafive{fd.pdf}
> \shafive{foo/fd.pdf}
> 
> \stoptext


-- 
http://www.ousia.tk
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] slashes in paths (Lua code)

2017-05-31 Thread Akira Kakuto
Directories are a problem here. I mean, 
\shatwo{Desktop/i-context.pdf}

cannot work in Windows.


Here both of your example and an example by Hans
worked fine on Windows.
Note that
\shatwo{Desktop/i-context.pdf}
works only if the current directory is your %USERPROFILE%.

Best,
Akira

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] slashes in paths (Lua code)

2017-05-31 Thread Hans Hagen

On 5/31/2017 8:51 PM, Pablo Rodriguez wrote:

Dear list,

I need to add checksums to files I attach to PDF documents.

Following the suggestion from https://stackoverflow.com/a/326715, I wrote:

 \starttext
 \startluacode
 function document.capture(cmd, raw)
 local f = assert(io.popen(cmd, 'r'))
 local s = assert(f:read('*a'))
 f:close()
 if raw then return s end
 s = string.gsub(s, '^%s+', '')
 s = string.gsub(s, '%s+$', '')
 s = string.gsub(s, '[\n\r]+', ' ')
 return s
 end

 function document.sha256(file)
 command_output= document.capture("sha256sum -b " .. file)
 context(command_output:sub(0,64))
 end

 function document.sha512(file)
 command_output= document.capture("sha512sum -b " .. file)
 context(command_output:sub(0,128))
 end
 \stopluacode

 \def\shatwo#1%
 {\ctxlua{document.sha256("#1")}}

 \def\shafive#1%
 {\ctxlua{document.sha512("#1")}}

 \shatwo{Desktop/i-context.pdf}

 \shafive{i-context.pdf}
 \stoptext

Directories are a problem here. I mean, \shatwo{Desktop/i-context.pdf}
cannot work in Windows.

Which would be the way to make it work in Windows?

\starttext
\startluacode
local function sha(cmd,name)
local f = io.popen(string.format("%s -b %q",cmd,name),"rb")
if f then
local s = f:read("*a")
f:close()
 -- s = string.longtostring(s)
return string.match(s,"%s*([A-Fa-f0-9]+)")
end
end

function document.sha256(name)
local ok = sha("sha256sum",name)
if ok then
context(ok)
end
end

function document.sha512(name)
local ok = sha("sha512sum",name)
if ok then
context(ok)
end
end
\stopluacode

\def\shatwo #1{\ctxlua{document.sha256("#1")}}
\def\shafive#1{\ctxlua{document.sha512("#1")}}

\shafive{fd.pdf}
\shafive{foo/fd.pdf}

\stoptext


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] slashes in paths (Lua code)

2017-05-31 Thread Pablo Rodriguez
Dear list,

I need to add checksums to files I attach to PDF documents.

Following the suggestion from https://stackoverflow.com/a/326715, I wrote:

\starttext
\startluacode
function document.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end

function document.sha256(file)
command_output= document.capture("sha256sum -b " .. file)
context(command_output:sub(0,64))
end

function document.sha512(file)
command_output= document.capture("sha512sum -b " .. file)
context(command_output:sub(0,128))
end
\stopluacode

\def\shatwo#1%
{\ctxlua{document.sha256("#1")}}

\def\shafive#1%
{\ctxlua{document.sha512("#1")}}

\shatwo{Desktop/i-context.pdf}

\shafive{i-context.pdf}
\stoptext

Directories are a problem here. I mean, \shatwo{Desktop/i-context.pdf}
cannot work in Windows.

Which would be the way to make it work in Windows?

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___