]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lys-to-tely.py
Allow header/footer snippets in test cases, expand lilypond-book to insert versionnumber
[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
10 '''
11
12
13 import sys
14 import os
15 import string 
16 import getopt
17
18 program_name = 'lys-to-tely'
19
20 def help ():
21     sys.stdout.write (r"""Usage: lys-to-tely [OPTIONS]... LY-FILE...
22 Construct tely doc from LY-FILEs.
23
24 Options:
25  -h, --help                print this help
26  -n, --name=NAME         write tely doc to NAME
27  -t, --title=TITLE         set tely doc title TITLE
28  -i, --introduction=FILE   use FILE as intruduction at the top
29  -f, --footer=FILE         use FILE as footer on the bottom of the page
30
31 """)
32     sys.exit (0)
33
34 (options, files) = getopt.getopt(sys.argv[1:], 'hn:t:i:f:', [
35     'help', 'name=', 'title=', 'introduction=', 'footer='])
36
37 name="ly-doc"
38 title="Ly Doc"
39 header = None
40 footer = None
41 for opt in options:
42     o = opt[0]
43     a = opt[1]
44     if o == '-h' or o == '--help':
45         help ()
46     elif o == '-n' or o == '--name':
47         name = a
48     elif o == '-t' or o == '--title':
49         title = a
50     elif o == '-i' or o == '--introduction':
51         header = a
52     elif o == '-f' or o == '--footer':
53         footer = a
54     else:
55         raise 'unknown opt ', o
56
57 def strip_extension (f, ext):
58     (p, e) = os.path.splitext (f)
59     if e == ext:
60         e = ''
61     return p + e
62
63 if files:
64     dir = os.path.dirname (name)
65     if not dir:
66         dir = "."
67     name = strip_extension (os.path.basename (name), ".tely")
68
69     s = '''\input texinfo
70 @setfilename %s.info
71 @settitle %s
72
73 @documentencoding utf-8
74 @iftex
75 @afourpaper
76 @end iftex
77
78 @finalout @c we do not want black boxes.
79  
80 @c fool ls-latex
81 @ignore
82 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
83 @title %s
84 @end ignore
85
86 @node Top, , , (dir)
87 ''' % (name, title, title)
88
89     if header:
90         header_text = open (header).read ()
91         s += header_text
92
93
94     def name2line (n):
95         # UGR
96         s = r"""
97 @ifhtml
98 @html
99 <A NAME="%s"></A>
100 @end html
101 @end ifhtml
102 """ % n
103         
104         s += "\n\n@lilypondfile[printfilename,texidoc]{%s}" % n
105         return s
106     files.sort ()
107     s = s + string.join (map (lambda x: name2line (x), files), "\n")
108     s += '\n'
109     if footer:
110         footer_text = open (footer).read ()
111         s += footer_text
112         s += '\n'
113     s = s + '@bye\n'
114     f = "%s/%s.tely" % (dir, name)
115     sys.stderr.write ("%s: writing %s..." % (program_name, f))
116     h = open (f, "w")
117     h.write (s)
118     h.close ()
119     sys.stderr.write ('\n')
120 else:
121     # not Unix philosophy, but hey, at least we notice when
122     # we don't distribute any .ly files.
123     sys.stderr.write ("No files specified. Doing nothing")
124