7 * Add @nodes, split at sections?
9 * -o --output listed in help is not implemented?!
19 program_name = 'lys-to-tely'
21 include_snippets = '@lysnippets'
22 fragment_options = 'printfilename,texidoc'
23 help_text = r"""Usage: %(program_name)s [OPTIONS]... LY-FILE...
24 Construct tely doc from LY-FILEs.
27 -h, --help print this help
28 -f, --fragment-options=OPTIONS use OPTIONS as lilypond-book fragment
30 -o, --output=NAME write tely doc to NAME
31 -i, --input-filenames=NAME read list of files from a file instead of stdin
32 -g, --glob-input=GLOB a string which will be passed to glob.glob(GLOB)
33 -t, --title=TITLE set tely doc title TITLE
34 -a, --author=AUTHOR set tely author AUTHOR
35 --template=TEMPLATE use TEMPLATE as Texinfo template file,
36 instead of standard template; TEMPLATE should contain a command
37 '%(include_snippets)s' to tell where to insert LY-FILEs. When this
38 option is used, NAME and TITLE are ignored.
42 sys.stdout.write ( text)
45 (options, files) = getopt.getopt (sys.argv[1:], 'f:hn:t:',
46 ['fragment-options=', 'help', 'name=',
47 'title=', 'author=', 'template=',
48 'input-filenames=', 'glob-input='])
52 author = "Han-Wen Nienhuys and Jan Nieuwenhuizen"
55 template = '''\input texinfo
56 @setfilename %%(name)s.info
59 @documentencoding utf-8
64 @finalout @c we do not want black boxes.
78 ''' % include_snippets
83 if o == '-h' or o == '--help':
84 # We can't use vars () inside a function, as that only contains all
85 # local variables and none of the global variables! Thus we have to
86 # generate the help text here and pass it to the function...
87 help (help_text % vars ())
88 elif o == '-n' or o == '--name':
90 elif o == '-t' or o == '--title':
92 elif o == '-a' or o == '--author':
94 elif o == '-i' or o == '--input-filenames':
96 elif o == '-p' or o == '--glob-input':
98 elif o == '-f' or o == '--fragment-options':
100 elif o == '--template':
101 template = open (a, 'r').read ()
103 raise Exception ('unknown option: ' + o)
105 texi_file_re = re.compile ('.*\.i?te(ly|xi)$')
106 html_file_re = re.compile ('.*\.i?htm(l)?$')
107 xml_file_re = re.compile ('.*\.i?(xm|mx)l$')
108 tex_file_re = re.compile ('.*\.i?(la)?tex$')
109 pdf_file_re = re.compile ('.*\.i?pdf$')
112 if texi_file_re.match (n):
113 # We have a texi include file, simply include it:
114 s = r"@include %s" % os.path.basename (n)
115 elif (html_file_re.match (n) or pdf_file_re.match (n) or
116 tex_file_re.match (n)):
124 """ % (os.path.basename (n), os.path.basename (n))
126 elif (xml_file_re.match (n)):
127 # Assume it's a MusicXML file -> convert, create image etc.
135 @musicxmlfile[%s]{%s}
136 """ % (os.path.basename (n), fragment_options, n)
139 # Assume it's a lilypond file -> create image etc.
147 @lilypondfile[%s]{%s}
148 """ % (os.path.basename (n), fragment_options, n)
152 files = glob.glob(glob_input)
154 files = open(input_filename).read().split()
157 dir = os.path.dirname (name) or "."
158 # don't strip .tely extension, Documentation/snippets uses .itely
159 name = os.path.basename (name)
160 template = template % vars ()
162 s = "\n".join (map (name2line, files))
163 s = template.replace (include_snippets, s, 1)
164 f = "%s/%s" % (dir, name)
165 sys.stderr.write ("%s: writing %s..." % (program_name, f))
169 sys.stderr.write ('\n')
171 # not Unix philosophy, but hey, at least we notice when
172 # we don't distribute any .ly files.
173 sys.stderr.write ("No files specified. Doing nothing")