+ def add_file_compare (self, f1, f2):
+ system_index = []
+
+ def note_system_index (m):
+ system_index.append (int (m.group (1)))
+ return ''
+
+ base1 = re.sub ("-([0-9]+).signature", note_system_index, f1)
+ base2 = re.sub ("-([0-9]+).signature", note_system_index, f2)
+# name = os.path.split (base1)[1]
+
+ self.base_names = (os.path.normpath (base1),
+ os.path.normpath (base2))
+
+ def note_original (match):
+ self.original_name = match.group (1)
+ return ''
+
+ if not self.original_name:
+
+ ## ugh: can't we 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)
+
+ link = SystemLink (s1, s2)
+
+ self.add_system_link (link, system_index[0])
+
+ def link_files_for_html (self, old_dir, new_dir):
+
+ ## todo should create new_dir/old_suffix/HIER/ARCHY/old-file
+
+ old_suffix = os.path.split (old_dir)[1]
+ old_dest_dir = os.path.join (new_dir, old_suffix)
+ name = os.path.split (self.base_names[0])[1]
+ os.link (self.base_names[0] + '.png',
+ old_dest_dir + '/' + name + '.png')
+ if self.source_file ():
+ os.link (self.source_file (),
+ old_dest_dir + "/" + name + '.ly')
+
+ def html_record_string (self, old_dir, new_dir):
+ def img_cell (ly, img, name):
+ if not name:
+ name = 'source'
+ else:
+ name = '<tt>%s</tt>' % name
+
+ return '''
+<td align="center">
+<a href="%(img)s">
+<img src="%(img)s" style="border-style: none; max-width: 500px;">
+</a><br>
+<font size="-2">(<a href="%(ly)s">%(name)s</a>)
+</font>
+</td>
+''' % locals ()
+
+
+ old_suffix = os.path.split (old_dir)[1]
+ old_name = os.path.split (self.base_names[0])[1]
+
+ img_1 = os.path.join (old_suffix, old_name + '.png')
+ ly_1 = os.path.join (old_suffix, old_name + '.ly')
+ name = self.original_name
+
+ base_2 = self.base_names[1].replace (new_dir, '')
+ base_2 = re.sub ("^/*", '', base_2)
+ img_2 = base_2 + '.png'
+
+
+ ly_2 = img_2.replace ('.png','.ly')
+
+ html_entry = '''
+<tr>
+<td>
+%f<br>
+(<a href="%s">details</a>)
+</td>
+
+%s
+%s
+</tr>
+''' % (self.distance (), base_2 + '.html', img_cell (ly_1, img_1, name), img_cell (ly_2, img_2, name))
+
+
+ return html_entry
+
+
+ def html_system_details_string (self):
+ systems = self.system_links.items ()
+ systems.sort ()
+
+ html = ""
+ for (c, link) in systems:
+ e = '<td>%d</td>' % c
+ for d in link.distance ():
+ e += '<td>%f</td>' % d
+
+ e = '<tr>%s</tr>' % e
+ html += e
+
+ original = self.original_name
+ html = '''<html>
+<head>
+<title>comparison details for %(original)s</title>
+</head>
+<body>
+<table border=1>
+<tr>
+<th>system</th>
+<th>output</th>
+<th>orphan</th>
+<th>geo</th>
+</tr>
+
+%(html)s
+</table>
+
+</body>
+</html>
+''' % locals ()
+ return html
+
+ def write_html_system_details (self, dir2):
+ details = open (os.path.join (dir2, os.path.split (self.base_names[1])[1]) + '.html', 'w')
+ details.write (self.html_system_details_string ())
+