On Sun, Apr 23, 2006 at 10:49:00PM -0700, Danny Yoo wrote:
>
>
>On Sun, 23 Apr 2006, George Georgalis wrote:
>
>>Hi! I've been struggling to find a way up seed hash.update() with
>>the sha1 (or similar) of the file that is the program running.
>>
>>this is not a security task but rather a means to generate
>>reasonably unique filenames based on various parameters including
>>changes to the program: name = hash.hexdigest()
>>
>>so new files are generated when the program or parameters are
>>changed; but cached files are used when identical results are
>>expected.
>>
>>help! I cannot figure out how to pass the program body as a seed
>>to hash.update().
>
>Hi George,
>
>I'm slightly confused. Isn't this a matter of doing:
>
>###
>def prepare_md5(filename):
>m = md5.new()
>m.update(open(filename).read()) ## not so smart: do this
> ## progressively in real life!
>return m
>###
I'm pretty green as far as python is concerned, but that looks good.
However filename is unpredictable, as this is a website plugin module,
and the path could be anything.
open(filename).read()
>Are you asking instead: how do I get the filename of the currently running
>program?
yep, that's the main part of the problem I have
# Use a hash of the parameters to generate a cache filename.
hash = sha.new(texData)
hash.update( "%d %d" % (density, int(texMag)) )
hash.update( outputVersion )
name = hash.hexdigest()
imageFile = "%s/%s.%s" % (imagePath, name, 'png')
where outputVersion is a manual set variable in the program
(so I have to purge all the imageFile each time I adjust the
program. maybe this is going to work, less progressive approach
# Use a hash of the parameters to generate a cache filename.
hash = sha.new(texData)
hash.update( "%d %d" % (density, int(texMag)) )
hash.update( open(argv[0]).read() )
name = hash.hexdigest()
imageFile = "%s/%s.%s" % (imagePath, name, 'png')
I cannot test till the evening because of $WORK; but is that a
good way to do it?
// George
--
George Georgalis, systems architect, administrator <
http://galis.org/ cell:646-331-2027 mailto:[EMAIL PROTECTED]
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor