lilypond-1.0.8
[lilypond.git] / bin / table-to-html.py
blobbc4bc7152a596772e4b8105cf3e7c8e6b61ab997
1 #!@PYTHON@
3 #
4 # table-to-html.py -- convert char-separated table to html table
5 #
6 # source file of the GNU LilyPond music typesetter
7 #
8 # (c) 1998 Jan Nieuwenhuizen <jan@digicash.com>
9 #
11 import getopt
12 from string import *
13 import regex
14 import regsub
15 import os
16 import sys
17 import time
19 version = '0.1'
21 lilypath =''
22 try:
23 lilypath = os.environ['LILYPOND_SOURCEDIR'] + '/'
24 except KeyError:
25 try:
26 lilypath = os.environ['top_srcdir'] + '/'
27 except KeyError:
28 print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
30 lilypath = lilypath + '/bin/'
31 sys.path.append (lilypath)
33 from flower import *
35 def program_id ():
36 return 'table-to-html.py version ' + version;
38 def identify ():
39 sys.stdout.write (program_id () + '\n')
41 def help ():
42 sys.stdout.write ("Usage: table-to-html [options] TABLE_FILE HTML_FILE\n"
43 + "Generate mozarella metrics table from preparated feta log\n\n"
44 + "Options:\n"
45 + " -h, --help print this help\n"
46 + " -s, --separator=SEP specify separator [:]\n")
47 sys.exit (0)
50 def header (html):
51 html.write ('<body><table cellspacing=10>')
53 def footer (html):
54 html.write ('</table></body>')
56 def convert (inname, outname, separator):
57 table = File (inname)
58 # ugh
59 html = File (outname, 'w')
61 header (html)
62 while not table.eof ():
63 line = table.readline ()
64 columns = split (line, separator)
65 html_line = '<tr><td>' + join (columns, '</td><td>') + '</td></tr>'
66 html.write (html_line)
67 table.close ()
68 footer (html)
69 html.close ()
72 def main ():
73 identify ()
74 (options, files) = getopt.getopt (
75 sys.argv[1:], 'hs:', ['help','separator='])
77 separator = ':'
78 for opt in options:
79 o = opt[0]
80 a = opt[1]
81 if o == '--separator' or o == '-s':
82 separator = a
83 elif o== '--help' or o == '-h':
84 help ()
85 else:
86 print o
87 raise getopt.error
89 convert (files[0], files[1], separator)
91 main ()