+''' % new_lys_marker
+
+options_parser = optparse.OptionParser (
+ description = "makelsr - update snippets directory from LSR",
+ usage = '''%%prog [options] [LSR_SNIPPETS_DIR]
+Unless -s option is specified, this script must be run from top of the
+source tree. If LSR_SNIPPETS_DIR is not specified, it defaults to
+current directory.
+
+Remove snippets in TOP_SOURCE_DIR/%(lys_from_lsr)s and put in snippets
+from LSR_SNIPPETS_DIR run through convert-ly or from
+TOP_SOURCE_DIR/%(new_lys)s; if a snippet is present in both
+directories, the one from TOP_SOURCE_DIR/%(new_lys)s is preferred.
+All written snippets are copied in LY_OUTPUT
+with appending translations from .texidoc files and are tested with
+lilypond with flags %(lilypond_flags)s
+
+''' % vars ())
+
+options_parser.add_option ('-s', '--top-source',
+ dest="top_source_dir",
+ action="store",
+ metavar="TOP_SOURCE_DIR",
+ default=".",
+ help="set LilyPond top source directory")
+
+options_parser.add_option ('-o', '--ly-output',
+ dest="ly_output",
+ action="store",
+ metavar="LY_OUTPUT",
+ default=ly_output,
+ help="set LilyPond output files temporary directory")
+
+options_parser.add_option ('-p', '--path',
+ dest="bin_path",
+ action="store",
+ metavar="LY_PATH",
+ default=conv_path,
+ help="directory where looking for LilyPond binaries")
+
+options_parser.add_option ('-c', '--convert-ly',
+ dest="convert_ly",
+ action="store",
+ metavar="CONVERT-LY",
+ default="LY_PATH/convert-ly",
+ help="convert-ly binary to use")
+
+options_parser.add_option ('-l', '--lilypond-binary',
+ dest="lilypond_bin",
+ action="store",
+ metavar="LILYPOND_BIN",
+ default="LY_PATH/lilypond",
+ help="lilypond binary to use")
+
+(options, args) = options_parser.parse_args ()
+
+if not os.path.isdir (options.top_source_dir):
+ sys.stderr.write ("Error: top source: %s: not a directory\n" % options.top_source_dir)
+ sys.exit (4)
+
+lys_from_lsr = os.path.normpath (os.path.join (options.top_source_dir, lys_from_lsr))
+new_lys = os.path.normpath (os.path.join (options.top_source_dir, new_lys))
+sys.path.append (os.path.normpath (os.path.join (options.top_source_dir, 'python')))
+import langdefs
+texidoc_dirs = [
+ os.path.normpath (os.path.join (options.top_source_dir, 'Documentation', language_code, 'texidocs'))
+ for language_code in langdefs.LANGDICT]
+
+if not os.path.isdir (lys_from_lsr):
+ sys.stderr.write ("Error: snippets path: %s: not a directory\n" % lys_from_lsr)
+ sys.exit (3)
+if not os.path.isdir (new_lys):
+ sys.stderr.write ("Error: new snippets path: %s: not a directory\n" % lys_from_lsr)
+ sys.exit (3)
+
+ly_output_ok = False
+if os.path.isdir (options.ly_output):
+ ly_output = options.ly_output
+ ly_output_ok = True
+elif os.path.exists (options.ly_output):
+ try:
+ os.unlink (options.ly_output)
+ except Exception as e:
+ sys.stderr.write ("Warning: could not delete file before creating directory: %s\n" % e)
+ else:
+ try:
+ os.makedirs (options.ly_output)
+ except Exception as e:
+ sys.stderr.write ("Warning: could not create directory: %s\n" % e)
+ else:
+ ly_output = options.ly_output
+ ly_output_ok = True
+else:
+ try:
+ os.makedirs (options.ly_output)
+ except Exception as e:
+ sys.stderr.write ("Warning: could not create directory: %s\n" % e)
+ else:
+ ly_output = options.ly_output
+ ly_output_ok = True
+if not ly_output_ok:
+ ly_output = tempfile.gettempdir ()
+ sys.stderr.write ("Warning: could not use or create directory %s, using default %s\n" % (options.ly_output, ly_output))