]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/output-distance.py
Merge branch 'cvs-head' of ssh+git://hanwen@repo.or.cz/srv/git/lilypond into master...
[lilypond.git] / buildscripts / output-distance.py
index 91db6f0699f4c22241c61d843ca5d7935b04c7a2..92768454dc4c80f5247137aa21386209f2aa46b0 100644 (file)
@@ -246,8 +246,20 @@ class SystemLink:
     
 def read_signature_file (name):
     print 'reading', name
-    exp_str = ("[%s]" % open (name).read ())
-    entries = safeeval.safe_eval (exp_str)
+    
+    entries = open (name).read ().split ('\n')
+    def string_to_tup (s):
+        return tuple (map (float, s.split (' '))) 
+
+    def string_to_entry (s):
+        fields = s.split('@')
+        fields[2] = string_to_tup (fields[2])
+        fields[3] = string_to_tup (fields[3])
+
+        return tuple (fields)
+    
+    entries = [string_to_entry (e) for e in entries
+               if e and not e.startswith ('#')]
 
     grob_sigs = [GrobSignature (e) for e in entries]
     sig = SystemSignature (grob_sigs)
@@ -269,9 +281,13 @@ class FileLink:
 
     def calc_distance (self):
         d = 0.0
+
+        orphan_distance = 0.0
         for l in self.system_links.values ():
             d = max (d, l.geometric_distance ())
-        return d
+            orphan_distance += l.orphan_count ()
+            
+        return d + orphan_distance
 
     def distance (self):
         if type (self._distance) != type (0.0):
@@ -325,10 +341,11 @@ class FileLink:
         self.add_system_link (link, system_index[0])
 
     def link_files_for_html (self, old_dir, new_dir, dest_dir):
-        for ext in ('.png', '.ly'):
+        for ext in ('.png', '.ly', '-page*png'):
             for oldnew in (0,1):
-                link_file (self.base_names[oldnew] + ext, 
-                           dest_dir + '/' + self.base_names[oldnew] + ext)
+                for f in glob.glob (self.base_names[oldnew] + ext):
+                    print f
+                    link_file (f, dest_dir + '/' + f)
 
     def html_record_string (self,  old_dir, new_dir):
         def img_cell (ly, img, name):
@@ -346,12 +363,38 @@ class FileLink:
 </font>
 </td>
 ''' % locals ()
-        
 
-        img_1  = self.base_names[0] + '.png'
-        ly_1  = self.base_names[0] + '.ly'
-        img_2  = self.base_names[1] + '.png'
-        ly_2  = self.base_names[1] + '.ly'
+        def multi_img_cell (ly, imgs, name):
+            if not name:
+                name = 'source'
+            else:
+                name = '<tt>%s</tt>' % name
+
+            imgs_str = '\n'.join (['''<a href="%s">
+<img src="%s" style="border-style: none; max-width: 500px;">
+</a><br>''' % (img, img) 
+                                  for img in imgs])
+
+
+            return '''
+<td align="center">
+%(imgs_str)s
+<font size="-2">(<a href="%(ly)s">%(name)s</a>)
+</font>
+</td>
+''' % locals ()
+
+
+
+        def cell (base, name):
+            pages = glob.glob (base + '-page*.png')
+            
+            if pages:
+                return multi_img_cell (base + '.ly', sorted (pages), name)
+            else:
+                return img_cell (base + '.ly', base + '.png', name)
+            
+
         html_2  = self.base_names[1] + '.html'
         name = self.original_name
         
@@ -366,8 +409,8 @@ class FileLink:
 %s
 </tr>
 ''' % (self.distance (), html_2,
-       img_cell (ly_1, img_1, name), img_cell (ly_2, img_2, name))
-
+       cell (self.base_names[0], name),
+       cell (self.base_names[1], name))
 
         return html_entry
 
@@ -553,8 +596,8 @@ class ComparisonData:
             if score <= threshold:
                 continue
 
-            link.write_html_system_details (dir1, dir2, dest_dir)
             link.link_files_for_html (dir1, dir2, dest_dir) 
+            link.write_html_system_details (dir1, dir2, dest_dir)
             html += link.html_record_string (dir1, dir2)
 
 
@@ -607,7 +650,11 @@ def mkdir (x):
 
 def link_file (x, y):
     mkdir (os.path.split (y)[0])
-    os.link (x, y)
+    try:
+        os.link (x, y)
+    except OSError, z:
+        print 'OSError', x, y, z
+        raise OSError
     
 def open_write_file (x):
     d = os.path.split (x)[0]
@@ -638,6 +685,11 @@ def test_compare_trees ():
     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 20multipage* dir1')
+    system ('cp 20multipage* dir2')
+    system ('cp 19multipage-1.signature dir2/20multipage-1.signature')
+
     
     system ('mkdir -p dir1/subdir/ dir2/subdir/')
     system ('cp 19-sub{-*.signature,.ly,.png} dir1/subdir/')
@@ -657,16 +709,18 @@ def test_compare_trees ():
 
 
 def test_basic_compare ():
-    ly_template = r"""#(set! toplevel-score-handler print-score-with-defaults)
-#(set! toplevel-music-handler
- (lambda (p m)
- (if (not (eq? (ly:music-property m 'void) #t))
-    (print-score-with-defaults
-    p (scorify-music m p)))))
+    ly_template = r"""
+#(set! toplevel-score-handler print-score-with-defaults)
+ #(set! toplevel-music-handler
+  (lambda (p m)
+  (if (not (eq? (ly:music-property m 'void) #t))
+     (print-score-with-defaults
+     p (scorify-music m p)))))
 
 \sourcefilename "my-source.ly"
-
 %(papermod)s
+\header { tagline = ##f } 
 <<
 \new Staff \relative c {
   c4^"%(userstring)s" %(extragrob)s
@@ -692,8 +746,8 @@ def test_basic_compare ():
              { 'papermod' : '',
                'name' : '20grob',
                'extragrob': 'r2. \\break c1',
-               'userstring': 'test' }
-
+               'userstring': 'test' },
+                
              ]
 
     for d in dicts:
@@ -703,11 +757,47 @@ def test_basic_compare ():
     
     system ('lilypond -ddump-signatures --png -b eps ' + ' '.join (names))
     
-    sigs = dict ((n, read_signature_file ('%s-1.signature' % n)) for n in names)
+
+    multipage_str = r'''
+    #(set-default-paper-size "a6")
+    {c1 \pageBreak c1 }
+    '''
+
+    open ('20multipage', 'w').write (multipage_str)
+    open ('19multipage', 'w').write ('#(set-global-staff-size 19.5)\n' + multipage_str)
+    system ('lilypond -ddump-signatures --png 19multipage 20multipage ')
+    test_compare_signatures (names)
+    
+def test_compare_signatures (names, timing=False):
+
+    import time
+
+    times = 1
+    if timing:
+        times = 100
+
+    t0 = time.clock ()
+
+    count = 0
+    for t in range (0, times):
+        sigs = dict ((n, read_signature_file ('%s-1.signature' % n)) for n in names)
+        count += 1
+
+    if timing:
+        print 'elapsed', (time.clock() - t0)/count
+
+
+    t0 = time.clock ()
+    count = 0
     combinations = {}
     for (n1, s1) in sigs.items():
         for (n2, s2) in sigs.items():
             combinations['%s-%s' % (n1, n2)] = SystemLink (s1,s2).distance ()
+            count += 1
+
+    if timing:
+        print 'elapsed', (time.clock() - t0)/count
 
     results = combinations.items ()
     results.sort ()
@@ -747,6 +837,7 @@ def main ():
                   dest="run_test",
                   action="store_true",
                   help='run test method')
+    
     p.add_option ('--max-count',
                   dest="max_count",
                   metavar="COUNT",
@@ -754,7 +845,6 @@ def main ():
                   default=0, 
                   action="store",
                   help='only analyze COUNT signature pairs')
 
     p.add_option ('', '--threshold',
                   dest="threshold",