summaryrefslogtreecommitdiffstats
path: root/recipes-extended/xen/files/xen-tools-pygrub-make-python-scripts-work-with-2.6-and-up.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-extended/xen/files/xen-tools-pygrub-make-python-scripts-work-with-2.6-and-up.patch')
-rw-r--r--recipes-extended/xen/files/xen-tools-pygrub-make-python-scripts-work-with-2.6-and-up.patch529
1 files changed, 0 insertions, 529 deletions
diff --git a/recipes-extended/xen/files/xen-tools-pygrub-make-python-scripts-work-with-2.6-and-up.patch b/recipes-extended/xen/files/xen-tools-pygrub-make-python-scripts-work-with-2.6-and-up.patch
deleted file mode 100644
index f4cbb670..00000000
--- a/recipes-extended/xen/files/xen-tools-pygrub-make-python-scripts-work-with-2.6-and-up.patch
+++ /dev/null
@@ -1,529 +0,0 @@
1From 0aabd89dcfee9ee2a6caaa2ec7a475daf5cada53 Mon Sep 17 00:00:00 2001
2From: Wei Liu <wei.liu2@citrix.com>
3Date: Thu, 7 Mar 2019 12:45:47 +0000
4Subject: [PATCH] pygrub: make python scripts work with 2.6 and up
5
6Run 2to3 and pick the sensible suggestions.
7
8Import print_function and absolute_import so 2.6 can work.
9
10There has never been a curses.wrapper module according to 2.x and 3.x
11doc, only a function, so "import curses.wrapper" is not correct. It
12happened to work because 2.x implemented a (undocumented) module.
13
14We only need to import curses to make curses.wrapper available to
15pygrub.
16
17Signed-off-by: Wei Liu <wei.liu2@citrix.com>
18Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
19---
20 tools/pygrub/src/ExtLinuxConf.py | 19 +++++----
21 tools/pygrub/src/GrubConf.py | 39 ++++++++++--------
22 tools/pygrub/src/LiloConf.py | 19 +++++----
23 tools/pygrub/src/pygrub | 71 ++++++++++++++++----------------
24 4 files changed, 78 insertions(+), 70 deletions(-)
25
26diff --git a/tools/pygrub/src/ExtLinuxConf.py b/tools/pygrub/src/ExtLinuxConf.py
27index d1789bf020..9fd635b9cf 100644
28--- a/tools/pygrub/src/ExtLinuxConf.py
29+++ b/tools/pygrub/src/ExtLinuxConf.py
30@@ -10,9 +10,11 @@
31 # along with this program; If not, see <http://www.gnu.org/licenses/>.
32 #
33
34+from __future__ import print_function, absolute_import
35+
36 import sys, re, os
37 import logging
38-import GrubConf
39+from . import GrubConf
40
41 class ExtLinuxImage(object):
42 def __init__(self, lines, path):
43@@ -32,7 +34,8 @@ class ExtLinuxImage(object):
44 self.lines = []
45 self.path = path
46 self.root = ""
47- map(self.set_from_line, lines)
48+ for line in lines:
49+ self.set_from_line(line)
50
51 def set_from_line(self, line, replace = None):
52 (com, arg) = GrubConf.grub_exact_split(line, 2)
53@@ -67,7 +70,7 @@ class ExtLinuxImage(object):
54 setattr(self, "initrd", a.replace("initrd=", ""))
55 arg = arg.replace(a, "")
56
57- if com is not None and self.commands.has_key(com):
58+ if com is not None and com in self.commands:
59 if self.commands[com] is not None:
60 setattr(self, self.commands[com], re.sub('^"(.+)"$', r"\1", arg.strip()))
61 else:
62@@ -136,7 +139,7 @@ class ExtLinuxConfigFile(object):
63 def parse(self, buf = None):
64 if buf is None:
65 if self.filename is None:
66- raise ValueError, "No config file defined to parse!"
67+ raise ValueError("No config file defined to parse!")
68
69 f = open(self.filename, 'r')
70 lines = f.readlines()
71@@ -167,7 +170,7 @@ class ExtLinuxConfigFile(object):
72
73 (com, arg) = GrubConf.grub_exact_split(l, 2)
74 com = com.lower()
75- if self.commands.has_key(com):
76+ if com in self.commands:
77 if self.commands[com] is not None:
78 setattr(self, self.commands[com], arg.strip())
79 else:
80@@ -207,8 +210,8 @@ class ExtLinuxConfigFile(object):
81
82 if __name__ == "__main__":
83 if len(sys.argv) < 2:
84- raise RuntimeError, "Need a configuration file to read"
85+ raise RuntimeError("Need a configuration file to read")
86 g = ExtLinuxConfigFile(sys.argv[1])
87 for i in g.images:
88- print i
89- print g.default
90+ print(i)
91+ print(g.default)
92diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py
93index dc810d55cb..f8d3799dc0 100644
94--- a/tools/pygrub/src/GrubConf.py
95+++ b/tools/pygrub/src/GrubConf.py
96@@ -12,6 +12,8 @@
97 # along with this program; If not, see <http://www.gnu.org/licenses/>.
98 #
99
100+from __future__ import print_function, absolute_import
101+
102 import os, sys
103 import logging
104 import re
105@@ -44,7 +46,7 @@ def get_path(s):
106 return (None, s)
107 idx = s.find(')')
108 if idx == -1:
109- raise ValueError, "Unable to find matching ')'"
110+ raise ValueError("Unable to find matching ')'")
111 d = s[:idx]
112 return (GrubDiskPart(d), s[idx + 1:])
113
114@@ -100,7 +102,8 @@ class _GrubImage(object):
115 " initrd: %s\n" %(self.title, self.root, self.kernel,
116 self.args, self.initrd))
117 def _parse(self, lines):
118- map(self.set_from_line, lines)
119+ for line in lines:
120+ self.set_from_line(line)
121
122 def reset(self, lines):
123 self._root = self._initrd = self._kernel = self._args = None
124@@ -141,7 +144,7 @@ class GrubImage(_GrubImage):
125 def set_from_line(self, line, replace = None):
126 (com, arg) = grub_exact_split(line, 2)
127
128- if self.commands.has_key(com):
129+ if com in self.commands:
130 if self.commands[com] is not None:
131 setattr(self, self.commands[com], arg.strip())
132 else:
133@@ -177,7 +180,7 @@ class _GrubConfigFile(object):
134 self.parse()
135
136 def parse(self, buf = None):
137- raise RuntimeError, "unimplemented parse function"
138+ raise RuntimeError("unimplemented parse function")
139
140 def hasPasswordAccess(self):
141 return self.passwordAccess
142@@ -201,7 +204,7 @@ class _GrubConfigFile(object):
143 import crypt
144 if crypt.crypt(password, pwd[1]) == pwd[1]:
145 return True
146- except Exception, e:
147+ except Exception as e:
148 self.passExc = "Can't verify password: %s" % str(e)
149 return False
150
151@@ -213,7 +216,7 @@ class _GrubConfigFile(object):
152
153 def set(self, line):
154 (com, arg) = grub_exact_split(line, 2)
155- if self.commands.has_key(com):
156+ if com in self.commands:
157 if self.commands[com] is not None:
158 setattr(self, self.commands[com], arg.strip())
159 else:
160@@ -233,7 +236,7 @@ class _GrubConfigFile(object):
161 self._default = val
162
163 if self._default < 0:
164- raise ValueError, "default must be positive number"
165+ raise ValueError("default must be positive number")
166 default = property(_get_default, _set_default)
167
168 def set_splash(self, val):
169@@ -265,7 +268,7 @@ class GrubConfigFile(_GrubConfigFile):
170 def parse(self, buf = None):
171 if buf is None:
172 if self.filename is None:
173- raise ValueError, "No config file defined to parse!"
174+ raise ValueError("No config file defined to parse!")
175
176 f = open(self.filename, 'r')
177 lines = f.readlines()
178@@ -296,7 +299,7 @@ class GrubConfigFile(_GrubConfigFile):
179 continue
180
181 (com, arg) = grub_exact_split(l, 2)
182- if self.commands.has_key(com):
183+ if com in self.commands:
184 if self.commands[com] is not None:
185 setattr(self, self.commands[com], arg.strip())
186 else:
187@@ -328,7 +331,7 @@ class Grub2Image(_GrubImage):
188 if com == "set":
189 (com,arg) = grub2_handle_set(arg)
190
191- if self.commands.has_key(com):
192+ if com in self.commands:
193 if self.commands[com] is not None:
194 setattr(self, self.commands[com], arg.strip())
195 else:
196@@ -364,7 +367,7 @@ class Grub2ConfigFile(_GrubConfigFile):
197 def parse(self, buf = None):
198 if buf is None:
199 if self.filename is None:
200- raise ValueError, "No config file defined to parse!"
201+ raise ValueError("No config file defined to parse!")
202
203 f = open(self.filename, 'r')
204 lines = f.readlines()
205@@ -398,7 +401,7 @@ class Grub2ConfigFile(_GrubConfigFile):
206 title_match = re.match('^menuentry ["\'](.*?)["\'] (.*){', l)
207 if title_match:
208 if img is not None:
209- raise RuntimeError, "syntax error: cannot nest menuentry (%d %s)" % (len(img),img)
210+ raise RuntimeError("syntax error: cannot nest menuentry (%d %s)" % (len(img),img))
211 img = []
212 title = title_match.group(1)
213 continue
214@@ -413,7 +416,7 @@ class Grub2ConfigFile(_GrubConfigFile):
215 menu_level -= 1
216 continue
217 else:
218- raise RuntimeError, "syntax error: closing brace without menuentry"
219+ raise RuntimeError("syntax error: closing brace without menuentry")
220
221 self.add_image(Grub2Image(title, img))
222 img = None
223@@ -428,7 +431,7 @@ class Grub2ConfigFile(_GrubConfigFile):
224 if com == "set":
225 (com,arg) = grub2_handle_set(arg)
226
227- if self.commands.has_key(com):
228+ if com in self.commands:
229 if self.commands[com] is not None:
230 arg_strip = arg.strip()
231 if arg_strip == "${saved_entry}" or arg_strip == "${next_entry}":
232@@ -443,7 +446,7 @@ class Grub2ConfigFile(_GrubConfigFile):
233 logging.warning("Unknown directive %s" %(com,))
234
235 if img is not None:
236- raise RuntimeError, "syntax error: end of file with open menuentry(%d %s)" % (len(img),img)
237+ raise RuntimeError("syntax error: end of file with open menuentry(%d %s)" % (len(img),img))
238
239 if self.hasPassword():
240 self.setPasswordAccess(False)
241@@ -462,12 +465,12 @@ class Grub2ConfigFile(_GrubConfigFile):
242
243 if __name__ == "__main__":
244 if len(sys.argv) < 3:
245- raise RuntimeError, "Need a grub version (\"grub\" or \"grub2\") and a grub.conf or grub.cfg to read"
246+ raise RuntimeError('Need a grub version ("grub" or "grub2") and a grub.conf or grub.cfg to read')
247 if sys.argv[1] == "grub":
248 g = GrubConfigFile(sys.argv[2])
249 elif sys.argv[1] == "grub2":
250 g = Grub2ConfigFile(sys.argv[2])
251 else:
252- raise RuntimeError, "Unknown config type %s" % sys.argv[1]
253+ raise RuntimeError("Unknown config type %s" % sys.argv[1])
254 for i in g.images:
255- print i #, i.title, i.root, i.kernel, i.args, i.initrd
256+ print(i) #, i.title, i.root, i.kernel, i.args, i.initrd
257diff --git a/tools/pygrub/src/LiloConf.py b/tools/pygrub/src/LiloConf.py
258index 2cb649f115..e3bfcb5244 100644
259--- a/tools/pygrub/src/LiloConf.py
260+++ b/tools/pygrub/src/LiloConf.py
261@@ -2,9 +2,11 @@
262 #LiloConf.py
263 #
264
265+from __future__ import print_function, absolute_import
266+
267 import sys, re, os
268 import logging
269-import GrubConf
270+from . import GrubConf
271
272 class LiloImage(object):
273 def __init__(self, lines, path):
274@@ -24,12 +26,13 @@ class LiloImage(object):
275 self.lines = []
276 self.path = path
277 self.root = ""
278- map(self.set_from_line, lines)
279+ for line in lines:
280+ self.set_from_line(line)
281
282 def set_from_line(self, line, replace = None):
283 (com, arg) = GrubConf.grub_exact_split(line, 2)
284
285- if self.commands.has_key(com):
286+ if com in self.commands:
287 if self.commands[com] is not None:
288 setattr(self, self.commands[com], re.sub('^"(.+)"$', r"\1", arg.strip()))
289 else:
290@@ -97,7 +100,7 @@ class LiloConfigFile(object):
291 def parse(self, buf = None):
292 if buf is None:
293 if self.filename is None:
294- raise ValueError, "No config file defined to parse!"
295+ raise ValueError("No config file defined to parse!")
296
297 f = open(self.filename, 'r')
298 lines = f.readlines()
299@@ -127,7 +130,7 @@ class LiloConfigFile(object):
300 continue
301
302 (com, arg) = GrubConf.grub_exact_split(l, 2)
303- if self.commands.has_key(com):
304+ if com in self.commands:
305 if self.commands[com] is not None:
306 setattr(self, self.commands[com], arg.strip())
307 else:
308@@ -170,8 +173,8 @@ class LiloConfigFile(object):
309
310 if __name__ == "__main__":
311 if len(sys.argv) < 2:
312- raise RuntimeError, "Need a lilo.conf to read"
313+ raise RuntimeError("Need a lilo.conf to read")
314 g = LiloConfigFile(sys.argv[1])
315 for i in g.images:
316- print i #, i.title, i.root, i.kernel, i.args, i.initrd
317- print g.default
318+ print(i) #, i.title, i.root, i.kernel, i.args, i.initrd
319+ print(g.default)
320diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
321index 1189b1ca48..dbdce315c6 100755
322--- a/tools/pygrub/src/pygrub
323+++ b/tools/pygrub/src/pygrub
324@@ -12,13 +12,15 @@
325 # along with this program; If not, see <http://www.gnu.org/licenses/>.
326 #
327
328+from __future__ import print_function
329+
330 import os, sys, string, struct, tempfile, re, traceback, stat, errno
331 import copy
332 import logging
333 import platform
334 import xen.lowlevel.xc
335
336-import curses, _curses, curses.wrapper, curses.textpad, curses.ascii
337+import curses, _curses, curses.textpad, curses.ascii
338 import getopt
339
340 import xenfsimage
341@@ -77,7 +79,7 @@ def get_solaris_slice(file, offset):
342 buf = os.read(fd, 512)
343 os.close(fd)
344 if struct.unpack("<H", buf[508:510])[0] != DKL_MAGIC:
345- raise RuntimeError, "Invalid disklabel magic"
346+ raise RuntimeError("Invalid disklabel magic")
347
348 nslices = struct.unpack("<H", buf[30:32])[0]
349
350@@ -88,7 +90,7 @@ def get_solaris_slice(file, offset):
351 if slicetag == V_ROOT:
352 return slicesect * SECTOR_SIZE
353
354- raise RuntimeError, "No root slice found"
355+ raise RuntimeError("No root slice found")
356
357 def get_fs_offset_gpt(file):
358 fd = os.open(file, os.O_RDONLY)
359@@ -423,20 +425,17 @@ class Grub:
360 we're being given a raw config file rather than a disk image."""
361
362 if not os.access(fn, os.R_OK):
363- raise RuntimeError, "Unable to access %s" %(fn,)
364+ raise RuntimeError("Unable to access %s" %(fn,))
365
366- cfg_list = map(lambda x: (x,grub.GrubConf.Grub2ConfigFile),
367- ["/boot/grub/grub.cfg", "/grub/grub.cfg",
368- "/boot/grub2/grub.cfg", "/grub2/grub.cfg"]) + \
369- map(lambda x: (x,grub.ExtLinuxConf.ExtLinuxConfigFile),
370- ["/boot/isolinux/isolinux.cfg",
371+ cfg_list = [(x,grub.GrubConf.Grub2ConfigFile) for x in ["/boot/grub/grub.cfg", "/grub/grub.cfg",
372+ "/boot/grub2/grub.cfg", "/grub2/grub.cfg"]] + \
373+ [(x,grub.ExtLinuxConf.ExtLinuxConfigFile) for x in ["/boot/isolinux/isolinux.cfg",
374 "/boot/extlinux/extlinux.conf",
375 "/boot/extlinux.conf",
376 "/extlinux/extlinux.conf",
377- "/extlinux.conf"]) + \
378- map(lambda x: (x,grub.GrubConf.GrubConfigFile),
379- ["/boot/grub/menu.lst", "/boot/grub/grub.conf",
380- "/grub/menu.lst", "/grub/grub.conf"])
381+ "/extlinux.conf"]] + \
382+ [(x,grub.GrubConf.GrubConfigFile) for x in ["/boot/grub/menu.lst", "/boot/grub/grub.conf",
383+ "/grub/menu.lst", "/grub/grub.conf"]]
384
385 if not fs:
386 # set the config file and parse it
387@@ -448,12 +447,12 @@ class Grub:
388
389 for f,parser in cfg_list:
390 if fs.file_exists(f):
391- print >>sys.stderr, "Using %s to parse %s" % (parser,f)
392+ print("Using %s to parse %s" % (parser,f), file=sys.stderr)
393 self.cf = parser()
394 self.cf.filename = f
395 break
396 if self.__dict__.get('cf', None) is None:
397- raise RuntimeError, "couldn't find bootloader config file in the image provided."
398+ raise RuntimeError("couldn't find bootloader config file in the image provided.")
399 f = fs.open_file(self.cf.filename)
400 # limit read size to avoid pathological cases
401 buf = f.read(FS_READ_MAX)
402@@ -628,11 +627,11 @@ def run_grub(file, entry, fs, cfg_args):
403 if list_entries:
404 for i in range(len(g.cf.images)):
405 img = g.cf.images[i]
406- print "title: %s" % img.title
407- print " root: %s" % img.root
408- print " kernel: %s" % img.kernel[1]
409- print " args: %s" % img.args
410- print " initrd: %s" % img.initrd[1]
411+ print("title: %s" % img.title)
412+ print(" root: %s" % img.root)
413+ print(" kernel: %s" % img.kernel[1])
414+ print(" args: %s" % img.args)
415+ print(" initrd: %s" % img.initrd[1])
416
417 if interactive and not list_entries:
418 curses.wrapper(run_main)
419@@ -646,7 +645,7 @@ def run_grub(file, entry, fs, cfg_args):
420 sel = idx
421
422 if sel == -1:
423- print "No kernel image selected!"
424+ print("No kernel image selected!")
425 sys.exit(1)
426
427 try:
428@@ -731,7 +730,7 @@ def format_sxp(kernel, ramdisk, args):
429 def format_simple(kernel, ramdisk, args, sep):
430 for check in (kernel, ramdisk, args):
431 if check is not None and sep in check:
432- raise RuntimeError, "simple format cannot represent delimiter-containing value"
433+ raise RuntimeError("simple format cannot represent delimiter-containing value")
434 s = ("kernel %s" % kernel) + sep
435 if ramdisk:
436 s += ("ramdisk %s" % ramdisk) + sep
437@@ -744,7 +743,7 @@ if __name__ == "__main__":
438 sel = None
439
440 def usage():
441- 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] [--offset=] <image>" %(sys.argv[0],)
442+ print("Usage: %s [-q|--quiet] [-i|--interactive] [-l|--list-entries] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] [--output-directory=] [--output-format=sxp|simple|simple0] [--offset=] <image>" %(sys.argv[0],), file=sys.stderr)
443
444 def copy_from_image(fs, file_to_read, file_type, output_directory,
445 not_really):
446@@ -755,8 +754,8 @@ if __name__ == "__main__":
447 sys.exit("The requested %s file does not exist" % file_type)
448 try:
449 datafile = fs.open_file(file_to_read)
450- except Exception, e:
451- print >>sys.stderr, e
452+ except Exception as e:
453+ print(e, file=sys.stderr)
454 sys.exit("Error opening %s in guest" % file_to_read)
455 (tfd, ret) = tempfile.mkstemp(prefix="boot_"+file_type+".",
456 dir=output_directory)
457@@ -769,8 +768,8 @@ if __name__ == "__main__":
458 return ret
459 try:
460 os.write(tfd, data)
461- except Exception, e:
462- print >>sys.stderr, e
463+ except Exception as e:
464+ print(e, file=sys.stderr)
465 os.close(tfd)
466 os.unlink(ret)
467 del datafile
468@@ -834,7 +833,7 @@ if __name__ == "__main__":
469 try:
470 part_offs = [ int(a) ]
471 except ValueError:
472- print "offset value must be an integer"
473+ print("offset value must be an integer")
474 usage()
475 sys.exit(1)
476 elif o in ("--entry",):
477@@ -847,13 +846,13 @@ if __name__ == "__main__":
478 debug = True
479 elif o in ("--output-format",):
480 if a not in ["sxp", "simple", "simple0"]:
481- print "unknown output format %s" % a
482+ print("unknown output format %s" % a)
483 usage()
484 sys.exit(1)
485 output_format = a
486 elif o in ("--output-directory",):
487 if not os.path.isdir(a):
488- print "%s is not an existing directory" % a
489+ print("%s is not an existing directory" % a)
490 sys.exit(1)
491 output_directory = a
492
493@@ -862,8 +861,8 @@ if __name__ == "__main__":
494
495
496 try:
497- os.makedirs(output_directory, 0700)
498- except OSError,e:
499+ os.makedirs(output_directory, 0o700)
500+ except OSError as e:
501 if (e.errno == errno.EEXIST) and os.path.isdir(output_directory):
502 pass
503 else:
504@@ -877,10 +876,10 @@ if __name__ == "__main__":
505 # debug
506 if isconfig:
507 chosencfg = run_grub(file, entry, fs, incfg["args"])
508- print " kernel: %s" % chosencfg["kernel"]
509+ print(" kernel: %s" % chosencfg["kernel"])
510 if chosencfg["ramdisk"]:
511- print " initrd: %s" % chosencfg["ramdisk"]
512- print " args: %s" % chosencfg["args"]
513+ print(" initrd: %s" % chosencfg["ramdisk"])
514+ print(" args: %s" % chosencfg["args"])
515 sys.exit(0)
516
517 # if boot filesystem is set then pass to fsimage.open
518@@ -926,7 +925,7 @@ if __name__ == "__main__":
519
520 # Did looping through partitions find us a kernel?
521 if fs is None:
522- raise RuntimeError, "Unable to find partition containing kernel"
523+ raise RuntimeError("Unable to find partition containing kernel")
524
525 bootcfg["kernel"] = copy_from_image(fs, chosencfg["kernel"], "kernel",
526 output_directory, not_really)
527--
5282.17.1
529