]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lys-to-tely.py
(strip_extension): add utf-8
[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
66 @documentencoding utf-8
67 @iftex
68 @afourpaper
69 @end iftex
70
71 @finalout @c we do not want black boxes.
72   
73 @c fool ls-latex
74 @ignore
75 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
76 @title %s
77 @end ignore
78
79 @node Top, , , (dir)
80 ''' % (name, title, title)
81
82         def name2line (n):
83                 # UGR
84                 s = r"""
85 @ifhtml
86 @html
87 <A NAME="%s"></A>
88 @end html
89 @end ifhtml
90 """ % n
91                 
92                 s += "\n\n@lilypondfile[printfilename,texidoc]{%s}" % n
93                 return s
94         files.sort ()
95         s = s + string.join (map (lambda x: name2line (x), files), "\n")
96         s = s + '\n@bye\n'
97         f = "%s/%s.tely" % (dir, name)
98         sys.stderr.write ("%s: writing %s..." % (program_name, f))
99         h = open (f, "w")
100         h.write (s)
101         h.close ()
102         sys.stderr.write ('\n')
103 else:
104         # not Unix philosophy, but hey, at least we notice when
105         # we don't distribute any .ly files.
106         sys.stderr.write ("No files specified. Doing nothing")
107