]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lys-to-tely.py
* input/regression/span-bar.ly: smaller file.
[lilypond.git] / buildscripts / lys-to-tely.py
1 #!@PYTHON@
2
3
4 '''
5 TODO:
6
7   * Add @nodes, plit at sections?
8   * Less kludged first introduction file
9   * include *.texi files for text at start of section?
10
11 '''
12
13
14 import sys
15 import os
16 import string 
17 import getopt
18
19 program_name = 'lys-to-tely'
20
21 def help ():
22         sys.stdout.write (r"""Usage: lys-to-tely [OPTION]... LY-FILE...
23 Construct tely doc from LY-FILEs.
24
25 Options:
26   -h, --help                print this help
27   -o,output=NAME            write tely doc to NAME
28   -t,title=TITLE            set tely tely doc title TITLE
29 """)
30         sys.exit (0)
31
32 (options, files) = getopt.getopt(sys.argv[1:], 'hn:t:', [
33         'help', 'name=', 'title='])
34
35 name="ly-doc"
36 title="Ly Doc"
37 for opt in options:
38         o = opt[0]
39         a = opt[1]
40         if o == '-h' or o == '--help':
41                 help ()
42         elif o == '-n' or o == '--name':
43                 name = a
44         elif o == '-t' or o == '--title':
45                 title = a
46         else:
47                 raise 'unknown opt ', o
48
49 def strip_extension (f, ext):
50         (p, e) = os.path.splitext (f)
51         if e == ext:
52                 e = ''
53         return p + e
54
55 if files:
56         dir = os.path.dirname (name)
57         if not dir:
58                 dir = "."
59         name = strip_extension (os.path.basename (name), ".tely")
60
61         s = '''\input texinfo
62 @setfilename %s.info
63 @settitle %s
64 @finalout @c we do not want black boxes.
65
66 @c fool ls-latex
67 @ignore
68 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
69 @title %s
70 @end ignore
71
72 @node Top, , , (dir)
73 ''' % (name, title, title)
74
75         def name2line (n):
76                 # UGR
77                 s = r"""
78 @ifhtml
79 @html
80 <A NAME="%s">
81 @end html
82 @end ifhtml
83 """ % n
84                 
85                 s += "@lilypondfile[printfilename]{%s}" % n
86                 return s
87         files.sort ()
88         s = s + string.join (map (lambda x: name2line (x), files), "\n")
89         s = s + '\n@bye\n'
90         f = "%s/%s.tely" % (dir, name)
91         sys.stderr.write ("%s: writing %s..." % (program_name, f))
92         h = open (f, "w")
93         h.write (s)
94         h.close ()
95         sys.stderr.write ('\n')
96 else:
97         # not Unix philosophy, but hey, at least we notice when
98         # we don't distribute any .ly files.
99         sys.stderr.write ("No files specified. Doing nothing")
100