WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] Make PyGrub run first entry in grub config when

To: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
From: Michal Novotny <minovotn@xxxxxxxxxx>
Date: Tue, 24 Mar 2009 10:21:38 +0100
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Tue, 24 Mar 2009 02:22:05 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <18887.49660.721664.393967@xxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <49C3A4D6.5050501@xxxxxxxxxx> <18887.49660.721664.393967@xxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.21 (X11/20090320)
Hi,
thanks for advice. Here's new and corrected version of the patch. Well, the error here is IndexError, when an error occurs so the IndexError is catched and not KeyError. I have also tried it with KeyError but it was not working so IndexError is catched here.

Michal

Ian Jackson wrote:
Michal Novotny writes ("[Xen-devel] [PATCH] Make PyGrub run first entry in grub 
config when invalid default boot option provided"):
-    img = g.cf.images[sel]
+    try:
+        img = g.cf.images[sel]
+    except:

It is not correct to do this on all exceptions.  (This is a common
mistake in Python.)  I assume that in your error case the images array
doesn't have the relevant entry and that your code should read:
  +        img = g.cf.images[sel]
  +    except KeyError:

Ian.

diff -r e1562a36094e tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub   Thu Mar 19 17:04:06 2009 +0000
+++ b/tools/pygrub/src/pygrub   Fri Mar 20 15:09:31 2009 +0100
@@ -530,7 +530,11 @@
         print "No kernel image selected!"
         sys.exit(1)
 
-    img = g.cf.images[sel]
+    try:
+        img = g.cf.images[sel]
+    except IndexError:
+        img = g.cf.images[0]
+
 
     grubcfg = { "kernel": None, "ramdisk": None, "args": None }
 
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel