]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/output-distance.py
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / buildscripts / output-distance.py
index d066ff7af7f3afbabcf354ee03e150e83df938c5..ea82a93de9c1c7d32d37ca79836725764aa6b16e 100644 (file)
@@ -91,7 +91,7 @@ def compare_png_images (old, new, dest_dir):
 
     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 %(dir)s/matte.png %(new)s %(dest)s" % locals ())
+    system ("composite -compose atop -quality 65 %(dir)s/matte.png %(new)s %(dest)s" % locals ())
 
 
 ################################################################
@@ -347,7 +347,10 @@ class FileLink:
         
     def text_record_string (self):
         return '%-30f %-20s\n' % (self.distance (),
-                                  self.name ())
+                                  self.name ()
+                                  + os.path.splitext (self.file_names[1])[1]
+                                  )
+    
     def calc_distance (self):
         return 0.0
 
@@ -357,11 +360,18 @@ class FileLink:
 
         return self._distance
     
+    def source_file (self):
+        for ext in ('.ly', '.ly.txt'):
+            base = os.path.splitext (self.file_names[1])[0]
+            f = base + ext
+            if os.path.exists (f):
+                return f
+            
+        return ''
         
     def name (self):
         base = os.path.basename (self.file_names[1])
         base = os.path.splitext (base)[0]
-        
         base = hash_to_original_name.get (base, base)
         base = os.path.splitext (base)[0]
         return base
@@ -426,6 +436,7 @@ class FileCompareLink (FileLink):
             return 0.0
         else:
             return 100.0;
+
         
     def get_content (self, f):
         print 'reading', f
@@ -433,6 +444,8 @@ class FileCompareLink (FileLink):
         return s
 
 
+
+
 class GitFileCompareLink (FileCompareLink):
     def get_cell (self, oldnew):
         str = self.contents[oldnew]
@@ -451,6 +464,7 @@ class GitFileCompareLink (FileCompareLink):
             d = 1.0001 *options.threshold
 
         return d
+
         
 class TextFileCompareLink (FileCompareLink):
     def calc_distance (self):
@@ -508,12 +522,13 @@ class ProfileFileLink (FileCompareLink):
                     note_info, self.contents[oldnew])
 
         dist = 0.0
-        factor = {'time': 3.0 ,
-                  'cells': 5.0,
-                  }
+        factor = {
+            'time': 0.1,
+            'cells': 5.0,
+            }
         
         for k in ('time', 'cells'):
-            real_val = math.tan (self.get_ratio (k) * 0.5* math.pi)
+            real_val = math.tan (self.get_ratio (k) * 0.5 * math.pi)
             dist += math.exp (math.fabs (real_val) * factor[k])  - 1
 
         dist = min (dist, 100)
@@ -562,12 +577,8 @@ class SignatureFileLink (FileLink):
             
         return d + orphan_distance
 
-    def source_file (self):
-        for ext in ('.ly', '.ly.txt'):
-            if os.path.exists (self.base_names[1] + ext):
-                return self.base_names[1] + ext
-        return ''
-    
+
+
     def add_file_compare (self, f1, f2):
         system_index = [] 
 
@@ -581,18 +592,6 @@ class SignatureFileLink (FileLink):
         self.base_names = (os.path.normpath (base1),
                            os.path.normpath (base2))
 
-        def note_original (match):
-            hash_to_original_name[os.path.basename (self.base_names[1])] = match.group (1)
-            return ''
-        
-        ## ugh: drop the .ly.txt
-        for ext in ('.ly', '.ly.txt'):
-            try:
-                re.sub (r'\\sourcefilename "([^"]+)"',
-                        note_original, open (base1 + ext).read ())
-            except IOError:
-                pass
-                
         s1 = read_signature_file (f1)
         s2 = read_signature_file (f2)
 
@@ -610,12 +609,17 @@ class SignatureFileLink (FileLink):
             for f in glob.glob (pat):
                 infile = f
                 outfile = (dest_dir + '/' + f).replace ('.eps', '.png')
-
+                data_option = ''
+                if options.local_data_dir:
+                    data_option = ('-slilypond-datadir=%s/share/lilypond/current '
+                                   % os.path.split(infile)[0])
+                
                 mkdir (os.path.split (outfile)[0])
                 cmd = ('gs -sDEVICE=png16m -dGraphicsAlphaBits=4 -dTextAlphaBits=4 '
+                       ' %(data_option)s '
                        ' -r101 '
                        ' -sOutputFile=%(outfile)s -dNOSAFER -dEPSCrop -q -dNOPAUSE '
-                       ' %(infile)s  -c quit '  % locals ())
+                       ' %(infile)s  -c quit ') % locals ()
 
                 files_created[oldnew].append (outfile)
                 system (cmd)
@@ -785,6 +789,23 @@ class ComparisonData:
         self.added = []
         self.file_links = {}
 
+    def read_sources (self):
+
+        ## ugh: drop the .ly.txt
+        for (key, val) in self.file_links.items ():
+            
+            def note_original (match, ln=val):
+                key = ln.name ()
+                hash_to_original_name[key] = match.group (1)
+                return ''
+
+            sf = val.source_file ()
+            if sf:
+                re.sub (r'\\sourcefilename "([^"]+)"',
+                        note_original, open (sf).read ())
+            else:
+                print 'no source for', val
+        
     def compare_trees (self, dir1, dir2):
         self.compare_directories (dir1, dir2)
         
@@ -800,7 +821,11 @@ class ComparisonData:
                 self.compare_trees (d1, d2)
     
     def compare_directories (self, dir1, dir2):
-        for ext in ['signature', 'midi', 'log', 'profile', 'gittxt']:
+        for ext in ['signature',
+                    'midi',
+                    'log',
+                    'profile',
+                    'gittxt']:
             (paired, m1, m2) = paired_files (dir1, dir2, '*.' + ext)
 
             self.missing += [(dir1, m) for m in m1] 
@@ -942,6 +967,9 @@ class ComparisonData:
 def compare_trees (dir1, dir2, dest_dir, threshold):
     data = ComparisonData ()
     data.compare_trees (dir1, dir2)
+    data.read_sources ()
+
+    
     data.print_results (threshold)
 
     if os.path.isdir (dest_dir):
@@ -1084,7 +1112,7 @@ def test_basic_compare ():
         
     names = [d['name'] for d in dicts]
 
-    system ('lilypond -ddump-profile -dseparate-log-files -ddump-signatures --png -eps ' + ' '.join (names))
+    system ('lilypond -ddump-profile -dseparate-log-files -ddump-signatures --png -dbackend=eps ' + ' '.join (names))
     
 
     multipage_str = r'''
@@ -1198,6 +1226,13 @@ def main ():
                   action="store_true",
                   help="Create PNGs from EPSes")
 
+
+    p.add_option ('--local-datadir',
+                  dest="local_data_dir",
+                  default=False,
+                  action="store_true",
+                  help='whether to use the share/lilypond/ directory in the test directory')
+
     p.add_option ('-o', '--output-dir',
                   dest="output_dir",
                   default=None,