-################################################################
-# different systems of a .ly file.
-
-class FileLink:
- def __init__ (self):
- self.original_name = ''
- self.base_names = ('','')
- self.system_links = {}
- self._distance = None
-
- def add_system_link (self, link, number):
- self.system_links[number] = link
-
- def calc_distance (self):
- d = 0.0
-
- orphan_distance = 0.0
- for l in self.system_links.values ():
- d = max (d, l.geometric_distance ())
- orphan_distance += l.orphan_count ()
-
- return d + orphan_distance
-
- def distance (self):
- if type (self._distance) != type (0.0):
- return self.calc_distance ()
-
- return self._distance
-
- def text_record_string (self):
- return '%-30f %-20s\n' % (self.distance (),
- self.original_name)
-
- 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 = []
-
- 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)
-
- 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:
- self.original_name = os.path.split (base1)[1]
-
- ## 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)
-
- link = SystemLink (s1, s2)
-
- 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 oldnew in (0,1):
- link_file (self.base_names[oldnew] + ext,
- dest_dir + '/' + self.base_names[oldnew] + ext)
-
- 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 ()
-
-
- 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'
- html_2 = self.base_names[1] + '.html'
- name = self.original_name
-
- html_entry = '''
-<tr>
-<td>
-%f<br>
-(<a href="%s">details</a>)
-</td>
-
-%s
-%s
-</tr>
-''' % (self.distance (), html_2,
- 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
-
- e = '<td>%d</td>' % c
- for s in (link.output_expression_details_string (),
- link.orphan_details_string (),
- link.geo_details_string ()):
- e += "<td>%s</td>" % s
-
-
- 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, dir1, dir2, dest_dir):
- dest_file = os.path.join (dest_dir, self.base_names[1] + '.html')
-
- details = open_write_file (dest_file)
- details.write (self.html_system_details_string ())
-
-################################################################
-# Files/directories
-
-import glob
-import re
-
-
-