+ def text_record_string (self):
+ return '%-30f %-20s\n' % (self.distance (),
+ self.name ()
+ + os.path.splitext (self.file_names[1])[1]
+ )
+
+ def calc_distance (self):
+ return 0.0
+
+ def distance (self):
+ if self._distance == None:
+ self._distance = self.calc_distance ()
+
+ 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
+
+ def extension (self):
+ return os.path.splitext (self.file_names[1])[1]
+
+ def link_files_for_html (self, dest_dir):
+ for f in self.file_names:
+ link_file (f, os.path.join (dest_dir, f))
+
+ def get_distance_details (self):
+ return ''
+
+ def get_cell (self, oldnew):
+ return ''
+
+ def get_file (self, oldnew):
+ return self.file_names[oldnew]
+
+ def html_record_string (self, dest_dir):
+ dist = self.distance()
+
+ details = self.get_distance_details ()
+ if details:
+ details_base = os.path.splitext (self.file_names[1])[0]
+ details_base += '.details.html'
+ fn = dest_dir + '/' + details_base
+ open_write_file (fn).write (details)
+
+ details = '<br>(<a href="%(details_base)s">details</a>)' % locals ()
+
+ cell1 = self.get_cell (0)
+ cell2 = self.get_cell (1)
+
+ name = self.name () + self.extension ()
+ file1 = self.get_file (0)
+ file2 = self.get_file (1)
+
+ return '''<tr>
+<td>
+%(dist)f
+%(details)s
+</td>
+<td>%(cell1)s<br><font size=-2><a href="%(file1)s"><tt>%(name)s</tt></font></td>
+<td>%(cell2)s<br><font size=-2><a href="%(file2)s"><tt>%(name)s</tt></font></td>
+</tr>''' % locals ()
+
+
+class FileCompareLink (FileLink):
+ def __init__ (self, f1, f2):
+ FileLink.__init__ (self, f1, f2)
+ self.contents = (self.get_content (self.file_names[0]),
+ self.get_content (self.file_names[1]))
+
+
+ def calc_distance (self):
+ ## todo: could use import MIDI to pinpoint
+ ## what & where changed.
+
+ if self.contents[0] == self.contents[1]:
+ return 0.0
+ else:
+ return 100.0;
+
+ def get_content (self, f):
+ 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):
+ import difflib
+ diff = difflib.unified_diff (self.contents[0].strip().split ('\n'),
+ self.contents[1].strip().split ('\n'),
+ fromfiledate = self.file_names[0],
+ tofiledate = self.file_names[1]
+ )
+
+ self.diff_lines = [l for l in diff]
+ self.diff_lines = self.diff_lines[2:]
+
+ return math.sqrt (float (len ([l for l in self.diff_lines if l[0] in '-+'])))
+
+ def get_cell (self, oldnew):
+ str = ''
+ if oldnew == 1:
+ str = '\n'.join ([d.replace ('\n','') for d in self.diff_lines])
+ str = '<font size="-2"><pre>%s</pre></font>' % str
+ return str
+
+class LogFileCompareLink (TextFileCompareLink):
+ def get_content (self, f):
+ c = TextFileCompareLink.get_content (self, f)
+ c = re.sub ("\nProcessing `[^\n]+'\n", '', c)
+ return c
+
+class ProfileFileLink (FileCompareLink):
+ def __init__ (self, f1, f2):
+ FileCompareLink.__init__ (self, f1, f2)
+ self.results = [{}, {}]
+
+ def get_cell (self, oldnew):
+ str = ''
+ for k in ('time', 'cells'):
+ if oldnew==0:
+ 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))
+
+ return '<pre>%s</pre>' % str
+
+ def get_ratio (self, key):
+ (v1,v2) = (self.results[0].get (key, -1),
+ self.results[1].get (key, -1))
+
+ if v1 <= 0 or v2 <= 0:
+ return 0.0
+
+ return (v1 - v2) / float (v1+v2)
+
+ def calc_distance (self):
+ for oldnew in (0,1):
+ def note_info (m):
+ self.results[oldnew][m.group(1)] = float (m.group (2))
+
+ re.sub ('([a-z]+): ([-0-9.]+)\n',
+ note_info, self.contents[oldnew])
+
+ dist = 0.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)
+ dist += math.exp (math.fabs (real_val) * factor[k]) - 1
+
+ dist = min (dist, 100)
+ return dist
+
+
+class MidiFileLink (TextFileCompareLink):
+ def get_content (self, oldnew):
+ import midi
+
+ data = FileCompareLink.get_content (self, oldnew)
+ midi = midi.parse (data)
+ tracks = midi[1]
+
+ str = ''
+ 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
+
+
+
+class SignatureFileLink (FileLink):
+ def __init__ (self, f1, f2 ):
+ FileLink.__init__ (self, f1, f2)
+ self.system_links = {}
+