'''
-import commands
import md5
import os
import re
action='store', dest='output_dir',
default='')
+ p.add_option ('--no-lily-run',
+ help=_ ("do not fail if no lilypond output is found."),
+ metavar=_ ("DIR"),
+ action='store_true', dest='skip_lilypond_run',
+ default=False)
+
p.add_option ('--lily-output-dir',
help=_ ("write lily-XXX files to DIR, link into --output dir."),
metavar=_ ("DIR"),
FRAGMENT = 'fragment'
HTML = 'html'
INDENT = 'indent'
+LANG = 'lang'
LATEX = 'latex'
LAYOUT = 'layout'
LINE_WIDTH = 'line-width'
NOINDENT,
PRINTFILENAME,
TEXIDOC,
+ LANG,
VERBATIM,
FONTLOAD,
FILENAME,
re.sub ('&', '&', s)))
+texinfo_lang_re = re.compile ('(?m)^@documentlanguage (.*?)( |$)')
def set_default_options (source, default_ly_options, format):
if LINE_WIDTH not in default_ly_options:
if format == LATEX:
textwidth = get_latex_textwidth (source)
default_ly_options[LINE_WIDTH] = '%.0f\\pt' % textwidth
elif format == TEXINFO:
+ m = texinfo_lang_re.search (source)
+ if m and not m.group (1).startswith ('en'):
+ default_ly_options[LANG] = m.group (1)
+ else:
+ default_ly_options[LANG] = ''
for regex in texinfo_line_widths:
# FIXME: @layout is usually not in
# chunk #0:
def filter_text (self):
return self.replacement_text ()
- def ly_is_outdated (self):
- return False
-
- def png_is_outdated (self):
- return False
-
def is_plain (self):
return False
if c_key:
if c_value:
warning (
- _ ("deprecated ly-option used: %s=%s"
- % (key, value)))
+ _ ("deprecated ly-option used: %s=%s") % (key, value))
warning (
- _ ("compatibility mode translation: %s=%s"
- % (c_key, c_value)))
+ _ ("compatibility mode translation: %s=%s") % (c_key, c_value))
else:
warning (
- _ ("deprecated ly-option used: %s"
- % key))
+ _ ("deprecated ly-option used: %s") % key)
warning (
- _ ("compatibility mode translation: %s"
- % c_key))
+ _ ("compatibility mode translation: %s") % c_key)
(key, value) = (c_key, c_value)
# TODO: use xx/xxxxx directory layout.
name = 'lily-%s' % cs[:10]
- if global_options.lily_output_dir:
- name = os.path.join (global_options.lily_output_dir, name)
return name
def write_ly (self):
- out = file (self.basename () + '.ly', 'w')
+ base = self.basename ()
+ path = os.path.join (global_options.lily_output_dir, base)
+
+ out = file (path + '.ly', 'w')
out.write (self.full_ly ())
- file (self.basename () + '.txt', 'w').write ('image of music')
+ file (path + '.txt', 'w').write ('image of music')
def relevant_contents (self, ly):
return re.sub (r'\\(version|sourcefileline|sourcefilename)[^\n]*\n', '', ly)
def link_all_output_files (self, output_dir, output_dir_files, destination):
- existing = self.all_output_files (output_dir_files)
+ existing = self.all_output_files (output_dir, output_dir_files)
+ if existing is None:
+ print '\nMissing', self.basename()
+ raise CompileError(self.basename())
for name in existing:
try:
os.unlink (os.path.join (destination, name))
os.link (src, dst)
- def all_output_files (self, output_dir_files):
+ def all_output_files (self, output_dir, output_dir_files):
"""Return all files generated in lily_output_dir, a set.
output_dir_files is the list of files in the output directory.
pass
result = set()
- base = os.path.basename(self.basename())
+ base = self.basename()
+ full = os.path.join (output_dir, base)
def consider_file (name):
if name in output_dir_files:
result.add (name)
raise Missing
result.add (name)
+ skip_lily = global_options.skip_lilypond_run
try:
for required in [base + '.ly',
- base + '.txt',
- base + '-systems.count']:
+ base + '.txt']:
require_file (required)
-
+ if not skip_lily:
+ require_file (base + '-systems.count')
+
map (consider_file, [base + '.tex',
base + '.eps',
+ base + '.texidoc',
base + '-systems.texi',
base + '-systems.tex',
base + '-systems.pdftexi'])
if base + '.eps' in result and self.format in (HTML, TEXINFO):
- page_count = ps_page_count (self.basename() + '.eps')
+ page_count = ps_page_count (full + '.eps')
if page_count <= 1:
require_file (base + '.png')
else:
for page in range (1, page_count + 1):
require_file (base + '-page%d.png' % page)
-
- system_count = int(file (self.basename () + '-systems.count').read())
+
+ system_count = 0
+ if not skip_lily:
+ system_count = int(file (full + '-systems.count').read())
for number in range(1, system_count + 1):
systemfile = '%s-%d' % (base, number)
require_file (systemfile + '.eps')
return result
- def is_outdated (self, current_files):
- return self.all_output_files (current_files) is None
+ def is_outdated (self, output_dir, current_files):
+ return self.all_output_files (output_dir, current_files) is None
def filter_text (self):
"""Run snippet bodies through a command (say: convert-ly).
base = self.basename ()
if TEXIDOC in self.option_dict:
texidoc = base + '.texidoc'
- if os.path.exists (texidoc):
+ translated_texidoc = texidoc + default_ly_options[LANG]
+ if os.path.exists (translated_texidoc):
+ str += '@include %(translated_texidoc)s\n\n' % vars ()
+ elif os.path.exists (texidoc):
str += '@include %(texidoc)s\n\n' % vars ()
substr = ''
def find_toplevel_snippets (input_string, format, types):
res = {}
for t in types:
- res[t] = ly.re.compile (snippet_res[format][t])
+ res[t] = re.compile (snippet_res[format][t])
snippets = []
index = 0
output_files = set(os.listdir(options.lily_output_dir))
- outdated = [c for c in snippets if c.is_outdated (output_files)]
+ outdated = [c for c in snippets if c.is_outdated (options.lily_output_dir, output_files)]
write_file_map (outdated, input_name)
progress (_ ("Writing snippets..."))
return do_file (name)
include_chunks = map (process_include,
- filter (lambda x: isinstance (x, IncludeSnippet),
- chunks))
+ filter (lambda x: isinstance (x, IncludeSnippet),
+ chunks))
return chunks + reduce (lambda x, y: x + y, include_chunks, [])