Skip to content

Python3 fixes#24

Merged
mika merged 2 commits into
grml:masterfrom
zwenna:python3-fixes
Oct 30, 2019
Merged

Python3 fixes#24
mika merged 2 commits into
grml:masterfrom
zwenna:python3-fixes

Conversation

@zwenna
Copy link
Copy Markdown
Contributor

@zwenna zwenna commented Oct 30, 2019

Two small but crucial fixes which let grml2usb actually run sucessfuly under Python 3. See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=943838.

By default Subprocess.open() opens file objects in binary mode, so the
"filesystem" variable is an array of bytes, and comparing it to a
string always yields false.  Fix that by explicitly opening the stream
in text mode.
By default open() reads in text which is not going to fly for a boot
sector.

Fatal: 'utf-8' codec can't decode byte 0x90 in position 6: invalid start byte
Exception:
Traceback (most recent call last):
  File "/usr/sbin/grml2usb", line 1913, in main
    install(iso, device)
  File "/usr/sbin/grml2usb", line 1626, in install
    install_grml(iso_mountpoint, device)
  File "/usr/sbin/grml2usb", line 1653, in install_grml
    check_boot_flag(device)
  File "/usr/sbin/grml2usb", line 393, in check_boot_flag
    data = image.read(520)
  File "/usr/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 6: invalid start byte
@mika mika merged commit c2e742a into grml:master Oct 30, 2019
@mika
Copy link
Copy Markdown
Member

mika commented Oct 30, 2019

Very nice, thanks for the bug report as well the PR, very much appreciated! 👍

@mika
Copy link
Copy Markdown
Member

mika commented Oct 31, 2019

Oh, turns out that text support was introduced in python 3.7 only, looking into whether universal_newlines is a workaround for this.

@zwenna
Copy link
Copy Markdown
Contributor Author

zwenna commented Oct 31, 2019

Indeed, text was only introduced in 3.7, I did not know that. universal_newlines should be the replacement in older versions. More information can be found on https://bugs.python.org/issue31756.

@mika
Copy link
Copy Markdown
Member

mika commented Oct 31, 2019

ACK + thx. I've prepared the following commit which seems to work as needed, check_output seems to provide what we actually need :)

     try:
-        udev_info = subprocess.Popen(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition],
-                                     stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
-        filesystem = udev_info.communicate()[0].rstrip()
+        filesystem = subprocess.check_output(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition]).decode().rstrip()

@zwenna zwenna deleted the python3-fixes branch October 31, 2019 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants