Skip to contentSkip to conversation

pygrub: add debug flag

PATCH Applied Guido Günther 3 participants 4 messages Oct 7, 2011 – Oct 11, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pygrub: add debug flag

Debugging config file errors is tedious so help a bit by not silently dropping parsing exceptions when --debug is given. Also intialize the logging API at debug level in this case.
Cheers,
-- Guido

---
 tools/pygrub/src/pygrub |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
tools/pygrub/src/pygrub +10 -2
index 52b1823..5dc9405 100644
@@ -13,7 +13,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #
 
-import os, sys, string, struct, tempfile, re
+import os, sys, string, struct, tempfile, re, traceback
 import copy
 import logging
 import platform
@@ -665,7 +665,7 @@ if __name__ == "__main__":
                                    ["quiet", "interactive", "not-really", "help", 
                                     "output=", "output-format=", "output-directory=",
                                     "entry=", "kernel=", 
-                                    "ramdisk=", "args=", "isconfig"])
+                                    "ramdisk=", "args=", "isconfig", "debug"])
     except getopt.GetoptError:
         usage()
         sys.exit(1)
@@ -679,6 +679,7 @@ if __name__ == "__main__":
     entry = None
     interactive = True
     isconfig = False
+    debug = False
     not_really = False
     output_format = "sxp"
     output_directory = "/var/run/xend/boot"
@@ -714,6 +715,8 @@ if __name__ == "__main__":
             interactive = False
         elif o in ("--isconfig",):
             isconfig = True
+        elif o in ("--debug",):
+            debug = True
         elif o in ("--output-format",):
             if a not in ["sxp", "simple", "simple0"]:
                 print "unkonwn output format %s" % a
@@ -723,6 +726,9 @@ if __name__ == "__main__":
         elif o in ("--output-directory",):
             output_directory = a
 
+    if debug:
+	logging.basicConfig(level=logging.DEBUG)
+
     if output is None or output == "-":
         fd = sys.stdout.fileno()
     else:
@@ -769,6 +775,8 @@ if __name__ == "__main__":
         except:
             # IOErrors raised by fsimage.open
             # RuntimeErrors raised by run_grub if no menu.lst present
+            if debug:
+		traceback.print_exc()
             fs = None
             continue
 
Signature · 1 line
1.7.6.3
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Guido Günther

Debugging config file errors is tedious so help a bit by not silently dropping parsing exceptions when --debug is given. Also intialize the logging API at debug level in this case.

This looks fine but requires a Signed-off-line, per the DCO
http://wiki.xen.org/xenwiki/SubmittingXenPatches

BTW another useful but not widely known debug feature is that you can run {Grub,ExtLinux}Conf.py directly passing a config file as a parameter and they will print out what they parse from it, or the errors as appropriate.

Ian.

Quoted 65 lines

Cheers,
-- Guido

---
 tools/pygrub/src/pygrub |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
tools/pygrub/src/pygrub +10 -2
index 52b1823..5dc9405 100644
@@ -13,7 +13,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #
 
-import os, sys, string, struct, tempfile, re
+import os, sys, string, struct, tempfile, re, traceback
 import copy
 import logging
 import platform
@@ -665,7 +665,7 @@ if __name__ == "__main__":
                                    ["quiet", "interactive", "not-really", "help", 
                                     "output=", "output-format=", "output-directory=",
                                     "entry=", "kernel=", 
-                                    "ramdisk=", "args=", "isconfig"])
+                                    "ramdisk=", "args=", "isconfig", "debug"])
     except getopt.GetoptError:
         usage()
         sys.exit(1)
@@ -679,6 +679,7 @@ if __name__ == "__main__":
     entry = None
     interactive = True
     isconfig = False
+    debug = False
     not_really = False
     output_format = "sxp"
     output_directory = "/var/run/xend/boot"
@@ -714,6 +715,8 @@ if __name__ == "__main__":
             interactive = False
         elif o in ("--isconfig",):
             isconfig = True
+        elif o in ("--debug",):
+            debug = True
         elif o in ("--output-format",):
             if a not in ["sxp", "simple", "simple0"]:
                 print "unkonwn output format %s" % a
@@ -723,6 +726,9 @@ if __name__ == "__main__":
         elif o in ("--output-directory",):
             output_directory = a
 
+    if debug:
+	logging.basicConfig(level=logging.DEBUG)
+
     if output is None or output == "-":
         fd = sys.stdout.fileno()
     else:
@@ -769,6 +775,8 @@ if __name__ == "__main__":
         except:
             # IOErrors raised by fsimage.open
             # RuntimeErrors raised by run_grub if no menu.lst present
+            if debug:
+		traceback.print_exc()
             fs = None
             continue
 
#2 lore raw
Quoted 8 lines · Ian Campbell
Quoted 3 lines · Guido Günther

Debugging config file errors is tedious so help a bit by not silently dropping parsing exceptions when --debug is given. Also intialize the logging API at debug level in this case.

This looks fine but requires a Signed-off-line, per the DCO
http://wiki.xen.org/xenwiki/SubmittingXenPatches

Quoted 6 lines

BTW another useful but not widely known debug feature is that you can run {Grub,ExtLinux}Conf.py directly passing a config file as a parameter and they will print out what they parse from it, or the errors as appropriate.

New version with Signed-off attached.
Cheers,
-- Guido

Quoted 1 line

From 41ff0496852be86a43245beaaab0afd43a3a471a Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Guido=20G=C3=BCnther?= <[email protected]>
Date: Fri, 7 Oct 2011 10:35:06 +0200
Subject: [PATCH] pygrub: add debug flag
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Debugging config file errors is tedious so help a bit by not silently dropping parsing exceptions when --debug is given. Also intialize the logging API at debug level in this case.
Cheers,
-- Guido

---
 tools/pygrub/src/pygrub |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
tools/pygrub/src/pygrub +10 -2
index 52b1823..5dc9405 100644
@@ -13,7 +13,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #
 
-import os, sys, string, struct, tempfile, re
+import os, sys, string, struct, tempfile, re, traceback
 import copy
 import logging
 import platform
@@ -665,7 +665,7 @@ if __name__ == "__main__":
                                    ["quiet", "interactive", "not-really", "help", 
                                     "output=", "output-format=", "output-directory=",
                                     "entry=", "kernel=", 
-                                    "ramdisk=", "args=", "isconfig"])
+                                    "ramdisk=", "args=", "isconfig", "debug"])
     except getopt.GetoptError:
         usage()
         sys.exit(1)
@@ -679,6 +679,7 @@ if __name__ == "__main__":
     entry = None
     interactive = True
     isconfig = False
+    debug = False
     not_really = False
     output_format = "sxp"
     output_directory = "/var/run/xend/boot"
@@ -714,6 +715,8 @@ if __name__ == "__main__":
             interactive = False
         elif o in ("--isconfig",):
             isconfig = True
+        elif o in ("--debug",):
+            debug = True
         elif o in ("--output-format",):
             if a not in ["sxp", "simple", "simple0"]:
                 print "unkonwn output format %s" % a
@@ -723,6 +726,9 @@ if __name__ == "__main__":
         elif o in ("--output-directory",):
             output_directory = a
 
+    if debug:
+	logging.basicConfig(level=logging.DEBUG)
+
     if output is None or output == "-":
         fd = sys.stdout.fileno()
     else:
@@ -769,6 +775,8 @@ if __name__ == "__main__":
         except:
             # IOErrors raised by fsimage.open
             # RuntimeErrors raised by run_grub if no menu.lst present
+            if debug:
+		traceback.print_exc()
             fs = None
             continue
 
Signature · 1 line
1.7.6.3

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Applied
#3 lore raw

Guido Günther writes ("Re: [Xen-devel] [PATCH] pygrub: add debug flag"):

Quoted 1 line

New version with Signed-off attached.

Applied, thanks.

Ian