mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
pygrub: make python scripts work with 2.6 and up
Run 2to3 and pick the sensible suggestions. Import print_function and absolute_import so 2.6 can work. There has never been a curses.wrapper module according to 2.x and 3.x doc, only a function, so "import curses.wrapper" is not correct. It happened to work because 2.x implemented a (undocumented) module. We only need to import curses to make curses.wrapper available to pygrub. Signed-off-by: Wei Liu <wei.liu2@citrix.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
1 parent
660d2dd863
commit
0aabd89dcf
4 files changed
+78
-70
No files matched your search
@@ -10,9 +10,11 @@
|
||||
# along with this program; If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
|
||||
import sys, re, os
|
||||
import logging
|
||||
import GrubConf
|
||||
from . import GrubConf
|
||||
|
||||
class ExtLinuxImage(object):
|
||||
def __init__(self, lines, path):
|
||||
@@ -32,7 +34,8 @@ class ExtLinuxImage(object):
|
||||
self.lines = []
|
||||
self.path = path
|
||||
self.root = ""
|
||||
map(self.set_from_line, lines)
|
||||
for line in lines:
|
||||
self.set_from_line(line)
|
||||
|
||||
def set_from_line(self, line, replace = None):
|
||||
(com, arg) = GrubConf.grub_exact_split(line, 2)
|
||||
@@ -67,7 +70,7 @@ class ExtLinuxImage(object):
|
||||
setattr(self, "initrd", a.replace("initrd=", ""))
|
||||
arg = arg.replace(a, "")
|
||||
|
||||
if com is not None and self.commands.has_key(com):
|
||||
if com is not None and com in self.commands:
|
||||
if self.commands[com] is not None:
|
||||
setattr(self, self.commands[com], re.sub('^"(.+)"$', r"\1", arg.strip()))
|
||||
else:
|
||||
@@ -136,7 +139,7 @@ class ExtLinuxConfigFile(object):
|
||||
def parse(self, buf = None):
|
||||
if buf is None:
|
||||
if self.filename is None:
|
||||
raise ValueError, "No config file defined to parse!"
|
||||
raise ValueError("No config file defined to parse!")
|
||||
|
||||
f = open(self.filename, 'r')
|
||||
lines = f.readlines()
|
||||
@@ -167,7 +170,7 @@ class ExtLinuxConfigFile(object):
|
||||
|
||||
(com, arg) = GrubConf.grub_exact_split(l, 2)
|
||||
com = com.lower()
|
||||
if self.commands.has_key(com):
|
||||
if com in self.commands:
|
||||
if self.commands[com] is not None:
|
||||
setattr(self, self.commands[com], arg.strip())
|
||||
else:
|
||||
@@ -207,8 +210,8 @@ class ExtLinuxConfigFile(object):
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
raise RuntimeError, "Need a configuration file to read"
|
||||
raise RuntimeError("Need a configuration file to read")
|
||||
g = ExtLinuxConfigFile(sys.argv[1])
|
||||
for i in g.images:
|
||||
print i
|
||||
print g.default
|
||||
print(i)
|
||||
print(g.default)
|
||||