]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Allow .xml to be left out on input files, allow .ly on output files
authorReinhold Kainhofer <reinhold@kainhofer.com>
Thu, 6 Sep 2007 23:03:47 +0000 (01:03 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Thu, 6 Sep 2007 23:20:25 +0000 (01:20 +0200)
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 <reinhold@kainhofer.com>
scripts/musicxml2ly.py

index d0bd4183991575e40c60c8f7d0110ea811315e95..daf52ec43cc22ed397b6319cbdad4aabd2b988e6 100644 (file)
@@ -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()