]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lys-to-tely.py
release: 1.5.8
[lilypond.git] / buildscripts / lys-to-tely.py
1 #!@PYTHON@
2
3 import sys
4 import os
5 import string 
6 import getopt
7
8 program_name = 'lys-to-tely'
9
10 def help ():
11         sys.stdout.write (r"""Usage: lys-to-tely [OPTION]... LY-FILE...
12 Construct tely doc from LY-FILEs.
13
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)
20
21 (options, files) = getopt.getopt(sys.argv[1:], 'hn:t:', [
22         'help', 'name=', 'title='])
23
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
37
38 def strip_extension (f, ext):
39         (p, e) = os.path.splitext (f)
40         if e == ext:
41                 e = ''
42         return p + e
43
44 if files:
45         dir = os.path.dirname (name)
46         if not dir:
47                 dir = "."
48         name = strip_extension (os.path.basename (name), ".tely")
49
50         s = '''\input texinfo
51 @setfilename %s.info
52 @settitle %s
53
54 @c fool ls-latex
55 @ignore
56 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
57 @title %s
58 @end ignore
59
60 @node Top, , , (dir)
61 ''' % (name, title, title)
62
63         def name2line (n):
64                 # UGR
65                 if string.find (n, '+') >= 0:
66                         s = "@lilypondfile{%s}" % n
67                 else:
68                         s = "@lilypondfile[printfilename,verbatim]{%s}" % n
69                 return s
70
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')
79 else:
80         # not Unix philosophy, but hey, at least we notice when
81         # we don't distribute any .ly files.
82         sys.stderr.write ("No files specified. Doing nothing")
83