[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH for-next v2 v2 3/5] pygrub: convert python scripts to work with 2.6 and up
Run 2to3 and pick the sensible suggestions. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- 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@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |