]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lys-to-tely.py
Deeply revise input/lsr structure, generation and compilation
[lilypond.git] / buildscripts / lys-to-tely.py
1 #!@PYTHON@
2
3
4 '''
5 TODO:
6
7  * Add @nodes, split at sections?
8
9 '''
10
11
12 import sys
13 import os
14 import getopt
15
16 program_name = 'lys-to-tely'
17 include_snippets = '@lysnippets'
18
19 def help ():
20     sys.stdout.write (r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
21 Construct tely doc from LY-FILEs.
22
23 Options:
24  -h, --help                print this help
25  -o, --output=NAME         write tely doc to NAME
26  -t, --title=TITLE         set tely doc title TITLE
27      --template=TEMPLATE   use TEMPLATE as Texinfo template file,
28    instead of standard template; TEMPLATE should contain a command
29    '%(include_snippets)s' to tell where to insert LY-FILEs.  When this option
30    is used, NAME and TITLE are ignored
31 """ % vars ())
32     sys.exit (0)
33
34 (options, files) = getopt.getopt (sys.argv[1:], 'hn:t:',
35                      ['help', 'name=', 'title=', 'template='])
36
37 name = "ly-doc"
38 title = "Ly Doc"
39 template = '''\input texinfo
40 @setfilename %%(name)s.info
41 @settitle %%(name)s
42
43 @documentencoding utf-8
44 @iftex
45 @afourpaper
46 @end iftex
47
48 @finalout @c we do not want black boxes.
49
50 @c fool ls-latex
51 @ignore
52 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
53 @title %%(title)s
54 @end ignore
55
56 @node Top, , , (dir)
57
58 %s
59
60 @bye
61 ''' % include_snippets
62
63 for opt in options:
64     o = opt[0]
65     a = opt[1]
66     if o == '-h' or o == '--help':
67         help ()
68     elif o == '-n' or o == '--name':
69         name = a
70     elif o == '-t' or o == '--title':
71         title = a
72     elif o == '--template':
73         template = open (a, 'r').read ()
74     else:
75         raise 'unknown opt ', o
76
77 def name2line (n):
78     # UGR
79     s = r"""
80 @ifhtml
81 @html
82 <A NAME="%s"></A>
83 @end html
84 @end ifhtml
85
86 @lilypondfile[printfilename,texidoc]{%s}""" % (n, n)
87     return s
88
89 if files:
90     dir = os.path.dirname (name) or "."
91 # don't strip .tely extension, input/lsr uses .itely
92     name = os.path.basename (name)
93     template = template % vars ()
94
95     files.sort ()
96     s = "\n".join (map (name2line, files))
97     s = template.replace (include_snippets, s, 1)
98     f = "%s/%s" % (dir, name)
99     sys.stderr.write ("%s: writing %s..." % (program_name, f))
100     h = open (f, "w")
101     h.write (s)
102     h.close ()
103     sys.stderr.write ('\n')
104 else:
105     # not Unix philosophy, but hey, at least we notice when
106     # we don't distribute any .ly files.
107     sys.stderr.write ("No files specified. Doing nothing")