From: Reinhold Kainhofer Date: Thu, 6 Sep 2007 23:03:47 +0000 (+0200) Subject: MusicXML: Allow .xml to be left out on input files, allow .ly on output files X-Git-Tag: release/2.11.33-1~4^2~16 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2f7533a4a73cb1f1d91ff97a469877f935025adf;p=lilypond.git MusicXML: Allow .xml to be left out on input files, allow .ly on output files The output file name is assumed to be without the .ly suffix, which is counterintuitive: As as user I would expect the option "-o test.ly" to generate a file test.ly. However, .ly was always appended to the filename, so remove a possible .ly suffix if given on the output filename. Similarly, the input file name was assumed to be the full file name. In particular with tab-completion in a shell, this means several more keystrokes. If the input file given does not exists, I now also check if a file exists with the .xml suffix appended. This is similar to the behavior of lilypond, where "lilypond test" will also convert a file test.ly. Signed-off-by: Reinhold Kainhofer --- diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index d0bd418399..daf52ec43c 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -992,6 +992,8 @@ def convert (filename, options): if not options.output_name: options.output_name = os.path.basename (filename) options.output_name = os.path.splitext (options.output_name)[0] + elif re.match (".*\.ly", options.output_name): + options.output_name = os.path.splitext (options.output_name)[0] defs_ly_name = options.output_name + '-defs.ly' @@ -1018,6 +1020,13 @@ def convert (filename, options): return voices +def get_existing_filename_with_extension (filename, ext): + if not os.path.exists (filename): + if filename[-1] == '.': + filename += "xml" + elif not re.match ("\.xml$", filename): + filename += ".xml" + return filename def main (): opt_parser = option_parser() @@ -1026,8 +1035,13 @@ def main (): if not args: opt_parser.print_usage() sys.exit (2) - - voices = convert (args[0], options) + + # Allow the user to leave out the .xml on the filename + filename = get_existing_filename_with_extension (args[0], "xml") + if not os.path.exists (filename): + print "Unable to find input file %s" % args[0] + else: + voices = convert (filename, options) if __name__ == '__main__': main()