]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/output-distance.py
Merge branch 'master' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / buildscripts / output-distance.py
index 4846af20b317c599fa34217daadfbe3186ea3ce5..e56b1e477de1e044df67092e2269aa19428aabd5 100644 (file)
@@ -7,9 +7,7 @@ import math
 ## so we can call directly as buildscripts/output-distance.py
 me_path = os.path.abspath (os.path.split (sys.argv[0])[0])
 sys.path.insert (0, me_path + '/../python/')
-
-
-import safeeval
+sys.path.insert (0, me_path + '/../python/out/')
 
 
 X_AXIS = 0
@@ -367,9 +365,9 @@ class FileLink:
         base = hash_to_original_name.get (base, base)
         base = os.path.splitext (base)[0]
         return base
-
+    
     def extension (self):
-        return '<undefined>'
+        return os.path.splitext (self.file_names[1])[1]
 
     def link_files_for_html (self, dest_dir):
         for f in self.file_names:
@@ -378,15 +376,13 @@ class FileLink:
     def get_distance_details (self):
         return ''
 
-    def get_cell (oldnew):
+    def get_cell (self, oldnew):
         return ''
     
     def get_file (self, oldnew):
         return self.file_names[oldnew]
     
     def html_record_string (self, dest_dir):
-        self.link_files_for_html (dest_dir)
-        
         dist = self.distance()
         
         details = self.get_distance_details ()
@@ -394,7 +390,7 @@ class FileLink:
             details_base = os.path.splitext (self.file_names[1])[0]
             details_base += '.details.html'
             fn = dest_dir + '/'  + details_base
-            open (fn, 'w').write (details)
+            open_write_file (fn).write (details)
 
             details = '<br>(<a href="%(details_base)s">details</a>)' % locals ()
 
@@ -422,9 +418,6 @@ class FileCompareLink (FileLink):
                          self.get_content (self.file_names[1]))
         
 
-    def extension (self):
-        return '.ext'
-
     def calc_distance (self):
         ## todo: could use import MIDI to pinpoint
         ## what & where changed.
@@ -438,7 +431,26 @@ class FileCompareLink (FileLink):
         print 'reading', f
         s = open (f).read ()
         return s
+
+
+class GitFileCompareLink (FileCompareLink):
+    def get_cell (self, oldnew):
+        str = self.contents[oldnew]
+
+        # truncate long lines
+        str = '\n'.join ([l[:80] for l in str.split ('\n')])
+
+        
+        str = '<font size="-2"><pre>%s</pre></font>' % str
+        return str
     
+    def calc_distance (self):
+        if self.contents[0] == self.contents[1]:
+            d = 0.0
+        else:
+            d = 1.0001 *options.threshold
+
+        return d
         
 class TextFileCompareLink (FileCompareLink):
     def calc_distance (self):
@@ -452,7 +464,7 @@ class TextFileCompareLink (FileCompareLink):
         self.diff_lines =  [l for l in diff]
         self.diff_lines = self.diff_lines[2:]
         
-        return float (len (self.diff_lines))
+        return math.sqrt (float (len ([l for l in self.diff_lines if l[0] in '-+'])))
         
     def get_cell (self, oldnew):
         str = ''
@@ -461,21 +473,12 @@ class TextFileCompareLink (FileCompareLink):
         str = '<font size="-2"><pre>%s</pre></font>' % str
         return str
 
-    def extension (self):
-        return '.txt'
-    
-class LogFileCompareLink (TextFileCompareLink):
-    def extension (self):
-        return '.log'
-
+        
 class ProfileFileLink (FileCompareLink):
     def __init__ (self, f1, f2):
         FileCompareLink.__init__ (self, f1, f2)
         self.results = [{}, {}]
     
-    def extension (self):
-        return '.profile'
-
     def get_cell (self, oldnew):
         str = ''
         for k in ('time', 'cells'):
@@ -483,7 +486,7 @@ class ProfileFileLink (FileCompareLink):
                 str += '%-8s: %d\n' %  (k, int (self.results[oldnew][k]))
             else:
                 str += '%-8s: %8d (%5.3f)\n' % (k, int (self.results[oldnew][k]),
-                                         self.get_ratio (k))
+                                                self.get_ratio (k))
 
         return '<pre>%s</pre>' % str
             
@@ -505,40 +508,47 @@ class ProfileFileLink (FileCompareLink):
                     note_info, self.contents[oldnew])
 
         dist = 0.0
-        factor = {'time': 1.0 ,
-                  'cells': 10.0,
+        factor = {'time': 2.0 ,
+                  'cells': 5.0,
                   }
         
         for k in ('time', 'cells'):
-            dist += math.exp (self.get_ratio (k) * factor[k]) - 1
+            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)
         return dist
 
-class MidiFileLink (FileCompareLink):
-    def get_content (self, f):
-        s = FileCompareLink.get_content (self, f)
-        s = re.sub ('LilyPond [0-9.]+', '', s)
-        return s
     
-    def get_cell (self, oldnew):
+class MidiFileLink (TextFileCompareLink):
+    def get_content (self, oldnew):
+        import midi
+        
+        data = FileCompareLink.get_content (self, oldnew)
+        midi = midi.parse (data)
+        tracks = midi[1]
+
         str = ''
-        if oldnew == 1 and self.distance () > 0:
-            str = 'changed' 
+        j = 0
+        for t in tracks:
+            str += 'track %d' % j
+            j += 1
+
+            for e in t:
+                ev_str = repr (e)
+                if re.search ('LilyPond [0-9.]+', ev_str):
+                    continue
+                
+                str += '  ev %s\n' % `e`
         return str
-        
-    def extension (self):
-        return '.midi'
     
 
+
 class SignatureFileLink (FileLink):
     def __init__ (self, f1, f2 ):
         FileLink.__init__ (self, f1, f2)
         self.system_links = {}
 
-    def extension (self):
-        return '.ly'
-
     def add_system_link (self, link, number):
         self.system_links[number] = link
 
@@ -790,7 +800,7 @@ class ComparisonData:
                 self.compare_trees (d1, d2)
     
     def compare_directories (self, dir1, dir2):
-        for ext in ['signature', 'midi', 'log', 'profile']:
+        for ext in ['signature', 'midi', 'log', 'profile', 'gittxt']:
             (paired, m1, m2) = paired_files (dir1, dir2, '*.' + ext)
 
             self.missing += [(dir1, m) for m in m1] 
@@ -814,6 +824,7 @@ class ComparisonData:
                 '.midi': MidiFileLink,
                 '.log' : TextFileCompareLink,
                 '.profile': ProfileFileLink,
+                '.gittxt': GitFileCompareLink, 
                 }
             
             if klasses.has_key (ext):
@@ -840,13 +851,15 @@ class ComparisonData:
 
         file_link.add_file_compare (f1, f2)
 
-    def remove_changed (self, dir, threshold):
+    def write_changed (self, dest_dir, threshold):
         (changed, below, unchanged) = self.thresholded_results (threshold)
-        for link in changed:
-            try:
-                system ('rm -f %s*' % link.base_names[1])
-            except AttributeError: ### UGH.
-                system ('rm -f %s/%s*' % (dir, link.name ()))
+
+        str = '\n'.join ([os.path.splitext (link.file_names[1])[0]
+                        for link in changed])
+        fn = dest_dir + '/changed.txt'
+        
+        open_write_file (fn).write (str)
+                
     def thresholded_results (self, threshold):
         ## todo: support more scores.
         results = [(link.distance(), link)
@@ -917,7 +930,12 @@ class ComparisonData:
 
         dest_file = dest_dir + '/index.html'
         open_write_file (dest_file).write (html)
+
+
+        for link in changed:
+            link.link_files_for_html (dest_dir)
         
+
     def print_results (self, threshold):
         self.write_text_result_page ('', threshold)
 
@@ -926,13 +944,10 @@ def compare_trees (dir1, dir2, dest_dir, threshold):
     data.compare_trees (dir1, dir2)
     data.print_results (threshold)
 
-    if options.remove_changed:
-        data.remove_changed (dir2, threshold)
-        return
-    
     if os.path.isdir (dest_dir):
         system ('rm -rf %s '% dest_dir)
 
+    data.write_changed (dest_dir, threshold)
     data.create_html_result_page (dir1, dir2, dest_dir, threshold)
     data.create_text_result_page (dir1, dir2, dest_dir, threshold)
     
@@ -996,6 +1011,8 @@ def test_compare_trees ():
     system ('cp 19.sub{-*.signature,.ly,.png,.eps,.log,.profile} dir2/subdir/')
     system ('cp 20grob{-*.signature,.ly,.png,.eps,.log,.profile} dir2/')
     system ('cp 20grob{-*.signature,.ly,.png,.eps,.log,.profile} dir1/')
+    system ('echo HEAD is 1 > dir1/tree.gittxt')
+    system ('echo HEAD is 2 > dir2/tree.gittxt')
 
     ## introduce differences
     system ('cp 19-1.signature dir2/20-1.signature')
@@ -1014,7 +1031,7 @@ def test_compare_trees ():
     system ('cp 19multipage.log dir1/log-differ.log')
     system ('cp 19multipage.log dir2/log-differ.log &&  echo different >> dir2/log-differ.log &&  echo different >> dir2/log-differ.log')
 
-    compare_trees ('dir1', 'dir2', 'compare-dir1dir2', 0.5)
+    compare_trees ('dir1', 'dir2', 'compare-dir1dir2', options.threshold)
 
 
 def test_basic_compare ():
@@ -1169,13 +1186,6 @@ def main ():
                   type="float",
                   help='threshold for geometric distance')
 
-
-    p.add_option ('--remove-changed',
-                  dest="remove_changed",
-                  default=False,
-                  action="store_true",
-                  help="Remove all files from tree2 that are over the threshold.")
-
     p.add_option ('--no-compare-images',
                   dest="compare_images",
                   default=True,