7 * Add @nodes, split at sections?
16 program_name
= 'lys-to-tely'
18 include_snippets
= '@lysnippets'
19 fragment_options
= 'printfilename,texidoc'
20 help_text
= r
"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
21 Construct tely doc from LY-FILEs.
24 -h, --help print this help
25 -f, --fragment-options=OPTIONS use OPTIONS as lilypond-book fragment
27 -o, --output=NAME write tely doc to NAME
28 -t, --title=TITLE set tely doc title TITLE
29 --template=TEMPLATE use TEMPLATE as Texinfo template file,
30 instead of standard template; TEMPLATE should contain a command
31 '%(include_snippets)s' to tell where to insert LY-FILEs. When this
32 option is used, NAME and TITLE are ignored.
36 sys
.stdout
.write ( text
)
39 (options
, files
) = getopt
.getopt (sys
.argv
[1:], 'f:hn:t:',
40 ['fragment-options=', 'help', 'name=', 'title=', 'template='])
44 template
= '''\input texinfo
45 @setfilename %%(name)s.info
48 @documentencoding utf-8
53 @finalout @c we do not want black boxes.
57 @author Han-Wen Nienhuys and Jan Nieuwenhuizen
67 ''' % include_snippets
72 if o
== '-h' or o
== '--help':
73 # We can't use vars () inside a function, as that only contains all
74 # local variables and none of the global variables! Thus we have to
75 # generate the help text here and pass it to the function...
76 help (help_text
% vars ())
77 elif o
== '-n' or o
== '--name':
79 elif o
== '-t' or o
== '--title':
81 elif o
== '-f' or o
== '--fragment-options':
83 elif o
== '--template':
84 template
= open (a
, 'r').read ()
86 raise Exception ('unknown option: ' + o
)
97 """ % (os
.path
.basename (n
), fragment_options
, n
)
101 dir = os
.path
.dirname (name
) or "."
102 # don't strip .tely extension, input/lsr uses .itely
103 name
= os
.path
.basename (name
)
104 template
= template
% vars ()
107 s
= "\n".join (map (name2line
, files
))
108 s
= template
.replace (include_snippets
, s
, 1)
109 f
= "%s/%s" % (dir, name
)
110 sys
.stderr
.write ("%s: writing %s..." % (program_name
, f
))
114 sys
.stderr
.write ('\n')
116 # not Unix philosophy, but hey, at least we notice when
117 # we don't distribute any .ly files.
118 sys
.stderr
.write ("No files specified. Doing nothing")