]> git.donarmstrong.com Git - lilypond.git/blob - bin/table-to-html.py
release: 0.1.64
[lilypond.git] / bin / table-to-html.py
1 #!@PYTHON@
2
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
10
11 import getopt
12 from string import *
13 import regex
14 import regsub
15 import os
16 import sys
17 import time
18
19 version = '0.1'
20
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/'
29
30 lilypath = lilypath + '/bin/'
31 sys.path.append (lilypath)
32  
33 from flower import *
34
35 def program_id ():
36     return 'table-to-html.py version ' + version;
37
38 def identify ():
39     sys.stdout.write (program_id () + '\n')
40     
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)
48
49
50 def header (html):
51     html.write ('<body><table cellspacing=10>')
52
53 def footer (html):
54     html.write ('</table></body>')
55
56 def convert (inname, outname, separator):
57     table = File (inname)
58     # ugh
59     html = File (outname, 'w')
60
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 ()
70
71
72 def main ():
73     identify ()
74     (options, files) = getopt.getopt (
75         sys.argv[1:], 'hs:', ['help','separator='])
76
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
88
89     convert (files[0], files[1], separator)
90
91 main ()
92