From: Han-Wen Nienhuys Date: Thu, 4 Jan 2007 23:55:37 +0000 (+0100) Subject: tmp dir safety for output-distance.py X-Git-Tag: release/2.11.9-1~25 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4fa6316167142aaa5d1edf9e65d933c9680a45d9;p=lilypond.git tmp dir safety for output-distance.py --- diff --git a/buildscripts/output-distance.py b/buildscripts/output-distance.py index 5064ca6f30..936af1aaa9 100644 --- a/buildscripts/output-distance.py +++ b/buildscripts/output-distance.py @@ -20,6 +20,37 @@ OUTPUT_EXPRESSION_PENALTY = 1 ORPHAN_GROB_PENALTY = 1 options = None + +temp_dir = None +class TempDirectory: + def __init__ (self): + import tempfile + self.dir = tempfile.mkdtemp () + print 'dir is', self.dir + def __del__ (self): + print 'rm -rf %s' % self.dir + os.system ('rm -rf %s' % self.dir ) + def __call__ (self): + return self.dir + + +def get_temp_dir (): + global temp_dir + if not temp_dir: + temp_dir = TempDirectory () + return temp_dir () + +def read_pipe (c): + print 'pipe' , c + return os.popen (c).read () + +def system (c): + print 'system' , c + s = os.system (c) + if s : + raise Exception ("failed") + return + def shorten_string (s): threshold = 15 if len (s) > 2*threshold: @@ -277,25 +308,13 @@ def read_signature_file (name): hash_to_original_name = {} - -def read_pipe (c): - print 'pipe' , c - return os.popen (c).read () - -def system (c): - print 'system' , c - s = os.system (c) - if s : - raise Exception ("failed") - return - -def compare_png_images (old, new, dir): +def compare_png_images (old, new, dest_dir): def png_dims (f): m = re.search ('([0-9]+) x ([0-9]+)', read_pipe ('file %s' % f)) return tuple (map (int, m.groups ())) - dest = os.path.join (dir, new.replace ('.png', '.compare.jpeg')) + dest = os.path.join (dest_dir, new.replace ('.png', '.compare.jpeg')) try: dims1 = png_dims (old) dims2 = png_dims (new) @@ -307,14 +326,15 @@ def compare_png_images (old, new, dir): dims = (min (dims1[0], dims2[0]), min (dims1[1], dims2[1])) - system ('convert -depth 8 -crop %dx%d+0+0 %s crop1.png' % (dims + (old,))) - system ('convert -depth 8 -crop %dx%d+0+0 %s crop2.png' % (dims + (new,))) + dir = get_temp_dir () + system ('convert -depth 8 -crop %dx%d+0+0 %s %s/crop1.png' % (dims + (old, dir))) + system ('convert -depth 8 -crop %dx%d+0+0 %s %s/crop2.png' % (dims + (new, dir))) - system ('compare -depth 8 crop1.png crop2.png diff.png') + system ('compare -depth 8 %(dir)s/crop1.png %(dir)s/crop2.png %(dir)s/diff.png' % locals ()) - system ("convert -depth 8 diff.png -blur 0x3 -negate -channel alpha,blue -type TrueColorMatte -fx 'intensity' matte.png") + system ("convert -depth 8 %(dir)s/diff.png -blur 0x3 -negate -channel alpha,blue -type TrueColorMatte -fx 'intensity' %(dir)s/matte.png" % locals ()) - system ("composite -quality 65 matte.png %(new)s %(dest)s" % locals ()) + system ("composite -quality 65 %(dir)s/matte.png %(new)s %(dest)s" % locals ()) class FileLink: def __init__ (self):