Richard Cooper has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/39895 )

Change subject: util: Update util/gem5img.py to work with Python 3.
......................................................................

util: Update util/gem5img.py to work with Python 3.

Tested on Ubuntu 18.04 with Python 3.6.8 and Python 2.7.15+.

Change-Id: Ic8b407ad41dc0d6d37a54a54eeef2b9156d893d6
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39895
Reviewed-by: Bobby R. Bruce <[email protected]>
Maintainer: Bobby R. Bruce <[email protected]>
Tested-by: kokoro <[email protected]>
---
M util/gem5img.py
1 file changed, 8 insertions(+), 8 deletions(-)

Approvals:
  Bobby R. Bruce: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/util/gem5img.py b/util/gem5img.py
index 03d1f3f..26f398e 100755
--- a/util/gem5img.py
+++ b/util/gem5img.py
@@ -86,7 +86,7 @@
 def runCommand(command, inputVal=''):
     print("%>", ' '.join(command))
     proc = Popen(command, stdin=PIPE)
-    proc.communicate(inputVal)
+    proc.communicate(inputVal.encode())
     return proc.returncode

 # Run an external command and capture its output. This is intended to be
@@ -98,7 +98,7 @@
     proc = Popen(command, stderr=STDOUT,
                  stdin=PIPE, stdout=PIPE)
     (out, err) = proc.communicate(inputVal)
-    return (out, proc.returncode)
+    return (out.decode(), proc.returncode)

 # Run a command as root, using sudo if necessary.
 def runPriv(command, inputVal=''):
@@ -120,7 +120,7 @@
         if cleanupDev:
             cleanupDev.destroy()
exit("Unable to find program %s, check your PATH variable." % program)
-    return string.strip(out)
+    return out.strip()

 class LoopbackDevice(object):
     def __init__(self, devFile=None):
@@ -134,7 +134,7 @@
         if returncode != 0:
             print(out)
             return returncode
-        self.devFile = string.strip(out)
+        self.devFile = out.strip()
         command = [findProg('losetup'), self.devFile, fileName]
         if offset:
             off = findPartOffset(self.devFile, fileName, 0)
@@ -174,7 +174,7 @@
         chunks = lines[5].split()
# The fourth chunk is the offset of the partition in sectors followed by
     # a comma. We drop the comma and convert that to an integer.
-    sectors = string.atoi(chunks[3][:-1])
+    sectors = int(chunks[3][:-1])
     # Free the loopback device and return an answer.
     dev.destroy()
     return sectors * BlockSize
@@ -299,11 +299,11 @@
     # store to disk and which is defined to read as zero.
     fd = os.open(file, os.O_WRONLY | os.O_CREAT)
     os.lseek(fd, size - 1, os.SEEK_SET)
-    os.write(fd, '\0')
+    os.write(fd, b'\0')

 def newComFunc(options, args):
     (file, mb) = args
-    mb = string.atoi(mb)
+    mb = int(mb)
     newImage(file, mb)


@@ -366,7 +366,7 @@

 def initComFunc(options, args):
     (path, mb) = args
-    mb = string.atoi(mb)
+    mb = int(mb)
     newImage(path, mb)
     dev = LoopbackDevice()
     if dev.setup(path) != 0:

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/39895
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ic8b407ad41dc0d6d37a54a54eeef2b9156d893d6
Gerrit-Change-Number: 39895
Gerrit-PatchSet: 5
Gerrit-Owner: Richard Cooper <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Richard Cooper <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to