From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
Anthony PERARD <anthony.perard@citrix.com>,
Wei Liu <wei.liu2@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH for-next v2 v2 3/5] pygrub: convert python scripts to work with 2.6 and up
Date: Wed, 6 Mar 2019 17:52:08 +0000 [thread overview]
Message-ID: <20190306175210.28145-4-wei.liu2@citrix.com> (raw)
In-Reply-To: <20190306175210.28145-1-wei.liu2@citrix.com>
Run 2to3 and pick the sensible suggestions.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/pygrub/src/ExtLinuxConf.py | 15 ++++++++-------
tools/pygrub/src/GrubConf.py | 36 ++++++++++++++++++------------------
tools/pygrub/src/LiloConf.py | 15 ++++++++-------
3 files changed, 34 insertions(+), 32 deletions(-)
diff --git a/tools/pygrub/src/ExtLinuxConf.py b/tools/pygrub/src/ExtLinuxConf.py
index d1789bf020..b84bbf8454 100644
--- a/tools/pygrub/src/ExtLinuxConf.py
+++ b/tools/pygrub/src/ExtLinuxConf.py
@@ -32,7 +32,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 +68,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 +137,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 +168,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 +208,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)
diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py
index dc810d55cb..97913f3993 100644
--- a/tools/pygrub/src/GrubConf.py
+++ b/tools/pygrub/src/GrubConf.py
@@ -44,7 +44,7 @@ def get_path(s):
return (None, s)
idx = s.find(')')
if idx == -1:
- raise ValueError, "Unable to find matching ')'"
+ raise ValueError("Unable to find matching ')'")
d = s[:idx]
return (GrubDiskPart(d), s[idx + 1:])
@@ -100,7 +100,7 @@ class _GrubImage(object):
" initrd: %s\n" %(self.title, self.root, self.kernel,
self.args, self.initrd))
def _parse(self, lines):
- map(self.set_from_line, lines)
+ list(map(self.set_from_line, lines))
def reset(self, lines):
self._root = self._initrd = self._kernel = self._args = None
@@ -141,7 +141,7 @@ class GrubImage(_GrubImage):
def set_from_line(self, line, replace = None):
(com, arg) = grub_exact_split(line, 2)
- 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:
@@ -177,7 +177,7 @@ class _GrubConfigFile(object):
self.parse()
def parse(self, buf = None):
- raise RuntimeError, "unimplemented parse function"
+ raise RuntimeError("unimplemented parse function")
def hasPasswordAccess(self):
return self.passwordAccess
@@ -201,7 +201,7 @@ class _GrubConfigFile(object):
import crypt
if crypt.crypt(password, pwd[1]) == pwd[1]:
return True
- except Exception, e:
+ except Exception as e:
self.passExc = "Can't verify password: %s" % str(e)
return False
@@ -213,7 +213,7 @@ class _GrubConfigFile(object):
def set(self, line):
(com, arg) = grub_exact_split(line, 2)
- 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:
@@ -233,7 +233,7 @@ class _GrubConfigFile(object):
self._default = val
if self._default < 0:
- raise ValueError, "default must be positive number"
+ raise ValueError("default must be positive number")
default = property(_get_default, _set_default)
def set_splash(self, val):
@@ -265,7 +265,7 @@ class GrubConfigFile(_GrubConfigFile):
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()
@@ -296,7 +296,7 @@ class GrubConfigFile(_GrubConfigFile):
continue
(com, arg) = grub_exact_split(l, 2)
- 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:
@@ -328,7 +328,7 @@ class Grub2Image(_GrubImage):
if com == "set":
(com,arg) = grub2_handle_set(arg)
- 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:
@@ -364,7 +364,7 @@ class Grub2ConfigFile(_GrubConfigFile):
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()
@@ -398,7 +398,7 @@ class Grub2ConfigFile(_GrubConfigFile):
title_match = re.match('^menuentry ["\'](.*?)["\'] (.*){', l)
if title_match:
if img is not None:
- raise RuntimeError, "syntax error: cannot nest menuentry (%d %s)" % (len(img),img)
+ raise RuntimeError("syntax error: cannot nest menuentry (%d %s)" % (len(img),img))
img = []
title = title_match.group(1)
continue
@@ -413,7 +413,7 @@ class Grub2ConfigFile(_GrubConfigFile):
menu_level -= 1
continue
else:
- raise RuntimeError, "syntax error: closing brace without menuentry"
+ raise RuntimeError("syntax error: closing brace without menuentry")
self.add_image(Grub2Image(title, img))
img = None
@@ -428,7 +428,7 @@ class Grub2ConfigFile(_GrubConfigFile):
if com == "set":
(com,arg) = grub2_handle_set(arg)
- if self.commands.has_key(com):
+ if com in self.commands:
if self.commands[com] is not None:
arg_strip = arg.strip()
if arg_strip == "${saved_entry}" or arg_strip == "${next_entry}":
@@ -443,7 +443,7 @@ class Grub2ConfigFile(_GrubConfigFile):
logging.warning("Unknown directive %s" %(com,))
if img is not None:
- raise RuntimeError, "syntax error: end of file with open menuentry(%d %s)" % (len(img),img)
+ raise RuntimeError("syntax error: end of file with open menuentry(%d %s)" % (len(img),img))
if self.hasPassword():
self.setPasswordAccess(False)
@@ -462,12 +462,12 @@ class Grub2ConfigFile(_GrubConfigFile):
if __name__ == "__main__":
if len(sys.argv) < 3:
- raise RuntimeError, "Need a grub version (\"grub\" or \"grub2\") and a grub.conf or grub.cfg to read"
+ raise RuntimeError("Need a grub version (\"grub\" or \"grub2\") and a grub.conf or grub.cfg to read")
if sys.argv[1] == "grub":
g = GrubConfigFile(sys.argv[2])
elif sys.argv[1] == "grub2":
g = Grub2ConfigFile(sys.argv[2])
else:
- raise RuntimeError, "Unknown config type %s" % sys.argv[1]
+ raise RuntimeError("Unknown config type %s" % sys.argv[1])
for i in g.images:
- print i #, i.title, i.root, i.kernel, i.args, i.initrd
+ print(i) #, i.title, i.root, i.kernel, i.args, i.initrd
diff --git a/tools/pygrub/src/LiloConf.py b/tools/pygrub/src/LiloConf.py
index 2cb649f115..f4d26737f5 100644
--- a/tools/pygrub/src/LiloConf.py
+++ b/tools/pygrub/src/LiloConf.py
@@ -24,12 +24,13 @@ class LiloImage(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)
- if self.commands.has_key(com):
+ if com in self.commands:
if self.commands[com] is not None:
setattr(self, self.commands[com], re.sub('^"(.+)"$', r"\1", arg.strip()))
else:
@@ -97,7 +98,7 @@ class LiloConfigFile(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()
@@ -127,7 +128,7 @@ class LiloConfigFile(object):
continue
(com, arg) = GrubConf.grub_exact_split(l, 2)
- 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:
@@ -170,8 +171,8 @@ class LiloConfigFile(object):
if __name__ == "__main__":
if len(sys.argv) < 2:
- raise RuntimeError, "Need a lilo.conf to read"
+ raise RuntimeError("Need a lilo.conf to read")
g = LiloConfigFile(sys.argv[1])
for i in g.images:
- print i #, i.title, i.root, i.kernel, i.args, i.initrd
- print g.default
+ print(i) #, i.title, i.root, i.kernel, i.args, i.initrd
+ print(g.default)
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-03-06 17:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-06 17:52 [PATCH for-next v2 v2 0/5] tools: Python 3 compatibility Wei Liu
2019-03-06 17:52 ` [PATCH for-next v2 v2 1/5] build/m4: make python_devel.m4 work with both python 2 and 3 Wei Liu
2019-03-07 11:14 ` Anthony PERARD
2019-03-06 17:52 ` [PATCH for-next v2 v2 2/5] libxl: make python scripts work with python 2.6 and up Wei Liu
2019-03-06 18:20 ` Andrew Cooper
2019-03-06 20:58 ` Hans van Kranenburg
2019-03-07 10:37 ` Wei Liu
2019-03-07 11:30 ` Wei Liu
2019-03-06 17:52 ` Wei Liu [this message]
2019-03-06 18:23 ` [PATCH for-next v2 v2 3/5] pygrub: convert python scripts to work with " Andrew Cooper
2019-03-06 17:52 ` [PATCH for-next v2 v2 4/5] pygrub: make it build with python 3 Wei Liu
2019-03-06 18:46 ` Andrew Cooper
2019-03-06 17:52 ` [PATCH for-next v2 v2 5/5] Update python requirement Wei Liu
2019-03-07 11:21 ` Anthony PERARD
2019-03-07 11:24 ` Wei Liu
2019-03-06 18:17 ` [PATCH for-next v2 v2 0/5] tools: Python 3 compatibility Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190306175210.28145-4-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.