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