new_lys = os.path.join ('Documentation', 'snippets', 'new')
ly_output = os.path.join (tempfile.gettempdir (), 'lsrtest')
-# which convert-ly to use
-if os.path.isfile ("out/bin/convert-ly"):
- conv_path = "out/bin/"
+# which convert-ly and lilypond to use
+P = os.path.join (os.environ.get ("LILYPOND_BUILD_DIR", ""),
+ "out/bin/convert-ly")
+if os.path.isfile (P):
+ conv_path = os.path.dirname (P)
elif os.path.isfile ("build/out/bin/convert-ly"):
conv_path = "build/out/bin/"
else:
conv_path=''
-convert_ly = conv_path + 'convert-ly'
-lilypond_bin = conv_path + 'lilypond'
+convert_ly = os.path.join (conv_path, 'convert-ly')
+lilypond_bin = os.path.join (conv_path, 'lilypond')
dest="bin_path",
action="store",
metavar="LY_PATH",
- default="out/bin",
+ default=conv_path,
help="directory where looking for LilyPond binaries")
options_parser.add_option ('-c', '--convert-ly',
options_parser.print_help (sys.stderr)
sys.exit (n)
+tags=[]
if len (args):
in_dir = args[0]
if not (os.path.isdir (in_dir)):
sys.exit (4)
if len (args) > 1:
exit_with_usage (2)
+ tags = os.listdir (in_dir)
+ ## Make sure all users get the same ordering of tags
+ tags.sort()
else:
in_dir = '.'
convert_ly = os.path.join (options.bin_path, "convert-ly")
else:
convert_ly = options.convert_ly
-if not os.path.isfile (convert_ly):
- sys.stderr.write ("Warning: %s: no such file")
+if not os.path.exists (convert_ly):
+ sys.stderr.write ("Warning: %s: no such file\n" % convert_ly)
convert_ly = "convert-ly"
if options.lilypond_bin == "LY_PATH/lilypond":
lilypond_bin = os.path.join (options.bin_path, "lilypond")
else:
lilypond_bin = options.lilypond_bin
-if not os.path.isfile (lilypond_bin):
- sys.stderr.write ("Warning: %s: no such file")
+if not os.path.exists (lilypond_bin):
+ sys.stderr.write ("Warning: %s: no such file\n" % lilypond_bin)
lilypond_bin = "lilypond"
sys.stderr.write ("Using %s, %s\n" % (convert_ly, lilypond_bin))
-tags = os.listdir (in_dir)
-
unsafe = []
unconverted = []
notags_files = []
begin_header_re = re.compile (r'\\header\s*{', re.M)
ly_new_version_re = re.compile (r'\\version\s*"(.+?)"')
strip_white_spaces_re = re.compile (r'[ \t]+(?=\n)')
+final_empty_lines_re = re.compile (r'\n{2,}$')
# add tags to ly files from LSR
def add_tags (ly_code, tags):
s = mark_verbatim_section (s)
s = lsr_comment_re.sub ('', s)
s = strip_white_spaces_re.sub ('', s)
+ s = final_empty_lines_re.sub ('\n', s)
s = escape_backslashes_in_header (s)
sys.stderr.write ("makelsr.py: writing %s\n" % dest)
open (dest, 'w').write (s)
f = open (file, 'w')
f.write ('\n'.join (sorted (new_list)) + '\n')
-## clean out existing lys and generated files
-map (os.remove, glob.glob (os.path.join (lys_from_lsr, '*.ly')) +
- glob.glob (os.path.join (lys_from_lsr, '*.snippet-list')))
+## clean out existing lys and generated files - but only when we're
+## completely recreating them from the tarball. Otherwise
+## tags will be empty and so we can use this to skip this step
+
+if len(tags) > 0:
+ map (os.remove, glob.glob (os.path.join (lys_from_lsr, '*.ly')) +
+ glob.glob (os.path.join (lys_from_lsr, '*.snippet-list')))
# read LSR source where tags are defined by subdirs
snippets, tag_lists = read_source_with_dirs (in_dir)
for t in tags:
tag_lists[t].update (l[t])
-for (name, (srcdir, tags)) in snippets.items ():
- copy_ly (srcdir, name, tags)
+for (name, (srcdir, file_tags)) in snippets.items ():
+ copy_ly (srcdir, name, file_tags)
for (tag, file_set) in tag_lists.items ():
dump_file_list (os.path.join (lys_from_lsr, tag + '.snippet-list'),
file_set, update=not(in_dir))