From: John Mandereau Date: Tue, 29 Dec 2009 22:19:58 +0000 (+0100) Subject: Add lilypond-book --use-source-file-names command-line option X-Git-Tag: release/2.13.10-1~22 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=817c7f7e9880788e6a9c4cd74958dc7f8f901276;p=lilypond.git Add lilypond-book --use-source-file-names command-line option This is mainly intended to make regression tests output filenames more stable against changes of their contents and changes in lilypond-book, and could also make generated snippets reuse a little easier (as it makes output filenames controllable and predictable by the user). This doesn't break the hashing system that saves lilypond processing time. See complete discussion at http://lists.gnu.org/archive/html/lilypond-devel/2009-12/msg00636.html --- diff --git a/Documentation/usage/lilypond-book.itely b/Documentation/usage/lilypond-book.itely index 348f201e78..2abffff61e 100644 --- a/Documentation/usage/lilypond-book.itely +++ b/Documentation/usage/lilypond-book.itely @@ -923,7 +923,6 @@ elements that stick into the left margin, such as bar numbers and instrument names. This option will shorten each line and move each line to the right by the same amount. - @item -P @var{command} @itemx --process=@var{command} Process LilyPond snippets using @var{command}. The default command is @@ -933,6 +932,12 @@ Process LilyPond snippets using @var{command}. The default command is @item --pdf Create PDF files for use with PDF@LaTeX{}. +@itemx --use-source-file-names +Write snippet output files with the same base name as their source file. +This option works only for snippets included with @code{lilypondfile} +and only if directories implied by @code{--output-dir} and +@code{--lily-output-dir} options are different. + @item -V @itemx --verbose Be verbose. diff --git a/make/lysdoc-vars.make b/make/lysdoc-vars.make index a2874b271b..5cbc61717c 100644 --- a/make/lysdoc-vars.make +++ b/make/lysdoc-vars.make @@ -4,3 +4,7 @@ TITLE=LYs Doc ifeq ($(COLLATED_FILES),) COLLATED_FILES = $(sort $(TEXINFO_SOURCES) $(LY_FILES) $(OUT_LY_FILES) ) endif + +ifeq ($(out),test) +LILYPOND_BOOK_FLAGS += --use-source-file-names +endif diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 27a19c5263..0916ce1741 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -210,6 +210,11 @@ def get_option_parser (): action='store_true', dest='skip_png_check', default=False) + p.add_option ('--use-source-file-names', + help=_ ("write snippet output files with the same base name as their source file"), + action='store_true', dest='use_source_file_names', + default=False) + p.add_option ('-V', '--verbose', help=_ ("be verbose"), action="store_true", default=False, @@ -1292,6 +1297,8 @@ left-margin-default right-margin-default)" name = '%s/lily-%s' % (cs[:2], cs[2:]) return name + final_basename = basename + def write_ly (self): base = self.basename () path = os.path.join (global_options.lily_output_dir, base) @@ -1319,13 +1326,25 @@ printing diff against existing file." % filename) print '\nMissing', missing raise CompileError(self.basename()) for name in existing: + if (global_options.use_source_file_names + and isinstance (self, LilypondFileSnippet)): + base, ext = os.path.splitext (name) + components = base.split ('-') + # ugh, assume filenames with prefix with one dash (lily-xxxx) + if len (components) > 2: + base_suffix = '-' + components[-1] + else: + base_suffix = '' + final_name = self.final_basename () + base_suffix + ext + else: + final_name = name try: - os.unlink (os.path.join (destination, name)) + os.unlink (os.path.join (destination, final_name)) except OSError: pass src = os.path.join (output_dir, name) - dst = os.path.join (destination, name) + dst = os.path.join (destination, final_name) dst_path = os.path.split(dst)[0] if not os.path.isdir (dst_path): os.makedirs (dst_path) @@ -1426,7 +1445,7 @@ printing diff against existing file." % filename) return func (self) def get_images (self): - base = self.basename () + base = self.final_basename () single = '%(base)s.png' % vars () multiple = '%(base)s-page1.png' % vars () @@ -1443,7 +1462,7 @@ printing diff against existing file." % filename) def output_docbook (self): str = '' - base = self.basename () + base = self.final_basename () for image in self.get_images (): (base, ext) = os.path.splitext (image) str += output[DOCBOOK][OUTPUT] % vars () @@ -1459,7 +1478,7 @@ printing diff against existing file." % filename) def output_html (self): str = '' - base = self.basename () + base = self.final_basename () if self.format == HTML: str += self.output_print_filename (HTML) if VERBATIM in self.option_dict: @@ -1488,13 +1507,13 @@ printing diff against existing file." % filename) info_image_path = os.path.join (global_options.info_images_dir, base) str += output[TEXINFO][OUTPUTIMAGE] % vars () - base = self.basename () + base = self.final_basename () str += output[self.format][OUTPUT] % vars () return str def output_latex (self): str = '' - base = self.basename () + base = self.final_basename () if self.format == LATEX: str += self.output_print_filename (LATEX) if VERBATIM in self.option_dict: @@ -1515,7 +1534,7 @@ printing diff against existing file." % filename) def output_print_filename (self, format): str = '' if PRINTFILENAME in self.option_dict: - base = self.basename () + base = self.final_basename () filename = os.path.basename (self.substring ('filename')) str = output[format][PRINTFILENAME] % vars () @@ -1523,7 +1542,7 @@ printing diff against existing file." % filename) def output_texinfo (self): str = self.output_print_filename (TEXINFO) - base = self.basename () + base = self.final_basename () if DOCTITLE in self.option_dict: doctitle = base + '.doctitle' translated_doctitle = doctitle + document_language @@ -1586,6 +1605,13 @@ class LilypondFileSnippet (LilypondSnippet): return ('\\sourcefilename \"%s\"\n\\sourcefileline 0\n%s' % (name, self.contents)) + def final_basename (self): + if global_options.use_source_file_names: + base = os.path.splitext (os.path.basename (self.substring ('filename')))[0] + return base + else: + return self.basename () + class LilyPondVersionString (Snippet): """A string that does not require extra memory."""