Commit 3c4ba2e9 authored by Leigh B Stoller's avatar Leigh B Stoller

Localized and fixed version of pygrub that can handle submenus and our

whacky slice images.
parent 091a7ac3
#
# GrubConf.py - Simple grub.conf parsing
#
# Copyright 2009 Citrix Systems Inc.
# Copyright 2009, 2013 Citrix Systems Inc.
# Copyright 2005-2006 Red Hat, Inc.
# Jeremy Katz <katzj@redhat.com>
#
......@@ -67,7 +67,14 @@ class GrubDiskPart(object):
return self._disk
def set_disk(self, val):
val = val.replace("(", "").replace(")", "")
self._disk = int(val[2:])
if val.startswith("/dev/"):
val = val[5:]
pass
val = val[2:]
if not str.isdigit(val):
val = ord(val) - ord('a');
pass
self._disk = int(val)
disk = property(get_disk, set_disk)
def get_part(self):
......@@ -167,6 +174,7 @@ class _GrubConfigFile(object):
self.images = []
self.timeout = -1
self._default = 0
self._submenu = ""
self.passwordAccess = True
self.passExc = None
......@@ -227,8 +235,12 @@ class _GrubConfigFile(object):
if val == "saved":
self._default = 0
else:
self._default = int(val)
try:
self._default = int(val)
except:
self._default = 0
self._submenu = val
pass
if self._default < 0:
raise ValueError, "default must be positive number"
default = property(_get_default, _set_default)
......@@ -370,7 +382,9 @@ class Grub2ConfigFile(_GrubConfigFile):
in_function = False
img = None
title = ""
subtitle = ""
menu_level=0
submenu_default=0
for l in lines:
l = l.strip()
# skip blank lines
......@@ -400,12 +414,23 @@ class Grub2ConfigFile(_GrubConfigFile):
if l.startswith("submenu"):
menu_level += 1
submenu_default = len(self.images)
submenu_match = re.match('^submenu ["\'](.*)["\'] \s*{', l)
if submenu_match:
subtitle = submenu_match.group(1)
pass
continue
if l.startswith("}"):
if img is None:
if menu_level > 0:
menu_level -= 1
print "foo"
print subtitle
print self._submenu
if subtitle == self._submenu:
self._set_default(submenu_default)
pass
continue
else:
raise RuntimeError, "syntax error: closing brace without menuentry"
......
......@@ -17,6 +17,9 @@ import os, sys, string, struct, tempfile, re, traceback
import copy
import logging
import platform
sys.path.append('/usr/lib/xen-default/lib/python')
import xen.lowlevel.xc
import curses, _curses, curses.wrapper, curses.textpad, curses.ascii
......@@ -624,6 +627,7 @@ def run_grub(file, entry, fs, cfg_args):
img = g.cf.images[sel]
except IndexError:
img = g.cf.images[0]
print str(img)
grubcfg = { "kernel": None, "ramdisk": None, "args": "" }
......@@ -726,21 +730,27 @@ if __name__ == "__main__":
except Exception, e:
print >>sys.stderr, e
sys.exit("Error opening %s in guest" % file_to_read)
(tfd, ret) = tempfile.mkstemp(prefix="boot_"+file_type+".",
dir=output_directory)
pass
filename = output_directory + "/" + file_type
try:
tfd = open(filename, "wb")
except Exception, e:
print >>sys.stderr, e
sys.exit("Error opening %s for writing" % filename)
pass
dataoff = 0
while True:
data = datafile.read(FS_READ_MAX, dataoff)
if len(data) == 0:
os.close(tfd)
tfd.close()
del datafile
return ret
return filename
try:
os.write(tfd, data)
tfd.write(data)
except Exception, e:
print >>sys.stderr, e
os.close(tfd)
os.unlink(ret)
tfd.close()
os.unlink(filename)
del datafile
sys.exit("Error writing temporary copy of "+file_type)
dataoff += len(data)
......@@ -841,6 +851,10 @@ if __name__ == "__main__":
# get list of offsets into file which start partitions
part_offs = get_partition_offsets(file)
print str(part_offs);
if len(part_offs) == 0:
part_offs = [0]
pass
for offset in part_offs:
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment