'''
-import commands
import md5
import os
import re
action='store', dest='output_dir',
default='')
+ p.add_option ('--skip-lily-check',
+ help=_ ("do not fail if no lilypond output is found."),
+ metavar=_ ("DIR"),
+ action='store_true', dest='skip_lilypond_run',
+ default=False)
+
+ p.add_option ('--skip-png-check',
+ help=_ ("do not fail if no PNG images are found for EPS files"),
+ metavar=_ ("DIR"),
+ action='store_true', dest='skip_png_check',
+ 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
return self.compose_ly (s)
return ''
- @staticmethod
- def split_options (option_string):
+ def split_options (self, option_string):
if option_string:
if self.format == HTML:
options = re.findall('[\w\.-:]+(?:\s*=\s*(?:"[^"]*"|\'[^\']*\'|\S+))?',
def do_options (self, option_string, type):
self.option_dict = {}
- options = split_options (option_string)
+ options = self.split_options (option_string)
for option in options:
if '=' in option:
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, missing = self.all_output_files (output_dir, output_dir_files)
+ if missing:
+ print '\nMissing', missing
+ 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):
- """Return all files generated in lily_output_dir.
+ 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.
"""
- base = os.path.basename(self.basename())
- result = set()
- for required in [base + '.ly',
- base + '.txt']:
- result.add (required)
-
+ result = set ()
+ missing = set ()
+ base = self.basename()
+ full = os.path.join (output_dir, base)
def consider_file (name):
if name in output_dir_files:
result.add (name)
+
+ def require_file (name):
+ if name in output_dir_files:
+ result.add (name)
+ else:
+ missing.add (name)
+
+ # UGH - junk global_options
+ skip_lily = global_options.skip_lilypond_run
+ for required in [base + '.ly',
+ base + '.txt']:
+ require_file (required)
+ if not skip_lily:
+ require_file (base + '-systems.count')
map (consider_file, [base + '.tex',
base + '.eps',
- base + '-systems.count',
+ base + '.texidoc',
base + '-systems.texi',
base + '-systems.tex',
base + '-systems.pdftexi'])
- if base + '.eps' in result:
- page_count = ps_page_count (self.basename() + '.eps')
+ # UGH - junk global_options
+ if (base + '.eps' in result and self.format in (HTML, TEXINFO)
+ and not global_options.skip_png_check):
+ page_count = ps_page_count (full + '.eps')
if page_count <= 1:
- consider_file (base + '.png')
+ require_file (base + '.png')
else:
for page in range (1, page_count + 1):
- consider_file (base + '-page%d.png' % page)
-
- if (base + '-systems.count') in result:
- system_count = int(file (self.basename () + '-systems.count').read())
- for number in range(1, system_count + 1):
- systemfile = '%s-%d' % (base, number)
- consider_file (systemfile + '.eps')
- consider_file (systemfile + '.pdf')
+ require_file (base + '-page%d.png' % page)
+
+ system_count = 0
+ if not skip_lily and not missing:
+ 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')
+ consider_file (systemfile + '.pdf')
- return result
-
- def ly_is_outdated (self):
- base = self.basename ()
- ly_file = find_file (base + '.ly', raise_error=False)
- tex_file = find_file (base + '.tex', raise_error=False)
- systems_file = find_file (base + '-systems.tex', raise_error=False)
-
- if (not os.path.exists (ly_file)
- or not os.path.exists (systems_file)):
- return True
-
- lines = file (systems_file).readlines ()
- if not lines:
- return True
-
- if not re.match ('% eof', lines[-1]):
- return true
-
- return False
-
- def png_is_outdated (self):
- base = self.basename ()
- eps_file = find_file (base + '.eps', raise_error=False)
- png_file = find_file (base + '.png', raise_error=False)
- if self.ly_is_outdated ():
- return True
-
- if (self.format in (HTML, TEXINFO)
- and os.path.exists (eps_file)):
- page_count = ps_page_count (eps_file)
- if page_count <= 1:
- return not os.path.exists (png_file)
- else:
- for page in range (1, page_count + 1):
- if not find_file (base + '-page%d.png' % page,
- raise_error=False):
- return True
-
- return False
+ return (result, missing)
+
+ def is_outdated (self, output_dir, current_files):
+ found, missing = self.all_output_files (output_dir, current_files)
+ return missing
def filter_text (self):
"""Run snippet bodies through a command (say: convert-ly).
This functionality is rarely used, and this code must have bitrot.
"""
-
code = self.substring ('code')
s = filter_pipe (code, global_options.filter_cmd)
d = {
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
endex = found[first][0]
if not first:
- snippets.append (Substring (input_string, index, len (s), line_start_idx))
+ snippets.append (Substring (input_string, index, len (input_string), line_start_idx))
break
while (start > line_starts[line_start_idx+1]):
def do_process_cmd (chunks, input_name, options):
snippets = [c for c in chunks if isinstance (c, LilypondSnippet)]
- outdated = [c for c in snippets
- if (c.ly_is_outdated () or c.png_is_outdated ())]
+
+
+ output_files = set(os.listdir(options.lily_output_dir))
+ 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, [])