debian/bin/gencontrol.py: Set encoding to UTF-8 globally

I just made this change for firmware-nonfree, for which I wrote:

    We open some, but not all, files with an explicit UTF-8 encoding.  One
    of the open calls that I missed has just caused gencontrol.py to fail
    instead a pbuilder environment.  Instead of continuing to set an
    explicit encoding for each open call, use locale.setlocale to set it
    globally.

I haven't hit such a problem here, but let's do it anyway.

Keep using explicit encodings in debian/lib for now, since we can't
assume all calling programs will set the locale.
This commit is contained in:
Ben Hutchings 2017-10-20 02:56:35 +01:00
parent 945bac5e39
commit 2629671100
2 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,7 @@
import sys
sys.path.append("debian/lib/python")
import codecs
import locale
import errno
import glob
import io
@ -11,6 +11,8 @@ import os
import os.path
import subprocess
locale.setlocale(locale.LC_CTYPE, "C.UTF-8")
from debian_linux import config
from debian_linux.debian import *
from debian_linux.gencontrol import Gencontrol as Base, merge_packages
@ -62,7 +64,7 @@ class Gencontrol(Base):
makeflags[dst] = data[src]
def _substitute_file(self, template, vars, target, append=False):
with codecs.open(target, 'a' if append else 'w', 'utf-8') as f:
with open(target, 'a' if append else 'w') as f:
f.write(self.substitute(self.templates[template], vars))
def do_main_setup(self, vars, makeflags, extra):
@ -237,9 +239,9 @@ class Gencontrol(Base):
stdout=subprocess.PIPE,
env=kw_env)
if not isinstance(kw_proc.stdout, io.IOBase):
udeb_packages = read_control(io.open(kw_proc.stdout.fileno(), encoding='utf-8', closefd=False))
udeb_packages = read_control(io.open(kw_proc.stdout.fileno(), closefd=False))
else:
udeb_packages = read_control(io.TextIOWrapper(kw_proc.stdout, 'utf-8'))
udeb_packages = read_control(io.TextIOWrapper(kw_proc.stdout))
kw_proc.wait()
if kw_proc.returncode != 0:
raise RuntimeError('kernel-wedge exited with code %d' %
@ -573,7 +575,7 @@ class Gencontrol(Base):
f.close()
def write_tests_control(self):
self.write_rfc822(codecs.open("debian/tests/control", 'w', 'utf-8'),
self.write_rfc822(open("debian/tests/control", 'w'),
[self.tests_control])
if __name__ == '__main__':

1
debian/changelog vendored
View File

@ -1,6 +1,7 @@
linux (4.14~rc5-1~exp2) UNRELEASED; urgency=medium
* [mips*] Increase RELOCATION_TABLE_SIZE to 0x00120000 (fixes FTBFS)
* debian/bin/gencontrol.py: Set encoding to UTF-8 globally
-- Ben Hutchings <ben@decadent.org.uk> Fri, 20 Oct 2017 00:20:35 +0100