]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/output-distance.py
Merge branch 'master-git.sv.gnu.org-lilypond.git' of /home/lilydev/vc/gub/downloads...
[lilypond.git] / buildscripts / output-distance.py
index a7de28b9ff10b14f53035d09122c91f806f58da2..ec8b5d9e10a769f2a907282d9885997a159c7902 100644 (file)
@@ -17,7 +17,7 @@ INFTY = 1e6
 
 OUTPUT_EXPRESSION_PENALTY = 1
 ORPHAN_GROB_PENALTY = 1
-inspect_max_count = 0
+options = None
 
 def shorten_string (s):
     threshold = 15 
@@ -332,14 +332,17 @@ class FileLink:
         return ''
 
 class MidiFileLink (FileLink):
+    def get_midi (self, f):
+        s = open (f).read ()
+        s = re.sub ('LilyPond [0-9.]+', '', s)
+        return s
+    
     def __init__ (self, f1, f2):
         self.files = (f1, f2)
 
-        print 'reading', f1
-        s1 = open (self.files[0]).read ()
-        print 'reading', f2
-        s2 = open (self.files[1]).read ()
-
+        s1 = self.get_midi (self.files[0])
+        s2 = self.get_midi (self.files[1])
+        
         self.same = (s1 == s2)
         
     def name (self):
@@ -432,21 +435,51 @@ class SignatureFileLink (FileLink):
 
         self.add_system_link (link, system_index[0])
 
+    
+    def create_images (self, old_dir, new_dir, dest_dir):
+
+        files_created = [[], []]
+        for oldnew in (0, 1):
+            pat = self.base_names[oldnew] + '.eps'
+
+            for f in glob.glob (pat):
+                infile = f
+                outfile = (dest_dir + '/' + f).replace ('.eps', '.png')
+
+                mkdir (os.path.split (outfile)[0])
+                cmd = ('gs -sDEVICE=png16m -dGraphicsAlphaBits=4 -dTextAlphaBits=4 '
+                       ' -r101 '
+                       ' -sOutputFile=%(outfile)s -dNOSAFER -dEPSCrop -q -dNOPAUSE '
+                       ' %(infile)s  -c quit '  % locals ())
+
+                files_created[oldnew].append (outfile)
+                system (cmd)
+
+        return files_created
+    
     def link_files_for_html (self, old_dir, new_dir, dest_dir):
-        png_linked = [[], []]
-        for ext in ('.png', '.ly', '-page*png'):
-            
+        to_compare = [[], []]
+
+        exts = ['.ly']
+        if options.create_images:
+            to_compare = self.create_images (old_dir, new_dir, dest_dir)
+        else:
+            exts += ['.png', '-page*png']
+        
+        for ext in exts:            
             for oldnew in (0,1):
                 for f in glob.glob (self.base_names[oldnew] + ext):
                     dst = dest_dir + '/' + f
                     link_file (f, dst)
 
                     if f.endswith ('.png'):
-                        png_linked[oldnew].append (f)
-
-        for (old,new) in zip (png_linked[0], png_linked[1]):
-            compare_png_images (old, new, dest_dir)
+                        to_compare[oldnew].append (f)
+                        
+        if options.compare_images:                
+            for (old, new) in zip (to_compare[0], to_compare[1]):
+                compare_png_images (old, new, dest_dir)
 
+                
     def html_record_string (self,  old_dir, new_dir):
         def img_cell (ly, img, name):
             if not name:
@@ -463,7 +496,6 @@ class SignatureFileLink (FileLink):
 </font>
 </td>
 ''' % locals ()
-
         def multi_img_cell (ly, imgs, name):
             if not name:
                 name = 'source'
@@ -498,6 +530,11 @@ class SignatureFileLink (FileLink):
 
         html_2  = self.base_names[1] + '.html'
         name = self.original_name
+
+        cell_1 = cell (self.base_names[0], name)
+        cell_2 = cell (self.base_names[1], name)
+        if options.compare_images:
+            cell_2 = cell_2.replace ('.png', '.compare.jpeg')
         
         html_entry = '''
 <tr>
@@ -509,9 +546,7 @@ class SignatureFileLink (FileLink):
 %s
 %s
 </tr>
-''' % (self.distance (), html_2,
-       cell (self.base_names[0], name),
-       cell (self.base_names[1], name).replace ('.png', '.compare.jpeg'))
+''' % (self.distance (), html_2, cell_1, cell_2)
 
         return html_entry
 
@@ -633,8 +668,8 @@ class ComparisonData:
             self.added += [(dir2, m) for m in m2] 
 
             for p in paired:
-                if (inspect_max_count
-                    and len (self.file_links) > inspect_max_count):
+                if (options.max_count
+                    and len (self.file_links) > options.max_count):
                     
                     continue
                 
@@ -793,14 +828,15 @@ def test_paired_files ():
 def test_compare_trees ():
     system ('rm -rf dir1 dir2')
     system ('mkdir dir1 dir2')
-    system ('cp 20{-*.signature,.ly,.png} dir1')
-    system ('cp 20{-*.signature,.ly,.png} dir2')
-    system ('cp 20expr{-*.signature,.ly,.png} dir1')
-    system ('cp 19{-*.signature,.ly,.png} dir2/')
-    system ('cp 19{-*.signature,.ly,.png} dir1/')
+    system ('cp 20{-*.signature,.ly,.png,.eps} dir1')
+    system ('cp 20{-*.signature,.ly,.png,.eps} dir2')
+    system ('cp 20expr{-*.signature,.ly,.png,.eps} dir1')
+    system ('cp 19{-*.signature,.ly,.png,.eps} dir2/')
+    system ('cp 19{-*.signature,.ly,.png,.eps} dir1/')
     system ('cp 19-1.signature 19-sub-1.signature')
     system ('cp 19.ly 19-sub.ly')
     system ('cp 19.png 19-sub.png')
+    system ('cp 19.eps 19-sub.eps')
 
     system ('cp 20multipage* dir1')
     system ('cp 20multipage* dir2')
@@ -808,10 +844,10 @@ def test_compare_trees ():
 
     
     system ('mkdir -p dir1/subdir/ dir2/subdir/')
-    system ('cp 19-sub{-*.signature,.ly,.png} dir1/subdir/')
-    system ('cp 19-sub{-*.signature,.ly,.png} dir2/subdir/')
-    system ('cp 20grob{-*.signature,.ly,.png} dir2/')
-    system ('cp 20grob{-*.signature,.ly,.png} dir1/')
+    system ('cp 19-sub{-*.signature,.ly,.png,.eps} dir1/subdir/')
+    system ('cp 19-sub{-*.signature,.ly,.png,.eps} dir2/subdir/')
+    system ('cp 20grob{-*.signature,.ly,.png,.eps} dir2/')
+    system ('cp 20grob{-*.signature,.ly,.png,.eps} dir1/')
 
     ## introduce differences
     system ('cp 19-1.signature dir2/20-1.signature')
@@ -983,6 +1019,17 @@ def main ():
                   type="float",
                   help='threshold for geometric distance')
 
+    p.add_option ('--no-compare-images',
+                  dest="compare_images",
+                  default=True,
+                  action="store_false",
+                  help="Don't run graphical comparisons")
+
+    p.add_option ('--create-images',
+                  dest="create_images",
+                  default=False,
+                  action="store_true",
+                  help="Create PNGs from EPSes")
 
     p.add_option ('-o', '--output-dir',
                   dest="output_dir",
@@ -991,6 +1038,7 @@ def main ():
                   type="string",
                   help='where to put the test results [tree2/compare-tree1tree2]')
 
+    global options
     (options, a) = p.parse_args ()
 
     if options.run_test:
@@ -1001,9 +1049,6 @@ def main ():
         p.print_usage()
         sys.exit (2)
 
-    global inspect_max_count
-    inspect_max_count = options.max_count
-
     name = options.output_dir
     if not name:
         name = a[0].replace ('/', '')