]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lys-to-tely.py
8069deaba8a8de86f1fae9a9e8ef0e8a08fc2cfb
[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 [OPTIONS]... 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 doc title TITLE
29
30 """)
31         sys.exit (0)
32
33 (options, files) = getopt.getopt(sys.argv[1:], 'hn:t:', [
34         'help', 'name=', 'title='])
35
36 name="ly-doc"
37 title="Ly Doc"
38 for opt in options:
39         o = opt[0]
40         a = opt[1]
41         if o == '-h' or o == '--help':
42                 help ()
43         elif o == '-n' or o == '--name':
44                 name = a
45         elif o == '-t' or o == '--title':
46                 title = a
47         else:
48                 raise 'unknown opt ', o
49
50 def strip_extension (f, ext):
51         (p, e) = os.path.splitext (f)
52         if e == ext:
53                 e = ''
54         return p + e
55
56 if files:
57         dir = os.path.dirname (name)
58         if not dir:
59                 dir = "."
60         name = strip_extension (os.path.basename (name), ".tely")
61
62         s = '''\input texinfo
63 @setfilename %s.info
64 @settitle %s
65 @finalout @c we do not want black boxes.
66
67 @iftex
68 @afourpaper
69 @end iftex
70   
71 @c fool ls-latex
72 @ignore
73 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
74 @title %s
75 @end ignore
76
77 @node Top, , , (dir)
78 ''' % (name, title, title)
79
80         def name2line (n):
81                 # UGR
82                 s = r"""
83 @ifhtml
84 @html
85 <A NAME="%s">
86 @end html
87 @end ifhtml
88 """ % n
89                 
90                 s += "\n\n@lilypondfile[printfilename]{%s}" % n
91                 return s
92         files.sort ()
93         s = s + string.join (map (lambda x: name2line (x), files), "\n")
94         s = s + '\n@bye\n'
95         f = "%s/%s.tely" % (dir, name)
96         sys.stderr.write ("%s: writing %s..." % (program_name, f))
97         h = open (f, "w")
98         h.write (s)
99         h.close ()
100         sys.stderr.write ('\n')
101 else:
102         # not Unix philosophy, but hey, at least we notice when
103         # we don't distribute any .ly files.
104         sys.stderr.write ("No files specified. Doing nothing")
105