7 * Add @nodes, split at sections?
17 program_name = 'lys-to-tely'
19 include_snippets = '@lysnippets'
20 fragment_options = 'printfilename,texidoc'
21 help_text = r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
22 Construct tely doc from LY-FILEs.
25 -h, --help print this help
26 -f, --fragment-options=OPTIONS use OPTIONS as lilypond-book fragment
28 -o, --output=NAME write tely doc to NAME
29 -t, --title=TITLE set tely doc title TITLE
30 -a, --author=AUTHOR set tely author AUTHOR
31 --template=TEMPLATE use TEMPLATE as Texinfo template file,
32 instead of standard template; TEMPLATE should contain a command
33 '%(include_snippets)s' to tell where to insert LY-FILEs. When this
34 option is used, NAME and TITLE are ignored.
38 sys.stdout.write ( text)
41 (options, files) = getopt.getopt (sys.argv[1:], 'f:hn:t:',
42 ['fragment-options=', 'help', 'name=', 'title=', 'author=', 'template='])
46 author = "Han-Wen Nienhuys and Jan Nieuwenhuizen"
47 template = '''\input texinfo
48 @setfilename %%(name)s.info
51 @documentencoding utf-8
56 @finalout @c we do not want black boxes.
70 ''' % include_snippets
75 if o == '-h' or o == '--help':
76 # We can't use vars () inside a function, as that only contains all
77 # local variables and none of the global variables! Thus we have to
78 # generate the help text here and pass it to the function...
79 help (help_text % vars ())
80 elif o == '-n' or o == '--name':
82 elif o == '-t' or o == '--title':
84 elif o == '-a' or o == '--author':
86 elif o == '-f' or o == '--fragment-options':
88 elif o == '--template':
89 template = open (a, 'r').read ()
91 raise Exception ('unknown option: ' + o)
93 texi_file_re = re.compile ('.*\.i?te(ly|xi)$')
94 html_file_re = re.compile ('.*\.i?htm(l)?$')
95 xml_file_re = re.compile ('.*\.i?xml$')
96 tex_file_re = re.compile ('.*\.i?(la)?tex$')
97 pdf_file_re = re.compile ('.*\.i?pdf$')
100 if texi_file_re.match (n):
101 # We have a texi include file, simply include it:
102 s = r"@include %s" % os.path.basename (n)
103 elif (html_file_re.match (n) or pdf_file_re.match (n) or
104 xml_file_re.match (n) or tex_file_re.match (n)):
112 """ % (os.path.basename (n), os.path.basename (n))
115 # Assume it's a lilypond file -> create image etc.
123 @lilypondfile[%s]{%s}
124 """ % (os.path.basename (n), fragment_options, n)
128 dir = os.path.dirname (name) or "."
129 # don't strip .tely extension, Documentation/snippets uses .itely
130 name = os.path.basename (name)
131 template = template % vars ()
133 s = "\n".join (map (name2line, files))
134 s = template.replace (include_snippets, s, 1)
135 f = "%s/%s" % (dir, name)
136 sys.stderr.write ("%s: writing %s..." % (program_name, f))
140 sys.stderr.write ('\n')
142 # not Unix philosophy, but hey, at least we notice when
143 # we don't distribute any .ly files.
144 sys.stderr.write ("No files specified. Doing nothing")