Mailing List Archive

[PATCH] pygrub: Add option to list grub entries
# HG changeset patch
# Parent aa479945f718ff775c18afa2f37a391fca573114
# User carnold@suse.com
# Date 1350668686 21600
pygrub: Add option to list grub entries

The argument to "--entry" allows 2 syntaxes, either directly the entry number
in menu.lst, or the whole string behind the "title" key word. This poses the
following issue:
From Dom0 there is no way to guess the number and, or the complete title
string because this string contains the kernel version, which will change
with a kernel update.
This patch adds [-l|--list-entries] as an argument to pygrub.

Signed-off-by: Charles Arnold <carnold@suse.com>

diff -r c1c549c4fe9e tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub Mon Oct 15 16:51:44 2012 +0100
+++ b/tools/pygrub/src/pygrub Fri Oct 19 11:40:49 2012 -0600
@@ -595,7 +595,17 @@ def run_grub(file, entry, fs, cfg_args):
sel = g.run()

g = Grub(file, fs)
- if interactive:
+
+ if list_entries:
+ for i in range(len(g.cf.images)):
+ img = g.cf.images[i]
+ print "title: %s" % img.title
+ print " root: %s" % img.root
+ print " kernel: %s" % img.kernel[1]
+ print " args: %s" % img.args
+ print " initrd: %s" % img.initrd[1]
+
+ if interactive and not list_entries:
curses.wrapper(run_main)
else:
sel = g.cf.default
@@ -702,7 +712,7 @@ if __name__ == "__main__":
sel = None

def usage():
- print >> sys.stderr, "Usage: %s [-q|--quiet] [-i|--interactive] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] [--output-directory=] [--output-format=sxp|simple|simple0] <image>" %(sys.argv[0],)
+ print >> sys.stderr, "Usage: %s [-q|--quiet] [-i|--interactive] [-l|--list-entries] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] [--output-directory=] [--output-format=sxp|simple|simple0] <image>" %(sys.argv[0],)

def copy_from_image(fs, file_to_read, file_type, output_directory,
not_really):
@@ -736,8 +746,8 @@ if __name__ == "__main__":
dataoff += len(data)

try:
- opts, args = getopt.gnu_getopt(sys.argv[1:], 'qinh::',
- ["quiet", "interactive", "not-really", "help",
+ opts, args = getopt.gnu_getopt(sys.argv[1:], 'qilnh::',
+ [."quiet", "interactive", "list-entries", "not-really", "help",
"output=", "output-format=", "output-directory=",
"entry=", "kernel=",
"ramdisk=", "args=", "isconfig", "debug"])
@@ -753,6 +763,7 @@ if __name__ == "__main__":
output = None
entry = None
interactive = True
+ list_entries = False
isconfig = False
debug = False
not_really = False
@@ -771,6 +782,8 @@ if __name__ == "__main__":
interactive = False
elif o in ("-i", "--interactive"):
interactive = True
+ elif o in ("-l", "--list-entries"):
+ list_entries = True
elif o in ("-n", "--not-really"):
not_really = True
elif o in ("-h", "--help"):
@@ -855,6 +868,9 @@ if __name__ == "__main__":
fs = None
continue

+ if list_entries:
+ sys.exit(0)
+
# Did looping through partitions find us a kernel?
if not fs:
raise RuntimeError, "Unable to find partition containing kernel"



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
Re: [PATCH] pygrub: Add option to list grub entries [ In reply to ]
Charles Arnold writes ("[Xen-devel] [PATCH] pygrub: Add option to list grub entries"):
> pygrub: Add option to list grub entries
>
> The argument to "--entry" allows 2 syntaxes, either directly the entry number
> in menu.lst, or the whole string behind the "title" key word. This poses the
> following issue:
> >From Dom0 there is no way to guess the number and, or the complete title
> string because this string contains the kernel version, which will change
> with a kernel update.
> This patch adds [-l|--list-entries] as an argument to pygrub.

> + if list_entries:
> + for i in range(len(g.cf.images)):
> + img = g.cf.images[i]
> + print "title: %s" % img.title
> + print " root: %s" % img.root
> + print " kernel: %s" % img.kernel[1]
> + print " args: %s" % img.args
> + print " initrd: %s" % img.initrd[1]

Is it possible for any of these to contain newlines ? I don't think
so but I'm not entirely sure. If it is then they need to be quoted
somehow or the caller may be unable to unambigously parse the output.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
Re: [PATCH] pygrub: Add option to list grub entries [ In reply to ]
>>> On 10/25/2012 at 09:02 AM, in message
<20617.21621.886298.796143@mariner.uk.xensource.com>, Ian Jackson
<Ian.Jackson@eu.citrix.com> wrote:
> Charles Arnold writes ("[Xen-devel] [PATCH] pygrub: Add option to list grub
> entries"):
>> pygrub: Add option to list grub entries
>>
>> The argument to "--entry" allows 2 syntaxes, either directly the entry number
>> in menu.lst, or the whole string behind the "title" key word. This poses the
>> following issue:
>> >From Dom0 there is no way to guess the number and, or the complete title
>> string because this string contains the kernel version, which will change
>> with a kernel update.
>> This patch adds [-l|--list-entries] as an argument to pygrub.
>
>> + if list_entries:
>> + for i in range(len(g.cf.images)):
>> + img = g.cf.images[i]
>> + print "title: %s" % img.title
>> + print " root: %s" % img.root
>> + print " kernel: %s" % img.kernel[1]
>> + print " args: %s" % img.args
>> + print " initrd: %s" % img.initrd[1]
>
> Is it possible for any of these to contain newlines ? I don't think
> so but I'm not entirely sure. If it is then they need to be quoted
> somehow or the caller may be unable to unambigously parse the output.
>
> Ian.

No, newlines in the menu.lst / grub.cfg files are treated as terminating
characters for each entry option. Nothing I've read in the grub specification
indicates that the entries can be wrapped with an escaped newline character.
My attempts to force a newline character in an entry always fails. The
parsing code in GrubConf.py splits the config file at all newlines.

- Charles



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
Re: [PATCH] pygrub: Add option to list grub entries [ In reply to ]
Charles Arnold writes ("Re: [Xen-devel] [PATCH] pygrub: Add option to list grub entries"):
> No, newlines in the menu.lst / grub.cfg files are treated as terminating
> characters for each entry option. Nothing I've read in the grub specification
> indicates that the entries can be wrapped with an escaped newline character.
> My attempts to force a newline character in an entry always fails. The
> parsing code in GrubConf.py splits the config file at all newlines.

Excellent, thanks for checking.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel