Skip to content

Commit f10994a

Browse files
chore!: Migrate to Python 3
BREAKING CHANGE: drop support for Python 2 Signed-off-by: Justin Hendrick <justinjhendrick@gmail.com>
1 parent 401323a commit f10994a

26 files changed

+263
-401
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
250250

251251
gen-out-type = $(subst .,-,$(suffix $@))
252252

253-
qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
253+
qapi-py = $(SRC_PATH)/scripts/qapi.py
254254

255255
qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h :\
256256
$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)

configure

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,8 @@ fi
11861186

11871187
# Note that if the Python conditional here evaluates True we will exit
11881188
# with status 1 which is a shell 'false' value.
1189-
if ! $python -c 'import sys; sys.exit(sys.version_info < (2,6) or sys.version_info >= (3,))'; then
1190-
error_exit "Cannot use '$python', Python 2.6 or later is required." \
1191-
"Note that Python 3 or later is not yet supported." \
1189+
if ! $python -c 'import sys; sys.exit(sys.version_info < (3,8))'; then
1190+
error_exit "Cannot use '$python', Python 3.8 or later is required." \
11921191
"Use --python=/path/to/python to specify a supported Python."
11931192
fi
11941193

pebble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
if args.vnc_ws:
5555
cmd_line += "-vnc :1,websocket=4444 "
5656

57-
print "Executing command line: \n ", cmd_line
57+
print("Executing command line: \n ", cmd_line)
5858
os.system(cmd_line)
5959

6060

scripts/acpi_extract.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@ def aml_package_start(offset):
252252
lineno = lineno + 1
253253
debug = "input line %d: %s" % (lineno, line)
254254
#ASL listing: space, then line#, then ...., then code
255-
pasl = re.compile('^\s+([0-9]+)(:\s\s|\.\.\.\.)\s*')
255+
pasl = re.compile(r'^\s+([0-9]+)(:\s\s|\.\.\.\.)\s*')
256256
m = pasl.search(line)
257257
if (m):
258258
add_asl(lineno, pasl.sub("", line));
259259
# AML listing: offset in hex, then ...., then code
260-
paml = re.compile('^([0-9A-Fa-f]+)(:\s\s|\.\.\.\.)\s*')
260+
paml = re.compile(r'^([0-9A-Fa-f]+)(:\s\s|\.\.\.\.)\s*')
261261
m = paml.search(line)
262262
if (m):
263263
add_aml(m.group(1), paml.sub("", line))
@@ -357,7 +357,7 @@ def get_value_type(maxvalue):
357357
return "char"
358358

359359
# Pretty print output
360-
for array in output.keys():
360+
for array in list(output.keys()):
361361
otype = get_value_type(max(output[array]))
362362
odata = []
363363
for value in output[array]:

scripts/analyse-9p-simpletrace.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -79,135 +79,135 @@
7979

8080
class VirtFSRequestTracker(simpletrace.Analyzer):
8181
def begin(self):
82-
print "Pretty printing 9p simpletrace log ..."
82+
print("Pretty printing 9p simpletrace log ...")
8383

8484
def v9fs_rerror(self, tag, id, err):
85-
print "RERROR (tag =", tag, ", id =", symbol_9p[id], ", err = \"", os.strerror(err), "\")"
85+
print("RERROR (tag =", tag, ", id =", symbol_9p[id], ", err = \"", os.strerror(err), "\")")
8686

8787
def v9fs_version(self, tag, id, msize, version):
88-
print "TVERSION (tag =", tag, ", msize =", msize, ", version =", version, ")"
88+
print("TVERSION (tag =", tag, ", msize =", msize, ", version =", version, ")")
8989

9090
def v9fs_version_return(self, tag, id, msize, version):
91-
print "RVERSION (tag =", tag, ", msize =", msize, ", version =", version, ")"
91+
print("RVERSION (tag =", tag, ", msize =", msize, ", version =", version, ")")
9292

9393
def v9fs_attach(self, tag, id, fid, afid, uname, aname):
94-
print "TATTACH (tag =", tag, ", fid =", fid, ", afid =", afid, ", uname =", uname, ", aname =", aname, ")"
94+
print("TATTACH (tag =", tag, ", fid =", fid, ", afid =", afid, ", uname =", uname, ", aname =", aname, ")")
9595

9696
def v9fs_attach_return(self, tag, id, type, version, path):
97-
print "RATTACH (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "})"
97+
print("RATTACH (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "})")
9898

9999
def v9fs_stat(self, tag, id, fid):
100-
print "TSTAT (tag =", tag, ", fid =", fid, ")"
100+
print("TSTAT (tag =", tag, ", fid =", fid, ")")
101101

102102
def v9fs_stat_return(self, tag, id, mode, atime, mtime, length):
103-
print "RSTAT (tag =", tag, ", mode =", mode, ", atime =", atime, ", mtime =", mtime, ", length =", length, ")"
103+
print("RSTAT (tag =", tag, ", mode =", mode, ", atime =", atime, ", mtime =", mtime, ", length =", length, ")")
104104

105105
def v9fs_getattr(self, tag, id, fid, request_mask):
106-
print "TGETATTR (tag =", tag, ", fid =", fid, ", request_mask =", hex(request_mask), ")"
106+
print("TGETATTR (tag =", tag, ", fid =", fid, ", request_mask =", hex(request_mask), ")")
107107

108108
def v9fs_getattr_return(self, tag, id, result_mask, mode, uid, gid):
109-
print "RGETATTR (tag =", tag, ", result_mask =", hex(result_mask), ", mode =", oct(mode), ", uid =", uid, ", gid =", gid, ")"
109+
print("RGETATTR (tag =", tag, ", result_mask =", hex(result_mask), ", mode =", oct(mode), ", uid =", uid, ", gid =", gid, ")")
110110

111111
def v9fs_walk(self, tag, id, fid, newfid, nwnames):
112-
print "TWALK (tag =", tag, ", fid =", fid, ", newfid =", newfid, ", nwnames =", nwnames, ")"
112+
print("TWALK (tag =", tag, ", fid =", fid, ", newfid =", newfid, ", nwnames =", nwnames, ")")
113113

114114
def v9fs_walk_return(self, tag, id, nwnames, qids):
115-
print "RWALK (tag =", tag, ", nwnames =", nwnames, ", qids =", hex(qids), ")"
115+
print("RWALK (tag =", tag, ", nwnames =", nwnames, ", qids =", hex(qids), ")")
116116

117117
def v9fs_open(self, tag, id, fid, mode):
118-
print "TOPEN (tag =", tag, ", fid =", fid, ", mode =", oct(mode), ")"
118+
print("TOPEN (tag =", tag, ", fid =", fid, ", mode =", oct(mode), ")")
119119

120120
def v9fs_open_return(self, tag, id, type, version, path, iounit):
121-
print "ROPEN (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, iounit =", iounit, ")"
121+
print("ROPEN (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, iounit =", iounit, ")")
122122

123123
def v9fs_lcreate(self, tag, id, dfid, flags, mode, gid):
124-
print "TLCREATE (tag =", tag, ", dfid =", dfid, ", flags =", oct(flags), ", mode =", oct(mode), ", gid =", gid, ")"
124+
print("TLCREATE (tag =", tag, ", dfid =", dfid, ", flags =", oct(flags), ", mode =", oct(mode), ", gid =", gid, ")")
125125

126126
def v9fs_lcreate_return(self, tag, id, type, version, path, iounit):
127-
print "RLCREATE (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, iounit =", iounit, ")"
127+
print("RLCREATE (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, iounit =", iounit, ")")
128128

129129
def v9fs_fsync(self, tag, id, fid, datasync):
130-
print "TFSYNC (tag =", tag, ", fid =", fid, ", datasync =", datasync, ")"
130+
print("TFSYNC (tag =", tag, ", fid =", fid, ", datasync =", datasync, ")")
131131

132132
def v9fs_clunk(self, tag, id, fid):
133-
print "TCLUNK (tag =", tag, ", fid =", fid, ")"
133+
print("TCLUNK (tag =", tag, ", fid =", fid, ")")
134134

135135
def v9fs_read(self, tag, id, fid, off, max_count):
136-
print "TREAD (tag =", tag, ", fid =", fid, ", off =", off, ", max_count =", max_count, ")"
136+
print("TREAD (tag =", tag, ", fid =", fid, ", off =", off, ", max_count =", max_count, ")")
137137

138138
def v9fs_read_return(self, tag, id, count, err):
139-
print "RREAD (tag =", tag, ", count =", count, ", err =", err, ")"
139+
print("RREAD (tag =", tag, ", count =", count, ", err =", err, ")")
140140

141141
def v9fs_readdir(self, tag, id, fid, offset, max_count):
142-
print "TREADDIR (tag =", tag, ", fid =", fid, ", offset =", offset, ", max_count =", max_count, ")"
142+
print("TREADDIR (tag =", tag, ", fid =", fid, ", offset =", offset, ", max_count =", max_count, ")")
143143

144144
def v9fs_readdir_return(self, tag, id, count, retval):
145-
print "RREADDIR (tag =", tag, ", count =", count, ", retval =", retval, ")"
145+
print("RREADDIR (tag =", tag, ", count =", count, ", retval =", retval, ")")
146146

147147
def v9fs_write(self, tag, id, fid, off, count, cnt):
148-
print "TWRITE (tag =", tag, ", fid =", fid, ", off =", off, ", count =", count, ", cnt =", cnt, ")"
148+
print("TWRITE (tag =", tag, ", fid =", fid, ", off =", off, ", count =", count, ", cnt =", cnt, ")")
149149

150150
def v9fs_write_return(self, tag, id, total, err):
151-
print "RWRITE (tag =", tag, ", total =", total, ", err =", err, ")"
151+
print("RWRITE (tag =", tag, ", total =", total, ", err =", err, ")")
152152

153153
def v9fs_create(self, tag, id, fid, name, perm, mode):
154-
print "TCREATE (tag =", tag, ", fid =", fid, ", perm =", oct(perm), ", name =", name, ", mode =", oct(mode), ")"
154+
print("TCREATE (tag =", tag, ", fid =", fid, ", perm =", oct(perm), ", name =", name, ", mode =", oct(mode), ")")
155155

156156
def v9fs_create_return(self, tag, id, type, version, path, iounit):
157-
print "RCREATE (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, iounit =", iounit, ")"
157+
print("RCREATE (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, iounit =", iounit, ")")
158158

159159
def v9fs_symlink(self, tag, id, fid, name, symname, gid):
160-
print "TSYMLINK (tag =", tag, ", fid =", fid, ", name =", name, ", symname =", symname, ", gid =", gid, ")"
160+
print("TSYMLINK (tag =", tag, ", fid =", fid, ", name =", name, ", symname =", symname, ", gid =", gid, ")")
161161

162162
def v9fs_symlink_return(self, tag, id, type, version, path):
163-
print "RSYMLINK (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "})"
163+
print("RSYMLINK (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "})")
164164

165165
def v9fs_flush(self, tag, id, flush_tag):
166-
print "TFLUSH (tag =", tag, ", flush_tag =", flush_tag, ")"
166+
print("TFLUSH (tag =", tag, ", flush_tag =", flush_tag, ")")
167167

168168
def v9fs_link(self, tag, id, dfid, oldfid, name):
169-
print "TLINK (tag =", tag, ", dfid =", dfid, ", oldfid =", oldfid, ", name =", name, ")"
169+
print("TLINK (tag =", tag, ", dfid =", dfid, ", oldfid =", oldfid, ", name =", name, ")")
170170

171171
def v9fs_remove(self, tag, id, fid):
172-
print "TREMOVE (tag =", tag, ", fid =", fid, ")"
172+
print("TREMOVE (tag =", tag, ", fid =", fid, ")")
173173

174174
def v9fs_wstat(self, tag, id, fid, mode, atime, mtime):
175-
print "TWSTAT (tag =", tag, ", fid =", fid, ", mode =", oct(mode), ", atime =", atime, "mtime =", mtime, ")"
175+
print("TWSTAT (tag =", tag, ", fid =", fid, ", mode =", oct(mode), ", atime =", atime, "mtime =", mtime, ")")
176176

177177
def v9fs_mknod(self, tag, id, fid, mode, major, minor):
178-
print "TMKNOD (tag =", tag, ", fid =", fid, ", mode =", oct(mode), ", major =", major, ", minor =", minor, ")"
178+
print("TMKNOD (tag =", tag, ", fid =", fid, ", mode =", oct(mode), ", major =", major, ", minor =", minor, ")")
179179

180180
def v9fs_lock(self, tag, id, fid, type, start, length):
181-
print "TLOCK (tag =", tag, ", fid =", fid, "type =", type, ", start =", start, ", length =", length, ")"
181+
print("TLOCK (tag =", tag, ", fid =", fid, "type =", type, ", start =", start, ", length =", length, ")")
182182

183183
def v9fs_lock_return(self, tag, id, status):
184-
print "RLOCK (tag =", tag, ", status =", status, ")"
184+
print("RLOCK (tag =", tag, ", status =", status, ")")
185185

186186
def v9fs_getlock(self, tag, id, fid, type, start, length):
187-
print "TGETLOCK (tag =", tag, ", fid =", fid, "type =", type, ", start =", start, ", length =", length, ")"
187+
print("TGETLOCK (tag =", tag, ", fid =", fid, "type =", type, ", start =", start, ", length =", length, ")")
188188

189189
def v9fs_getlock_return(self, tag, id, type, start, length, proc_id):
190-
print "RGETLOCK (tag =", tag, "type =", type, ", start =", start, ", length =", length, ", proc_id =", proc_id, ")"
190+
print("RGETLOCK (tag =", tag, "type =", type, ", start =", start, ", length =", length, ", proc_id =", proc_id, ")")
191191

192192
def v9fs_mkdir(self, tag, id, fid, name, mode, gid):
193-
print "TMKDIR (tag =", tag, ", fid =", fid, ", name =", name, ", mode =", mode, ", gid =", gid, ")"
193+
print("TMKDIR (tag =", tag, ", fid =", fid, ", name =", name, ", mode =", mode, ", gid =", gid, ")")
194194

195195
def v9fs_mkdir_return(self, tag, id, type, version, path, err):
196-
print "RMKDIR (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, err =", err, ")"
196+
print("RMKDIR (tag =", tag, ", qid={type =", type, ", version =", version, ", path =", path, "}, err =", err, ")")
197197

198198
def v9fs_xattrwalk(self, tag, id, fid, newfid, name):
199-
print "TXATTRWALK (tag =", tag, ", fid =", fid, ", newfid =", newfid, ", xattr name =", name, ")"
199+
print("TXATTRWALK (tag =", tag, ", fid =", fid, ", newfid =", newfid, ", xattr name =", name, ")")
200200

201201
def v9fs_xattrwalk_return(self, tag, id, size):
202-
print "RXATTRWALK (tag =", tag, ", xattrsize =", size, ")"
202+
print("RXATTRWALK (tag =", tag, ", xattrsize =", size, ")")
203203

204204
def v9fs_xattrcreate(self, tag, id, fid, name, size, flags):
205-
print "TXATTRCREATE (tag =", tag, ", fid =", fid, ", name =", name, ", xattrsize =", size, ", flags =", flags, ")"
205+
print("TXATTRCREATE (tag =", tag, ", fid =", fid, ", name =", name, ", xattrsize =", size, ", flags =", flags, ")")
206206

207207
def v9fs_readlink(self, tag, id, fid):
208-
print "TREADLINK (tag =", tag, ", fid =", fid, ")"
208+
print("TREADLINK (tag =", tag, ", fid =", fid, ")")
209209

210210
def v9fs_readlink_return(self, tag, id, target):
211-
print "RREADLINK (tag =", tag, ", target =", target, ")"
211+
print("RREADLINK (tag =", tag, ", target =", target, ")")
212212

213213
simpletrace.run(VirtFSRequestTracker())

scripts/analyze-migration.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def read_migration_debug_json(self):
8686

8787
# Find the last NULL byte, then the first brace after that. This should
8888
# be the beginning of our JSON data.
89-
nulpos = data.rfind("\0")
90-
jsonpos = data.find("{", nulpos)
89+
nulpos = data.rfind(b"\0")
90+
jsonpos = data.find(b"{", nulpos)
9191

9292
# Check backwards from there and see whether we guessed right
9393
self.file.seek(datapos + jsonpos - 5, 0)
@@ -162,7 +162,7 @@ def read(self):
162162
len = self.file.read64()
163163
self.sizeinfo[self.name] = '0x%016x' % len
164164
if self.write_memory:
165-
print self.name
165+
print(self.name)
166166
mkdir_p('./' + os.path.dirname(self.name))
167167
f = open('./' + self.name, "wb")
168168
f.truncate(0)
@@ -359,7 +359,7 @@ def __init__(self, desc, file):
359359
array_len = field.pop('array_len')
360360
field['index'] = 0
361361
new_fields.append(field)
362-
for i in xrange(1, array_len):
362+
for i in range(1, array_len):
363363
c = field.copy()
364364
c['index'] = i
365365
new_fields.append(c)
@@ -426,7 +426,7 @@ def getDictArray(self, array):
426426

427427
def getDictOrderedDict(self, dict):
428428
r = collections.OrderedDict()
429-
for (key, value) in dict.items():
429+
for (key, value) in list(dict.items()):
430430
r[key] = self.getDictItem(value)
431431
return r
432432

@@ -558,7 +558,7 @@ def load_vmsd_json(self, file):
558558

559559
def getDict(self):
560560
r = collections.OrderedDict()
561-
for (key, value) in self.sections.items():
561+
for (key, value) in list(self.sections.items()):
562562
key = "%s (%d)" % ( value.section_key[0], key )
563563
r[key] = value.getDict()
564564
return r
@@ -584,15 +584,15 @@ def default(self, o):
584584
dump = MigrationDump(args.file)
585585

586586
dump.read(desc_only = True)
587-
print "desc.json"
587+
print("desc.json")
588588
f = open("desc.json", "wb")
589589
f.truncate()
590590
f.write(jsonenc.encode(dump.vmsd_desc))
591591
f.close()
592592

593593
dump.read(write_memory = True)
594594
dict = dump.getDict()
595-
print "state.json"
595+
print("state.json")
596596
f = open("state.json", "wb")
597597
f.truncate()
598598
f.write(jsonenc.encode(dict))
@@ -601,10 +601,10 @@ def default(self, o):
601601
dump = MigrationDump(args.file)
602602
dump.read(dump_memory = args.memory)
603603
dict = dump.getDict()
604-
print jsonenc.encode(dict)
604+
print(jsonenc.encode(dict))
605605
elif args.dump == "desc":
606606
dump = MigrationDump(args.file)
607607
dump.read(desc_only = True)
608-
print jsonenc.encode(dump.vmsd_desc)
608+
print(jsonenc.encode(dump.vmsd_desc))
609609
else:
610610
raise Exception("Please specify either -x, -d state or -d dump")

scripts/dump-guest-memory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def guest_phys_blocks_init(self):
136136
self.guest_phys_blocks = []
137137

138138
def guest_phys_blocks_append(self):
139-
print "guest RAM blocks:"
139+
print("guest RAM blocks:")
140140
print ("target_start target_end host_addr message "
141141
"count")
142142
print ("---------------- ---------------- ---------------- ------- "
@@ -187,9 +187,9 @@ def guest_phys_blocks_append(self):
187187
predecessor["target_end"] = target_end
188188
message = "joined"
189189

190-
print ("%016x %016x %016x %-7s %5u" %
190+
print(("%016x %016x %016x %-7s %5u" %
191191
(target_start, target_end, host_addr.cast(self.uintptr_t),
192-
message, len(self.guest_phys_blocks)))
192+
message, len(self.guest_phys_blocks))))
193193

194194
def cpu_get_dump_info(self):
195195
# We can't synchronize the registers with KVM post-mortem, and
@@ -309,8 +309,8 @@ def dump_iterate(self, vmcore):
309309
for block in self.guest_phys_blocks:
310310
cur = block["host_addr"]
311311
left = block["target_end"] - block["target_start"]
312-
print ("dumping range at %016x for length %016x" %
313-
(cur.cast(self.uintptr_t), left))
312+
print(("dumping range at %016x for length %016x" %
313+
(cur.cast(self.uintptr_t), left)))
314314
while (left > 0):
315315
chunk_size = min(self.TARGET_PAGE_SIZE, left)
316316
chunk = qemu_core.read_memory(cur, chunk_size)

0 commit comments

Comments
 (0)