From dcd296e0d46d85e892a3237f6354502b5be614a9 Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Sun, 23 Mar 2008 15:40:17 +0100 Subject: [PATCH] Add support for LSR snippets texidocs translation Additional makelsr.py bugfixes: - quote file names (for file names with semicolons) - do not call lilypond with nice; the user should decide himself which process priority he wants to update LSR with. --- buildscripts/makelsr.py | 20 +++++++++++++++----- input/GNUmakefile | 2 +- input/texidocs/GNUmakefile | 5 +++++ make/lilypond-vars.make | 3 ++- scripts/lilypond-book.py | 23 ++++++++++++++++------- 5 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 input/texidocs/GNUmakefile diff --git a/buildscripts/makelsr.py b/buildscripts/makelsr.py index 265bbb6b83..a5fd48013e 100755 --- a/buildscripts/makelsr.py +++ b/buildscripts/makelsr.py @@ -20,6 +20,7 @@ LY_HEADER_NEW = '''%% Do not edit this file; it is auto-generated from input/new DEST = os.path.join ('input', 'lsr') NEW_LYS = os.path.join ('input', 'new') +TEXIDOCS = os.path.join ('input', 'texidocs') TAGS = [] # NR 1 @@ -56,11 +57,11 @@ end_header_re = re.compile ('(\\header {.+?(?:"\\s*|\\s+)}\n)\n', re.M | re.S) def mark_verbatim_section (ly_code): return end_header_re.sub ('\\1% begin verbatim\n', ly_code, 1) -# add tags to ly files from LSR -add_tags_re = re.compile ('\\header\\s*{', re.M) +begin_header_re = re.compile ('\\header\\s*{', re.M) +# add tags to ly files from LSR def add_tags (ly_code, tags): - return add_tags_re.sub ('\\g<0>\n lsrtags = "' + tags + '"\n', ly_code, 1) + return begin_header_re.sub ('\\g<0>\n lsrtags = "' + tags + '"\n', ly_code, 1) def copy_ly (srcdir, name, tags): global unsafe @@ -68,19 +69,28 @@ def copy_ly (srcdir, name, tags): dest = os.path.join (DEST, name) tags = ', '.join (tags) s = open (os.path.join (srcdir, name)).read () + + texidoc_translations_path = os.path.join (TEXIDOCS, + os.path.splitext (name)[0] + '.texidoc') + if os.path.exists (texidoc_translations_path): + texidoc_translations = open (texidoc_translations_path).read () + s = begin_header_re.sub ('\\g<0>\n' + texidoc_translations, s, 1) + if in_dir in srcdir: s = LY_HEADER_LSR + add_tags (s, tags) else: s = LY_HEADER_NEW + s + s = mark_verbatim_section (s) open (dest, 'w').write (s) - e = os.system('convert-ly -e ' + dest) + + e = os.system ("convert-ly -e '%s'" % dest) if e: unconverted.append (dest) if os.path.exists (dest + '~'): os.remove (dest + '~') # -V seems to make unsafe snippets fail nicer/sooner - e = os.system ('nice lilypond -V -dno-print-pages -dsafe -o /tmp/lsrtest ' + dest) + e = os.system ("lilypond -V -dno-print-pages -dsafe -o /tmp/lsrtest '%s'" % dest) if e: unsafe.append (dest) diff --git a/input/GNUmakefile b/input/GNUmakefile index 65db9aaa23..f6cc680093 100644 --- a/input/GNUmakefile +++ b/input/GNUmakefile @@ -1,6 +1,6 @@ depth = .. -SUBDIRS = regression tutorial mutopia manual lsr new +SUBDIRS = regression tutorial mutopia manual lsr new texidocs examples = typography-demo les-nereides wilhelmus proportional bach-schenker cary diff --git a/input/texidocs/GNUmakefile b/input/texidocs/GNUmakefile new file mode 100644 index 0000000000..6142dd9bd3 --- /dev/null +++ b/input/texidocs/GNUmakefile @@ -0,0 +1,5 @@ +depth=../.. + +EXTRA_DIST_FILES=$(call src-wildcard,*.texidoc) + +include $(depth)/make/stepmake.make diff --git a/make/lilypond-vars.make b/make/lilypond-vars.make index 45ed186353..e6f12ba7b0 100644 --- a/make/lilypond-vars.make +++ b/make/lilypond-vars.make @@ -29,7 +29,8 @@ LILYPOND_BOOK_INCLUDES = -I $(src-dir)/ -I $(outdir) -I $(input-dir) -I $(input- ## override from cmd line to speed up. ANTI_ALIAS_FACTOR=2 LILYPOND_JOBS=$(if $(CPU_COUNT),-djob-count=$(CPU_COUNT),) -LILYPOND_BOOK_LILYPOND_FLAGS=-dbackend=eps --formats=ps,png,pdf $(LILYPOND_JOBS) -dinclude-eps-fonts -dgs-load-fonts --header=texidoc -I $(top-src-dir)/input/manual -dcheck-internal-types -ddump-signatures -danti-alias-factor=$(ANTI_ALIAS_FACTOR) +LANG_TEXIDOC_FLAG=$(if $(ISOLANG),--header=texidoc$(ISOLANG),) +LILYPOND_BOOK_LILYPOND_FLAGS=-dbackend=eps --formats=ps,png,pdf $(LILYPOND_JOBS) -dinclude-eps-fonts -dgs-load-fonts --header=texidoc $(LANG_TEXIDOC_FLAG) -I $(top-src-dir)/input/manual -dcheck-internal-types -ddump-signatures -danti-alias-factor=$(ANTI_ALIAS_FACTOR) LILYPOND_BOOK_VERBOSE = --verbose LILYPOND_BOOK_INFO_IMAGES_DIR = $(if $(INFO_IMAGES_DIR),--info-images-dir=$(INFO_IMAGES_DIR),) LILYPOND_BOOK_FLAGS = $(LILYPOND_BOOK_VERBOSE) $(LILYPOND_BOOK_INFO_IMAGES_DIR) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 5e6ff2b32a..d4af98cf65 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -206,6 +206,7 @@ FILTER = 'filter' FRAGMENT = 'fragment' HTML = 'html' INDENT = 'indent' +LANG = 'lang' LATEX = 'latex' LAYOUT = 'layout' LINE_WIDTH = 'line-width' @@ -512,6 +513,7 @@ simple_options = [ NOINDENT, PRINTFILENAME, TEXIDOC, + LANG, VERBATIM, FONTLOAD, FILENAME, @@ -814,6 +816,8 @@ def split_options (option_string): option_string) return [] +texinfo_lang_re = re.compile ('(?m)^@documentlanguage (.*?)( |$)') + def set_default_options (source): global default_ly_options if not default_ly_options.has_key (LINE_WIDTH): @@ -822,6 +826,11 @@ def set_default_options (source): default_ly_options[LINE_WIDTH] = \ '''%.0f\\pt''' % textwidth elif global_options.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 (k, v) in texinfo_line_widths.items (): # FIXME: @layout is usually not in # chunk #0: @@ -1261,7 +1270,10 @@ class Lilypond_snippet (Snippet): 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 = '' @@ -1756,13 +1768,10 @@ def do_file (input_filename): progress ('\n') return do_file (name) - include_chunks = map (process_include, - filter (lambda x: is_derived_class (x.__class__, - Include_snippet), - chunks)) - + include_chunks = [process_include (c) for c in chunks + if is_derived_class (c.__class__, Include_snippet)] - return chunks + reduce (lambda x,y: x + y, include_chunks, []) + return chunks + reduce (operator.add, include_chunks, []) except Compile_error: os.chdir (original_dir) -- 2.39.2