lilypond-1.5.6
[lilypond.git] / buildscripts / lys-to-tely.py
blobeac92934e8fb8eccadad1d52b5f600df188c880b
1 #!@PYTHON@
3 import sys
4 import os
5 import string
6 import getopt
8 program_name = 'lys-to-tely'
10 def help ():
11 sys.stdout.write (r"""Usage: lys-to-tely [OPTION]... LY-FILE...
12 Construct tely doc from LY-FILEs.
14 Options:
15 -h, --help print this help
16 -o,output=NAME write tely doc to NAME
17 -t,title=TITLE set tely tely doc title TITLE
18 """)
19 sys.exit (0)
21 (options, files) = getopt.getopt(sys.argv[1:], 'hn:t:', [
22 'help', 'name=', 'title='])
24 name="ly-doc"
25 title="Ly Doc"
26 for opt in options:
27 o = opt[0]
28 a = opt[1]
29 if o == '-h' or o == '--help':
30 help ()
31 elif o == '-n' or o == '--name':
32 name = a
33 elif o == '-t' or o == '--title':
34 title = a
35 else:
36 raise 'unknown opt ', o
38 def strip_extension (f, ext):
39 (p, e) = os.path.splitext (f)
40 if e == ext:
41 e = ''
42 return p + e
44 if files:
45 dir = os.path.dirname (name)
46 if not dir:
47 dir = "."
48 name = strip_extension (os.path.basename (name), ".tely")
50 s = '''\input texinfo
51 @setfilename %s.info
52 @settitle %s
54 @c fool ls-latex
55 @ignore
56 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
57 @title %s
58 @end ignore
60 @node Top, , , (dir)
61 ''' % (name, title, title)
63 def name2line (n):
64 # UGR
65 if string.find (n, '+') >= 0:
66 s = "@lilypondfile{%s}" % n
67 else:
68 s = "@lilypondfile[printfilename]{%s}" % n
69 return s
71 s = s + string.join (map (lambda x: name2line (x), files), "\n")
72 s = s + '\n@bye\n'
73 f = "%s/%s.tely" % (dir, name)
74 sys.stderr.write ("%s: writing %s..." % (program_name, f))
75 h = open (f, "w")
76 h.write (s)
77 h.close ()
78 sys.stderr.write ('\n')