]> git.donarmstrong.com Git - lilypond.git/commitdiff
convert-ly: Raise an error message if version number is not a three-entry tuple
authorReinhold Kainhofer <reinhold@kainhofer.com>
Thu, 31 Dec 2009 11:20:41 +0000 (12:20 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 17 Feb 2010 21:38:14 +0000 (22:38 +0100)
This fixes crashes with things like
   \version "2.10"
or
   \version "2.10.4.3.21"
and instead gracefully reminds the user that version strings should have a
form like `2.8.12'

scripts/convert-ly.py

index f1d90f2641e63dd559792683197858f2722b1717..cf82b029cfd649a4294e0b0b1dceef1d126bc437 100644 (file)
@@ -204,12 +204,16 @@ def guess_lilypond_version (input):
     else:
         return ''
 
-class FatalConversionError:
+class FatalConversionError (Exception):
     pass
 
-class UnknownVersion:
+class UnknownVersion (Exception):
     pass
 
+class InvalidVersion (Exception):
+    def __init__ (self, version):
+      self.version = version
+
 def do_one_file (infile_name):
     ly.stderr_write (_ ("Processing `%s\'... ") % infile_name)
     sys.stderr.write ('\n')
@@ -236,6 +240,9 @@ def do_one_file (infile_name):
     else:
         to_version = latest_version ()
 
+    if len (from_version) != 3:
+        raise InvalidVersion (".".join ([str(n) for n in from_version]))
+
 
     (last, result) = do_conversion (input, from_version, to_version)
 
@@ -304,14 +311,18 @@ def main ():
         if f == '-':
             f = ''
         elif not os.path.isfile (f):
-            error (_ ("cannot open file: `%s'") % f)
+            error (_ ("%s: Unable to open file") % f)
             if len (files) == 1:
                 sys.exit (1)
             continue
         try:
             do_one_file (f)
         except UnknownVersion:
-            error (_ ("cannot determine version for `%s'.  Skipping") % f)
+            error (_ ("%s: Unable to determine version.  Skipping") % f)
+        except InvalidVersion as ex:
+            error (_ ("%s: Invalid version string `%s' \n"
+                      "Valid version strings consist of three numbers, "
+                      "separated by dots, e.g. `2.8.12'") % (f, ex.version) )
 
     sys.stderr.write ('\n')