On Tuesday 27 April 2004 14:04, Angus Leeming wrote:
> Jose' Matos wrote:
> >> What happens for users of Python < 2.0? They continue to use
> >> mktemp?
> >
> >   I am afraid so.
> >
> >   For almost a day I have been trying to find an alternative for
> >   those users. Finally I got the one attached.
>
> ;-) Jose, you've just fallen into the trap of doing my work for me.
> Many, many thanks.

  You are killing me, first you take great pains to make sure that we 
use secure temporary files and then you use pipes. Until python 2.3 
that module also used mktemp.... I would jump from a cliff if I had one 
near... ;-)

  Ok, I think that I have a solution for that also, make the pipe 
template return a file like object to be read.

  What does it means $IN and $OUT in the next function?

def crop_files(pnmcrop, basename):
    t = pipes.Template()
    t.append("%s -left $IN" % pnmcrop, 'f-')
    t.append("%s -right > $OUT" % pnmcrop, '-f')

    for file in glob.glob("%s*.ppm" % basename):
        tmp = mkstemp()
        
        if t.copy(file, tmp):
            copyfileobj(tmp, open(file,"wb"))

> >   What do you think? Unless you have any objections I will
> >   incorporate this code into the script and clean it accordingly.
>
> How could I object?
> I'd buy you a beer, if only you touched the stuff ;-)

  In this case I take an exception. ;-)

-- 
José Abílio

LyX and docbook, a perfect match. :-)

Reply via email to