util: Port util to python3
This commit is the result of running 2to3 converter on the util subdirectory JIRA: https://gem5.atlassian.net/browse/GEM5-832 Change-Id: I4e7e2d2b1b99f7bcc5fe0f6dc5d25880323616eb Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/37797 Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2.7
|
||||
#!/usr/bin/python3
|
||||
#
|
||||
# Copyright 2020 Google, Inc.
|
||||
#
|
||||
@@ -57,7 +57,7 @@ debug = False
|
||||
def chsFromSize(sizeInBlocks):
|
||||
if sizeInBlocks >= MaxLBABlocks:
|
||||
sizeInMBs = (sizeInBlocks * BlockSize) / MB
|
||||
print '%d MB is too big for LBA, truncating file.' % sizeInMBs
|
||||
print('%d MB is too big for LBA, truncating file.' % sizeInMBs)
|
||||
return (MaxLBACylinders, MaxLBAHeads, MaxLBASectors)
|
||||
|
||||
sectors = sizeInBlocks
|
||||
@@ -79,12 +79,12 @@ def needSudo():
|
||||
if not hasattr(needSudo, 'notRoot'):
|
||||
needSudo.notRoot = (os.geteuid() != 0)
|
||||
if needSudo.notRoot:
|
||||
print 'You are not root. Using sudo.'
|
||||
print('You are not root. Using sudo.')
|
||||
return needSudo.notRoot
|
||||
|
||||
# Run an external command.
|
||||
def runCommand(command, inputVal=''):
|
||||
print "%>", ' '.join(command)
|
||||
print("%>", ' '.join(command))
|
||||
proc = Popen(command, stdin=PIPE)
|
||||
proc.communicate(inputVal)
|
||||
return proc.returncode
|
||||
@@ -94,7 +94,7 @@ def runCommand(command, inputVal=''):
|
||||
def getOutput(command, inputVal=''):
|
||||
global debug
|
||||
if debug:
|
||||
print "%>", ' '.join(command)
|
||||
print("%>", ' '.join(command))
|
||||
proc = Popen(command, stderr=STDOUT,
|
||||
stdin=PIPE, stdout=PIPE)
|
||||
(out, err) = proc.communicate(inputVal)
|
||||
@@ -132,7 +132,7 @@ class LoopbackDevice(object):
|
||||
assert not self.devFile
|
||||
(out, returncode) = privOutput([findProg('losetup'), '-f'])
|
||||
if returncode != 0:
|
||||
print out
|
||||
print(out)
|
||||
return returncode
|
||||
self.devFile = string.strip(out)
|
||||
command = [findProg('losetup'), self.devFile, fileName]
|
||||
@@ -157,7 +157,7 @@ def findPartOffset(devFile, fileName, partition):
|
||||
command = [findProg('sfdisk'), '-d', dev.devFile]
|
||||
(out, returncode) = privOutput(command)
|
||||
if returncode != 0:
|
||||
print out
|
||||
print(out)
|
||||
exit(returncode)
|
||||
lines = out.splitlines()
|
||||
# Make sure the first few lines of the output look like what we expect.
|
||||
@@ -182,7 +182,7 @@ def findPartOffset(devFile, fileName, partition):
|
||||
def mountPointToDev(mountPoint):
|
||||
(mountTable, returncode) = getOutput([findProg('mount')])
|
||||
if returncode != 0:
|
||||
print mountTable
|
||||
print(mountTable)
|
||||
exit(returncode)
|
||||
mountTable = mountTable.splitlines()
|
||||
for line in mountTable:
|
||||
@@ -249,7 +249,7 @@ mountCom = Command('mount', 'Mount the first partition in the disk image.',
|
||||
def mountComFunc(options, args):
|
||||
(path, mountPoint) = args
|
||||
if not os.path.isdir(mountPoint):
|
||||
print "Mount point %s is not a directory." % mountPoint
|
||||
print("Mount point %s is not a directory." % mountPoint)
|
||||
|
||||
dev = LoopbackDevice()
|
||||
if dev.setup(path, offset=True) != 0:
|
||||
@@ -268,12 +268,12 @@ umountCom = Command('umount', 'Unmount the first partition in the disk image.',
|
||||
def umountComFunc(options, args):
|
||||
(mountPoint,) = args
|
||||
if not os.path.isdir(mountPoint):
|
||||
print "Mount point %s is not a directory." % mountPoint
|
||||
print("Mount point %s is not a directory." % mountPoint)
|
||||
exit(1)
|
||||
|
||||
dev = mountPointToDev(mountPoint)
|
||||
if not dev:
|
||||
print "Unable to find mount information for %s." % mountPoint
|
||||
print("Unable to find mount information for %s." % mountPoint)
|
||||
|
||||
# Unmount the loopback device.
|
||||
if runPriv([findProg('umount'), mountPoint]) != 0:
|
||||
@@ -388,14 +388,14 @@ initCom.func = initComFunc
|
||||
|
||||
# Figure out what command was requested and execute it.
|
||||
if len(argv) < 2 or argv[1] not in commands:
|
||||
print 'Usage: %s [command] <command arguments>'
|
||||
print 'where [command] is one of '
|
||||
print('Usage: %s [command] <command arguments>')
|
||||
print('where [command] is one of ')
|
||||
for name in commandOrder:
|
||||
command = commands[name]
|
||||
print ' %s: %s' % (command.name, command.description)
|
||||
print 'Watch for orphaned loopback devices and delete them with'
|
||||
print 'losetup -d. Mounted images will belong to root, so you may need'
|
||||
print 'to use sudo to modify their contents.'
|
||||
print(' %s: %s' % (command.name, command.description))
|
||||
print('Watch for orphaned loopback devices and delete them with')
|
||||
print('losetup -d. Mounted images will belong to root, so you may need')
|
||||
print('to use sudo to modify their contents.')
|
||||
exit(1)
|
||||
|
||||
command = commands[argv[1]]
|
||||
|
||||
Reference in New Issue
Block a user