From af0098b10aadcfd31fb8ab3cb23c2e41f82e9cc5 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Mon, 1 Oct 2018 16:22:49 +0100 Subject: [PATCH] debian/bin, debian/lib/python: Fix most errors reported by pycodestyle Fix coding style violations reported by pycodestyle. This is mostly a matter of reformatting code, particularly to eliminate over-long lines. I also rename one variable ("l" is considered visually ambiguous) and change a bare "except" to explicitly catch all exceptions. There are three types of error or warning remaining: - debian/bin/...: E402 module level import not at top of file Scripts in debian/bin need to modify the import path before importing from debian/lib/python. - E127 continuation line over-indented for visual indent This seems to be a false positive. pycodestyle doesn't seem to be happy with any level of indent (including 0) on a continuation line in a "with" statement. - debian/lib/python/debian_linux/debian.py:15:2: W291 trailing whitespace This is a false positive. The trailing spaces are in a long string and are intentional. --- debian/bin/abiupdate.py | 52 ++-- debian/bin/buildcheck.py | 52 ++-- debian/bin/gencontrol.py | 260 ++++++++++++------- debian/bin/gencontrol_signed.py | 83 ++++-- debian/bin/genorig.py | 31 ++- debian/bin/genpatch-lockdown | 24 +- debian/bin/genpatch-rt | 53 ++-- debian/bin/getconfig.py | 3 +- debian/bin/stable-update | 15 +- debian/changelog | 1 + debian/lib/python/debian_linux/abi.py | 2 +- debian/lib/python/debian_linux/config.py | 11 +- debian/lib/python/debian_linux/debian.py | 43 +-- debian/lib/python/debian_linux/firmware.py | 3 +- debian/lib/python/debian_linux/gencontrol.py | 85 ++++-- debian/lib/python/debian_linux/kconfig.py | 4 +- debian/lib/python/debian_linux/utils.py | 8 +- 17 files changed, 481 insertions(+), 249 deletions(-) diff --git a/debian/bin/abiupdate.py b/debian/bin/abiupdate.py index 3b0565c75..049d8bbe4 100755 --- a/debian/bin/abiupdate.py +++ b/debian/bin/abiupdate.py @@ -1,8 +1,6 @@ #!/usr/bin/python3 import sys -sys.path.append(sys.path[0] + "/../lib/python") - import optparse import os import shutil @@ -11,6 +9,7 @@ import tempfile from urllib.request import urlopen from urllib.error import HTTPError +sys.path.append(sys.path[0] + "/../lib/python") from debian_linux.abi import Symbols from debian_linux.config import * from debian_linux.debian import * @@ -35,25 +34,29 @@ class url_debian_pool(object): self.base = base def __call__(self, source, filename, arch): - return self.base + "pool/main/" + source[0] + "/" + source + "/" + filename + return (self.base + "pool/main/" + source[0] + "/" + source + "/" + + filename) class url_debian_ports_pool(url_debian_pool): def __call__(self, source, filename, arch): if arch == 'all': return url_debian_pool.__call__(self, source, filename, arch) - return self.base + "pool-" + arch + "/main/" + source[0] + "/" + source + "/" + filename + return (self.base + "pool-" + arch + "/main/" + source[0] + "/" + + source + "/" + filename) class url_debian_security_pool(url_debian_pool): def __call__(self, source, filename, arch): - return self.base + "pool/updates/main/" + source[0] + "/" + source + "/" + filename + return (self.base + "pool/updates/main/" + source[0] + "/" + source + + "/" + filename) class Main(object): dir = None - def __init__(self, url, url_config=None, arch=None, featureset=None, flavour=None): + def __init__(self, url, url_config=None, arch=None, featureset=None, + flavour=None): self.log = sys.stdout.write self.url = self.url_config = url @@ -72,7 +75,8 @@ class Main(object): self.version = changelog.version.linux_version self.version_source = changelog.version.complete - self.config = ConfigCoreDump(fp=open("debian/config.defines.dump", "rb")) + self.config = ConfigCoreDump(fp=open("debian/config.defines.dump", + "rb")) self.version_abi = self.config['version', ]['abiname'] @@ -104,14 +108,16 @@ class Main(object): def get_abi(self, arch, prefix): try: - version_abi = (self.config['version',]['abiname_base'] + '-' + + version_abi = (self.config[('version',)]['abiname_base'] + '-' + self.config['abi', arch]['abiname']) except KeyError: version_abi = self.version_abi - filename = "linux-headers-%s-%s_%s_%s.deb" % (version_abi, prefix, self.version_source, arch) + filename = ("linux-headers-%s-%s_%s_%s.deb" % + (version_abi, prefix, self.version_source, arch)) f = self.retrieve_package(self.url, filename, arch) d = self.extract_package(f, "linux-headers-%s_%s" % (prefix, arch)) - f1 = d + "/usr/src/linux-headers-%s-%s/Module.symvers" % (version_abi, prefix) + f1 = d + ("/usr/src/linux-headers-%s-%s/Module.symvers" % + (version_abi, prefix)) s = Symbols(open(f1)) shutil.rmtree(d) return version_abi, s @@ -166,7 +172,8 @@ class Main(object): def update_flavour(self, config, arch, featureset, flavour): config_base = config.merge('base', arch, featureset, flavour) - self.log("Updating ABI for arch %s, featureset %s, flavour %s: " % (arch, featureset, flavour)) + self.log("Updating ABI for arch %s, featureset %s, flavour %s: " % + (arch, featureset, flavour)) try: if featureset == 'none': localversion = flavour @@ -183,17 +190,26 @@ class Main(object): import traceback traceback.print_exc(None, sys.stdout) + if __name__ == '__main__': options = optparse.OptionParser() - options.add_option("-i", "--incoming", action="store_true", dest="incoming") - options.add_option("--incoming-config", action="store_true", dest="incoming_config") + options.add_option("-i", "--incoming", action="store_true", + dest="incoming") + options.add_option("--incoming-config", action="store_true", + dest="incoming_config") options.add_option("--ports", action="store_true", dest="ports") options.add_option("--security", action="store_true", dest="security") - options.add_option("-u", "--url-base", dest="url_base", default=default_url_base) - options.add_option("--url-base-incoming", dest="url_base_incoming", default=default_url_base_incoming) - options.add_option("--url-base-ports", dest="url_base_ports", default=default_url_base_ports) - options.add_option("--url-base-ports-incoming", dest="url_base_ports_incoming", default=default_url_base_ports_incoming) - options.add_option("--url-base-security", dest="url_base_security", default=default_url_base_security) + options.add_option("-u", "--url-base", dest="url_base", + default=default_url_base) + options.add_option("--url-base-incoming", dest="url_base_incoming", + default=default_url_base_incoming) + options.add_option("--url-base-ports", dest="url_base_ports", + default=default_url_base_ports) + options.add_option("--url-base-ports-incoming", + dest="url_base_ports_incoming", + default=default_url_base_ports_incoming) + options.add_option("--url-base-security", dest="url_base_security", + default=default_url_base_security) opts, args = options.parse_args() diff --git a/debian/bin/buildcheck.py b/debian/bin/buildcheck.py index eba717fa2..c9c5bafce 100755 --- a/debian/bin/buildcheck.py +++ b/debian/bin/buildcheck.py @@ -1,12 +1,11 @@ #!/usr/bin/python3 import sys -sys.path.append('debian/lib/python') - import fnmatch import glob import stat +sys.path.append('debian/lib/python') from debian_linux.abi import Symbols from debian_linux.config import ConfigCoreDump from debian_linux.debian import * @@ -46,19 +45,22 @@ class CheckAbi(object): self.filename_new = "%s/Module.symvers" % dir try: - version_abi = (self.config['version',]['abiname_base'] + '-' + + version_abi = (self.config[('version',)]['abiname_base'] + '-' + self.config['abi', arch]['abiname']) except KeyError: - version_abi = self.config['version',]['abiname'] - self.filename_ref = "debian/abi/%s/%s_%s_%s" % (version_abi, arch, featureset, flavour) + version_abi = self.config[('version',)]['abiname'] + self.filename_ref = ("debian/abi/%s/%s_%s_%s" % + (version_abi, arch, featureset, flavour)) def __call__(self, out): ret = 0 new = Symbols(open(self.filename_new)) - unversioned = [name for name in new if new[name].version == '0x00000000'] + unversioned = [name for name in new + if new[name].version == '0x00000000'] if unversioned: - out.write("ABI is not completely versioned! Refusing to continue.\n") + out.write("ABI is not completely versioned! " + "Refusing to continue.\n") out.write("\nUnversioned symbols:\n") for name in sorted(unversioned): self.SymbolInfo(new[name]).write(out, False) @@ -82,11 +84,13 @@ class CheckAbi(object): out.write("ABI has changed! Refusing to continue.\n") ret = 1 elif change or remove: - out.write("ABI has changed but all changes have been ignored. Continuing.\n") + out.write("ABI has changed but all changes have been ignored. " + "Continuing.\n") elif add_effective: out.write("New symbols have been added. Continuing.\n") elif add: - out.write("New symbols have been added but have been ignored. Continuing.\n") + out.write("New symbols have been added but have been ignored. " + "Continuing.\n") else: out.write("No ABI changes.\n") @@ -149,9 +153,12 @@ class CheckAbi(object): def _ignore(self, symbols): # TODO: let config merge this lists configs = [] - configs.append(self.config.get(('abi', self.arch, self.featureset, self.flavour), {})) - configs.append(self.config.get(('abi', self.arch, None, self.flavour), {})) - configs.append(self.config.get(('abi', self.arch, self.featureset), {})) + configs.append(self.config.get(('abi', self.arch, self.featureset, + self.flavour), {})) + configs.append(self.config.get(('abi', self.arch, None, self.flavour), + {})) + configs.append(self.config.get(('abi', self.arch, self.featureset), + {})) configs.append(self.config.get(('abi', self.arch), {})) configs.append(self.config.get(('abi', None, self.featureset), {})) configs.append(self.config.get(('abi',), {})) @@ -183,13 +190,17 @@ class CheckImage(object): self.changelog = Changelog(version=VersionLinux)[0] - self.config_entry_base = config.merge('base', arch, featureset, flavour) - self.config_entry_build = config.merge('build', arch, featureset, flavour) - self.config_entry_image = config.merge('image', arch, featureset, flavour) + self.config_entry_base = config.merge('base', arch, featureset, + flavour) + self.config_entry_build = config.merge('build', arch, featureset, + flavour) + self.config_entry_image = config.merge('image', arch, featureset, + flavour) def __call__(self, out): image = self.config_entry_build.get('image-file') - uncompressed_image = self.config_entry_build.get('uncompressed-image-file') + uncompressed_image = self.config_entry_build \ + .get('uncompressed-image-file') if not image: # TODO: Bail out @@ -236,16 +247,19 @@ class CheckImage(object): out.write('Continuing.\n') # Also check the uncompressed image - if uncompressed_image and self.config_entry_image.get('check-uncompressed-size'): + if uncompressed_image and \ + self.config_entry_image.get('check-uncompressed-size'): value = self.config_entry_image.get('check-uncompressed-size') size = os.stat(uncompressed_image).st_size usage = (float(size)/value) * 100.0 - out.write('Uncompressed Image size %d/%d, using %.2f%%. ' % (size, value, usage)) + out.write('Uncompressed Image size %d/%d, using %.2f%%. ' % + (size, value, usage)) if size > value: out.write('Too large. Refusing to continue.\n') return 1 elif usage >= 99.0: - out.write('Uncompressed Image Under 1%% space in %s. ' % self.changelog.distribution) + out.write('Uncompressed Image Under 1%% space in %s. ' % + self.changelog.distribution) else: out.write('Uncompressed Image fits. ') out.write('Continuing.\n') diff --git a/debian/bin/gencontrol.py b/debian/bin/gencontrol.py index 14e698799..fd8072d04 100755 --- a/debian/bin/gencontrol.py +++ b/debian/bin/gencontrol.py @@ -1,8 +1,6 @@ #!/usr/bin/python3 import sys -sys.path.append("debian/lib/python") - import locale import errno import glob @@ -11,13 +9,15 @@ import os import os.path import subprocess -locale.setlocale(locale.LC_CTYPE, "C.UTF-8") - +sys.path.append("debian/lib/python") from debian_linux import config from debian_linux.debian import * from debian_linux.gencontrol import Gencontrol as Base, merge_packages from debian_linux.utils import Templates, read_control +locale.setlocale(locale.LC_CTYPE, "C.UTF-8") + + class Gencontrol(Base): config_schema = { 'abi': { @@ -52,7 +52,8 @@ class Gencontrol(Base): } } - def __init__(self, config_dirs=["debian/config"], template_dirs=["debian/templates"]): + def __init__(self, config_dirs=["debian/config"], + template_dirs=["debian/templates"]): super(Gencontrol, self).__init__( config.ConfigCoreHierarchy(self.config_schema, config_dirs), Templates(template_dirs), @@ -91,9 +92,12 @@ class Gencontrol(Base): if os.getenv('DEBIAN_KERNEL_DISABLE_INSTALLER'): if self.changelog[0].distribution == 'UNRELEASED': import warnings - warnings.warn('Disable installer modules on request (DEBIAN_KERNEL_DISABLE_INSTALLER set)') + warnings.warn('Disable installer modules on request ' + '(DEBIAN_KERNEL_DISABLE_INSTALLER set)') else: - raise RuntimeError('Unable to disable installer modules in release build (DEBIAN_KERNEL_DISABLE_INSTALLER set)') + raise RuntimeError( + 'Unable to disable installer modules in release build ' + '(DEBIAN_KERNEL_DISABLE_INSTALLER set)') elif self.config.merge('packages').get('installer', True): # Add udebs using kernel-wedge kw_env = os.environ.copy() @@ -104,7 +108,8 @@ 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(), closefd=False)) + udeb_packages = read_control(io.open(kw_proc.stdout.fileno(), + closefd=False)) else: udeb_packages = read_control(io.TextIOWrapper(kw_proc.stdout)) kw_proc.wait() @@ -123,8 +128,8 @@ class Gencontrol(Base): # configuration errors before building linux-signed. build_signed = {} for arch in arches: - build_signed[arch] = (self.config.merge('build', arch) - .get('signed-code', False)) + build_signed[arch] = self.config.merge('build', arch) \ + .get('signed-code', False) for package in udeb_packages: # kernel-wedge currently chokes on Build-Profiles so add it now @@ -135,17 +140,20 @@ class Gencontrol(Base): # the package list while still being able to # convince debhelper and kernel-wedge to go # part way to building them. - package['Build-Profiles'] = '' + package['Build-Profiles'] = ( + '') else: package['Build-Profiles'] = '' for arch in package['Architecture']: - self.installer_packages.setdefault(arch, []).append(package) + self.installer_packages.setdefault(arch, []) \ + .append(package) def do_main_makefile(self, makefile, makeflags, extra): fs_enabled = [featureset for featureset in self.config['base', ]['featuresets'] - if self.config.merge('base', None, featureset).get('enabled', True)] + if (self.config.merge('base', None, featureset) + .get('enabled', True))] for featureset in fs_enabled: makeflags_featureset = makeflags.copy() makeflags_featureset['FEATURESET'] = featureset @@ -165,13 +173,17 @@ class Gencontrol(Base): super(Gencontrol, self).do_main_makefile(makefile, makeflags, extra) def do_main_packages(self, packages, vars, makeflags, extra): - packages.extend(self.process_packages(self.templates["control.main"], self.vars)) + packages.extend(self.process_packages( + self.templates["control.main"], self.vars)) if self.config.merge('packages').get('docs', True): - packages.extend(self.process_packages(self.templates["control.docs"], self.vars)) + packages.extend(self.process_packages( + self.templates["control.docs"], self.vars)) if self.config.merge('packages').get('tools-unversioned', True): - packages.extend(self.process_packages(self.templates["control.tools-unversioned"], self.vars)) + packages.extend(self.process_packages( + self.templates["control.tools-unversioned"], self.vars)) if self.config.merge('packages').get('tools-versioned', True): - packages.extend(self.process_packages(self.templates["control.tools-versioned"], self.vars)) + packages.extend(self.process_packages( + self.templates["control.tools-versioned"], self.vars)) self._substitute_file('perf.lintian-overrides', self.vars, 'debian/linux-perf-%s.lintian-overrides' % @@ -181,7 +193,8 @@ class Gencontrol(Base): makeflags['LOCALVERSION'] = vars['localversion'] kernel_arches = set() for arch in iter(self.config['base', ]['arches']): - if self.config.get_merge('base', arch, featureset, None, 'flavours'): + if self.config.get_merge('base', arch, featureset, None, + 'flavours'): kernel_arches.add(self.config['base', arch]['kernel-arch']) makeflags['ALL_KERNEL_ARCHES'] = ' '.join(sorted(list(kernel_arches))) @@ -197,9 +210,11 @@ class Gencontrol(Base): headers_featureset = self.templates["control.headers.featureset"] packages.extend(self.process_packages(headers_featureset, vars)) - cmds_binary_arch = ["$(MAKE) -f debian/rules.real binary-indep-featureset %s" % + cmds_binary_arch = ["$(MAKE) -f debian/rules.real " + "binary-indep-featureset %s" % makeflags] - makefile.add('binary-indep_%s_real' % featureset, cmds=cmds_binary_arch) + makefile.add('binary-indep_%s_real' % featureset, + cmds=cmds_binary_arch) arch_makeflags = ( ('kernel-arch', 'KERNEL_ARCH', False), @@ -211,17 +226,19 @@ class Gencontrol(Base): self._setup_makeflags(self.arch_makeflags, makeflags, config_base) try: - gnu_type_bytes = subprocess.check_output(['dpkg-architecture', '-f', - '-a', arch, - '-q', 'DEB_HOST_GNU_TYPE'], - stderr=subprocess.DEVNULL) + gnu_type_bytes = subprocess.check_output( + ['dpkg-architecture', '-f', '-a', arch, + '-q', 'DEB_HOST_GNU_TYPE'], + stderr=subprocess.DEVNULL) except subprocess.CalledProcessError: # This sometimes happens for the newest ports :-/ print('W: Unable to get GNU type for %s' % arch, file=sys.stderr) else: - vars['gnu-type-package'] = gnu_type_bytes.decode('utf-8').strip().replace('_', '-') + vars['gnu-type-package'] = ( + gnu_type_bytes.decode('utf-8').strip().replace('_', '-')) - def do_arch_packages(self, packages, makefile, arch, vars, makeflags, extra): + def do_arch_packages(self, packages, makefile, arch, vars, makeflags, + extra): if self.version.linux_modifier is None: try: abiname_part = '-%s' % self.config['abi', arch]['abiname'] @@ -230,18 +247,20 @@ class Gencontrol(Base): makeflags['ABINAME'] = vars['abiname'] = \ self.abiname_version + abiname_part - build_signed = self.config.merge('build', arch).get('signed-code', False) + build_signed = self.config.merge('build', arch) \ + .get('signed-code', False) # Some userland architectures require kernels from another # (Debian) architecture, e.g. x32/amd64. # And some derivatives don't need the headers-all packages # for other reasons. - if (self.config['base', arch].get('featuresets') and - self.config.merge('packages').get('headers-all', True)): + if self.config['base', arch].get('featuresets') and \ + self.config.merge('packages').get('headers-all', True): headers_arch = self.templates["control.headers.arch"] packages_headers_arch = self.process_packages(headers_arch, vars) packages_headers_arch[-1]['Depends'].extend(PackageRelation()) - extra['headers_arch_depends'] = packages_headers_arch[-1]['Depends'] + extra['headers_arch_depends'] = ( + packages_headers_arch[-1]['Depends']) else: packages_headers_arch = [] makeflags['DO_HEADERS_ALL'] = False @@ -254,8 +273,8 @@ class Gencontrol(Base): merge_packages(packages, packages_headers_arch, arch) - if (self.config['base', arch].get('featuresets') and - self.config.merge('packages').get('source', True)): + if self.config['base', arch].get('featuresets') and \ + self.config.merge('packages').get('source', True): merge_packages(packages, self.process_packages( self.templates["control.config"], vars), @@ -263,10 +282,12 @@ class Gencontrol(Base): else: makeflags['DO_CONFIG'] = False - cmds_build_arch = ["$(MAKE) -f debian/rules.real build-arch-arch %s" % makeflags] + cmds_build_arch = ["$(MAKE) -f debian/rules.real build-arch-arch %s" % + makeflags] makefile.add('build-arch_%s_real' % arch, cmds=cmds_build_arch) - cmds_binary_arch = ["$(MAKE) -f debian/rules.real binary-arch-arch %s" % makeflags] + cmds_binary_arch = ["$(MAKE) -f debian/rules.real binary-arch-arch %s" + % makeflags] makefile.add('binary-arch_%s_real' % arch, cmds=cmds_binary_arch, deps=['setup_%s' % arch]) @@ -296,16 +317,19 @@ class Gencontrol(Base): if build_signed: merge_packages(packages, self.process_packages( - self.templates['control.signed-template'], vars), + self.templates['control.signed-template'], + vars), arch) makefile.add( 'binary-arch_%s' % arch, - cmds=["$(MAKE) -f debian/rules.real install-signed-template_%s %s" % + cmds=["$(MAKE) -f debian/rules.real " + "install-signed-template_%s %s" % (arch, makeflags)]) def do_featureset_setup(self, vars, makeflags, arch, featureset, extra): config_base = self.config.merge('base', arch, featureset) - makeflags['LOCALVERSION_HEADERS'] = vars['localversion_headers'] = vars['localversion'] + vars['localversion_headers'] = vars['localversion'] + makeflags['LOCALVERSION_HEADERS'] = vars['localversion_headers'] flavour_makeflags_base = ( ('compiler', 'COMPILER', False), @@ -328,34 +352,47 @@ class Gencontrol(Base): ('localversion-image', 'LOCALVERSION_IMAGE', True), ) - def do_flavour_setup(self, vars, makeflags, arch, featureset, flavour, extra): + def do_flavour_setup(self, vars, makeflags, arch, featureset, flavour, + extra): config_base = self.config.merge('base', arch, featureset, flavour) config_build = self.config.merge('build', arch, featureset, flavour) - config_description = self.config.merge('description', arch, featureset, flavour) + config_description = self.config.merge('description', arch, featureset, + flavour) config_image = self.config.merge('image', arch, featureset, flavour) vars['class'] = config_description['hardware'] - vars['longclass'] = config_description.get('hardware-long') or vars['class'] + vars['longclass'] = (config_description.get('hardware-long') or + vars['class']) vars['localversion-image'] = vars['localversion'] override_localversion = config_image.get('override-localversion', None) if override_localversion is not None: - vars['localversion-image'] = vars['localversion_headers'] + '-' + override_localversion + vars['localversion-image'] = (vars['localversion_headers'] + '-' + + override_localversion) vars['image-stem'] = config_image.get('install-stem') - self._setup_makeflags(self.flavour_makeflags_base, makeflags, config_base) - self._setup_makeflags(self.flavour_makeflags_build, makeflags, config_build) - self._setup_makeflags(self.flavour_makeflags_image, makeflags, config_image) + self._setup_makeflags(self.flavour_makeflags_base, makeflags, + config_base) + self._setup_makeflags(self.flavour_makeflags_build, makeflags, + config_build) + self._setup_makeflags(self.flavour_makeflags_image, makeflags, + config_image) self._setup_makeflags(self.flavour_makeflags_other, makeflags, vars) - def do_flavour_packages(self, packages, makefile, arch, featureset, flavour, vars, makeflags, extra): + def do_flavour_packages(self, packages, makefile, arch, featureset, + flavour, vars, makeflags, extra): headers = self.templates["control.headers"] - config_entry_base = self.config.merge('base', arch, featureset, flavour) - config_entry_build = self.config.merge('build', arch, featureset, flavour) - config_entry_description = self.config.merge('description', arch, featureset, flavour) - config_entry_image = self.config.merge('image', arch, featureset, flavour) - config_entry_relations = self.config.merge('relations', arch, featureset, flavour) + config_entry_base = self.config.merge('base', arch, featureset, + flavour) + config_entry_build = self.config.merge('build', arch, featureset, + flavour) + config_entry_description = self.config.merge('description', arch, + featureset, flavour) + config_entry_image = self.config.merge('image', arch, featureset, + flavour) + config_entry_relations = self.config.merge('relations', arch, + featureset, flavour) compiler = config_entry_base.get('compiler', 'gcc') @@ -363,8 +400,8 @@ class Gencontrol(Base): # dependencies for cross-builds. Strip any remaining # restrictions, as they don't apply to binary Depends. relations_compiler_headers = PackageRelation( - self.substitute(config_entry_relations.get('headers%' + compiler) or - config_entry_relations.get(compiler), vars)) + self.substitute(config_entry_relations.get('headers%' + compiler) + or config_entry_relations.get(compiler), vars)) relations_compiler_headers = PackageRelation( PackageRelationGroup(entry for entry in group if 'cross' not in entry.restrictions) @@ -378,48 +415,54 @@ class Gencontrol(Base): for group in relations_compiler_build_dep: for item in group: item.arches = [arch] - packages['source']['Build-Depends-Arch'].extend(relations_compiler_build_dep) + packages['source']['Build-Depends-Arch'].extend( + relations_compiler_build_dep) image_fields = {'Description': PackageDescription()} - for field in 'Depends', 'Provides', 'Suggests', 'Recommends', 'Conflicts', 'Breaks': - image_fields[field] = PackageRelation(config_entry_image.get(field.lower(), None), override_arches=(arch,)) + for field in ('Depends', 'Provides', 'Suggests', 'Recommends', + 'Conflicts', 'Breaks'): + image_fields[field] = PackageRelation(config_entry_image.get( + field.lower(), None), override_arches=(arch,)) generators = config_entry_image['initramfs-generators'] - l = PackageRelationGroup() + group = PackageRelationGroup() for i in generators: i = config_entry_relations.get(i, i) - l.append(i) + group.append(i) a = PackageRelationEntry(i) if a.operator is not None: a.operator = -a.operator image_fields['Breaks'].append(PackageRelationGroup([a])) - for item in l: + for item in group: item.arches = [arch] - image_fields['Depends'].append(l) + image_fields['Depends'].append(group) bootloaders = config_entry_image.get('bootloaders') if bootloaders: - l = PackageRelationGroup() + group = PackageRelationGroup() for i in bootloaders: i = config_entry_relations.get(i, i) - l.append(i) + group.append(i) a = PackageRelationEntry(i) if a.operator is not None: a.operator = -a.operator image_fields['Breaks'].append(PackageRelationGroup([a])) - for item in l: + for item in group: item.arches = [arch] - image_fields['Suggests'].append(l) + image_fields['Suggests'].append(group) - desc_parts = self.config.get_merge('description', arch, featureset, flavour, 'parts') + desc_parts = self.config.get_merge('description', arch, featureset, + flavour, 'parts') if desc_parts: - # XXX: Workaround, we need to support multiple entries of the same name + # XXX: Workaround, we need to support multiple entries of the same + # name parts = list(set(desc_parts)) parts.sort() desc = image_fields['Description'] for part in parts: desc.append(config_entry_description['part-long-' + part]) - desc.append_short(config_entry_description.get('part-short-' + part, '')) + desc.append_short(config_entry_description + .get('part-short-' + part, '')) packages_dummy = [] packages_own = [] @@ -440,7 +483,8 @@ class Gencontrol(Base): package_headers['Depends'].extend(relations_compiler_headers) packages_own.append(package_headers) if extra.get('headers_arch_depends'): - extra['headers_arch_depends'].append('%s (= ${binary:Version})' % packages_own[-1]['Package']) + extra['headers_arch_depends'].append('%s (= ${binary:Version})' % + packages_own[-1]['Package']) if config_entry_build.get('vdso', False): makeflags['VDSO'] = True @@ -450,14 +494,18 @@ class Gencontrol(Base): if os.getenv('DEBIAN_KERNEL_DISABLE_DEBUG'): if self.changelog[0].distribution == 'UNRELEASED': import warnings - warnings.warn('Disable debug infos on request (DEBIAN_KERNEL_DISABLE_DEBUG set)') + warnings.warn('Disable debug infos on request ' + '(DEBIAN_KERNEL_DISABLE_DEBUG set)') build_debug = False else: - raise RuntimeError('Unable to disable debug infos in release build (DEBIAN_KERNEL_DISABLE_DEBUG set)') + raise RuntimeError( + 'Unable to disable debug infos in release build ' + '(DEBIAN_KERNEL_DISABLE_DEBUG set)') if build_debug: makeflags['DEBUG'] = True - packages_own.extend(self.process_packages(self.templates['control.image-dbg'], vars)) + packages_own.extend(self.process_packages( + self.templates['control.image-dbg'], vars)) merge_packages(packages, packages_own + packages_dummy, arch) @@ -506,12 +554,19 @@ class Gencontrol(Base): return check_config_files(configs) kconfig = check_config('config', True) - kconfig.extend(check_config("kernelarch-%s/config" % config_entry_base['kernel-arch'], False)) + kconfig.extend(check_config("kernelarch-%s/config" % + config_entry_base['kernel-arch'], + False)) kconfig.extend(check_config("%s/config" % arch, True, arch)) - kconfig.extend(check_config("%s/config.%s" % (arch, flavour), False, arch, None, flavour)) - kconfig.extend(check_config("featureset-%s/config" % featureset, False, None, featureset)) - kconfig.extend(check_config("%s/%s/config" % (arch, featureset), False, arch, featureset)) - kconfig.extend(check_config("%s/%s/config.%s" % (arch, featureset, flavour), False, arch, featureset, flavour)) + kconfig.extend(check_config("%s/config.%s" % (arch, flavour), False, + arch, None, flavour)) + kconfig.extend(check_config("featureset-%s/config" % featureset, False, + None, featureset)) + kconfig.extend(check_config("%s/%s/config" % (arch, featureset), False, + arch, featureset)) + kconfig.extend(check_config("%s/%s/config.%s" % + (arch, featureset, flavour), False, + arch, featureset, flavour)) makeflags['KCONFIG'] = ' '.join(kconfig) makeflags['KCONFIG_OPTIONS'] = '' if build_debug: @@ -519,16 +574,24 @@ class Gencontrol(Base): if build_signed: makeflags['KCONFIG_OPTIONS'] += ' -o MODULE_SIG=y' - cmds_binary_arch = ["$(MAKE) -f debian/rules.real binary-arch-flavour %s" % makeflags] + cmds_binary_arch = ["$(MAKE) -f debian/rules.real binary-arch-flavour " + "%s" % + makeflags] if packages_dummy: cmds_binary_arch.append( "$(MAKE) -f debian/rules.real install-dummy DH_OPTIONS='%s' %s" - % (' '.join("-p%s" % i['Package'] for i in packages_dummy), makeflags)) - cmds_build = ["$(MAKE) -f debian/rules.real build-arch-flavour %s" % makeflags] - cmds_setup = ["$(MAKE) -f debian/rules.real setup-arch-flavour %s" % makeflags] - makefile.add('binary-arch_%s_%s_%s_real' % (arch, featureset, flavour), cmds=cmds_binary_arch) - makefile.add('build-arch_%s_%s_%s_real' % (arch, featureset, flavour), cmds=cmds_build) - makefile.add('setup_%s_%s_%s_real' % (arch, featureset, flavour), cmds=cmds_setup) + % (' '.join("-p%s" % i['Package'] for i in packages_dummy), + makeflags)) + cmds_build = ["$(MAKE) -f debian/rules.real build-arch-flavour %s" % + makeflags] + cmds_setup = ["$(MAKE) -f debian/rules.real setup-arch-flavour %s" % + makeflags] + makefile.add('binary-arch_%s_%s_%s_real' % (arch, featureset, flavour), + cmds=cmds_binary_arch) + makefile.add('build-arch_%s_%s_%s_real' % (arch, featureset, flavour), + cmds=cmds_build) + makefile.add('setup_%s_%s_%s_real' % (arch, featureset, flavour), + cmds=cmds_setup) # Substitute kernel version etc. into maintainer scripts, # translations and lintian overrides @@ -537,10 +600,12 @@ class Gencontrol(Base): (vars['abiname'], vars['localversion'])) for name in ['postinst', 'postrm', 'preinst', 'prerm']: self._substitute_file('image.%s' % name, vars, - 'debian/%s.%s' % (image_main['Package'], name)) + 'debian/%s.%s' % + (image_main['Package'], name)) if build_debug: - debug_lintian_over = ('debian/linux-image-%s%s-dbg.lintian-overrides' % - (vars['abiname'], vars['localversion'])) + debug_lintian_over = ( + 'debian/linux-image-%s%s-dbg.lintian-overrides' % + (vars['abiname'], vars['localversion'])) self._substitute_file('image-dbg.lintian-overrides', vars, debug_lintian_over) os.chmod(debug_lintian_over, 0o755) @@ -565,7 +630,8 @@ class Gencontrol(Base): self.vars = { 'upstreamversion': self.version.linux_upstream, 'version': self.version.linux_version, - 'source_basename': re.sub(r'-[\d.]+$', '', self.changelog[0].source), + 'source_basename': re.sub(r'-[\d.]+$', '', + self.changelog[0].source), 'source_upstream': self.version.upstream, 'source_package': self.changelog[0].source, 'abiname': self.abiname_version + self.abiname_part, @@ -578,19 +644,24 @@ class Gencontrol(Base): distribution = self.changelog[0].distribution if distribution in ('unstable', ): - if (version.linux_revision_experimental or - version.linux_revision_backports or - version.linux_revision_other): - raise RuntimeError("Can't upload to %s with a version of %s" % (distribution, version)) + if version.linux_revision_experimental or \ + version.linux_revision_backports or \ + version.linux_revision_other: + raise RuntimeError("Can't upload to %s with a version of %s" % + (distribution, version)) if distribution in ('experimental', ): if not version.linux_revision_experimental: - raise RuntimeError("Can't upload to %s with a version of %s" % (distribution, version)) + raise RuntimeError("Can't upload to %s with a version of %s" % + (distribution, version)) if distribution.endswith('-security') or distribution.endswith('-lts'): - if version.linux_revision_backports or version.linux_revision_other: - raise RuntimeError("Can't upload to %s with a version of %s" % (distribution, version)) + if version.linux_revision_backports or \ + version.linux_revision_other: + raise RuntimeError("Can't upload to %s with a version of %s" % + (distribution, version)) if distribution.endswith('-backports'): if not version.linux_revision_backports: - raise RuntimeError("Can't upload to %s with a version of %s" % (distribution, version)) + raise RuntimeError("Can't upload to %s with a version of %s" % + (distribution, version)) def process_real_image(self, entry, fields, vars): entry = self.process_package(entry, vars) @@ -616,5 +687,6 @@ class Gencontrol(Base): self.write_rfc822(open("debian/tests/control", 'w'), [self.tests_control]) + if __name__ == '__main__': Gencontrol()() diff --git a/debian/bin/gencontrol_signed.py b/debian/bin/gencontrol_signed.py index 82bf7423e..f3b0fbade 100755 --- a/debian/bin/gencontrol_signed.py +++ b/debian/bin/gencontrol_signed.py @@ -1,25 +1,33 @@ #!/usr/bin/python3 +import codecs +import hashlib +import io +import json +import os.path +import re +import ssl +import subprocess import sys -sys.path.append("debian/lib/python") +import time +sys.path.append("debian/lib/python") from debian_linux.config import ConfigCoreDump from debian_linux.debian import Changelog, PackageDescription, VersionLinux, \ Package, PackageRelationGroup from debian_linux.gencontrol import Gencontrol as Base, merge_packages from debian_linux.utils import Templates, read_control -import os.path, re, codecs, io, json, subprocess, time, ssl, hashlib class Gencontrol(Base): def __init__(self, arch): super(Gencontrol, self).__init__( - ConfigCoreDump(fp = open('debian/config.defines.dump', 'rb')), + ConfigCoreDump(fp=open('debian/config.defines.dump', 'rb')), Templates(['debian/signing_templates', 'debian/templates'])) image_binary_version = self.changelog[0].version.complete - config_entry = self.config['version',] + config_entry = self.config[('version',)] self.version = VersionLinux(config_entry['source']) # Check config version matches changelog version @@ -42,7 +50,8 @@ class Gencontrol(Base): self.template_top_dir = (self.package_dir + '/usr/share/code-signing/%(template)s' % self.vars) - self.template_debian_dir = self.template_top_dir + '/source-template/debian' + self.template_debian_dir = (self.template_top_dir + + '/source-template/debian') os.makedirs(self.template_debian_dir, exist_ok=True) self.image_packages = [] @@ -54,7 +63,9 @@ class Gencontrol(Base): def do_main_setup(self, vars, makeflags, extra): makeflags['VERSION'] = self.version.linux_version makeflags['GENCONTROL_ARGS'] = ( - '-v%(imagebinaryversion)s -DBuilt-Using="linux (= %(imagesourceversion)s)"' % vars) + '-v%(imagebinaryversion)s ' + '-DBuilt-Using="linux (= %(imagesourceversion)s)"' % + vars) makeflags['PACKAGE_VERSION'] = vars['imagebinaryversion'] self.installer_packages = {} @@ -62,9 +73,12 @@ class Gencontrol(Base): if os.getenv('DEBIAN_KERNEL_DISABLE_INSTALLER'): if self.changelog[0].distribution == 'UNRELEASED': import warnings - warnings.warn('Disable installer modules on request (DEBIAN_KERNEL_DISABLE_INSTALLER set)') + warnings.warn('Disable installer modules on request ' + '(DEBIAN_KERNEL_DISABLE_INSTALLER set)') else: - raise RuntimeError('Unable to disable installer modules in release build (DEBIAN_KERNEL_DISABLE_INSTALLER set)') + raise RuntimeError( + 'Unable to disable installer modules in release build ' + '(DEBIAN_KERNEL_DISABLE_INSTALLER set)') elif self.config.merge('packages').get('installer', True): # Add udebs using kernel-wedge kw_env = os.environ.copy() @@ -75,7 +89,8 @@ 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(), closefd=False)) + udeb_packages = read_control(io.open(kw_proc.stdout.fileno(), + closefd=False)) else: udeb_packages = read_control(io.TextIOWrapper(kw_proc.stdout)) kw_proc.wait() @@ -85,8 +100,10 @@ class Gencontrol(Base): for package in udeb_packages: for arch in package['Architecture']: - if self.config.merge('build', arch).get('signed-code', False): - self.installer_packages.setdefault(arch, []).append(package) + if self.config.merge('build', arch) \ + .get('signed-code', False): + self.installer_packages.setdefault(arch, []) \ + .append(package) def do_main_packages(self, packages, vars, makeflags, extra): # Assume that arch:all packages do not get binNMU'd @@ -95,7 +112,8 @@ class Gencontrol(Base): def do_main_recurse(self, packages, makefile, vars, makeflags, extra): # Each signed source package only covers a single architecture - self.do_arch(packages, makefile, self.vars['arch'], vars.copy(), makeflags.copy(), extra) + self.do_arch(packages, makefile, self.vars['arch'], vars.copy(), + makeflags.copy(), extra) def do_extra(self, packages, makefile): pass @@ -110,7 +128,8 @@ class Gencontrol(Base): makeflags['ABINAME'] = vars['abiname'] = \ self.config['version', ]['abiname_base'] + abiname_part - def do_arch_packages(self, packages, makefile, arch, vars, makeflags, extra): + def do_arch_packages(self, packages, makefile, arch, vars, makeflags, + extra): udeb_packages = self.installer_packages.get(arch, []) if udeb_packages: merge_packages(packages, udeb_packages, arch) @@ -126,13 +145,17 @@ class Gencontrol(Base): (arch, makeflags, ' '.join(p['Package'] for p in udeb_packages))]) - def do_flavour_setup(self, vars, makeflags, arch, featureset, flavour, extra): - super(Gencontrol, self).do_flavour_setup(vars, makeflags, arch, featureset, flavour, extra) + def do_flavour_setup(self, vars, makeflags, arch, featureset, flavour, + extra): + super(Gencontrol, self).do_flavour_setup(vars, makeflags, arch, + featureset, flavour, extra) config_image = self.config.merge('image', arch, featureset, flavour) - makeflags['IMAGE_INSTALL_STEM'] = vars['image-stem'] = config_image.get('install-stem') + vars['image-stem'] = config_image.get('install-stem') + makeflags['IMAGE_INSTALL_STEM'] = vars['image-stem'] - def do_flavour_packages(self, packages, makefile, arch, featureset, flavour, vars, makeflags, extra): + def do_flavour_packages(self, packages, makefile, arch, featureset, + flavour, vars, makeflags, extra): if not (self.config.merge('build', arch, featureset, flavour) .get('signed-code', False)): return @@ -156,7 +179,8 @@ class Gencontrol(Base): break assert cert_file_name if featureset != "none": - cert_file_name = os.path.join('debian/build/source_%s' % featureset, + cert_file_name = os.path.join('debian/build/source_%s' % + featureset, cert_file_name) self.image_packages.append((image_suffix, image_package_name, @@ -180,8 +204,11 @@ class Gencontrol(Base): cmds_binary_arch = [] for i in packages_signed: - cmds_binary_arch += ["$(MAKE) -f debian/rules.real install-signed PACKAGE_NAME='%s' %s" % (i['Package'], makeflags)] - makefile.add('binary-arch_%s_%s_%s_real' % (arch, featureset, flavour), cmds = cmds_binary_arch) + cmds_binary_arch += ["$(MAKE) -f debian/rules.real install-signed " + "PACKAGE_NAME='%s' %s" % + (i['Package'], makeflags)] + makefile.add('binary-arch_%s_%s_%s_real' % (arch, featureset, flavour), + cmds=cmds_binary_arch) os.makedirs(self.package_dir + '/usr/share/lintian/overrides', 0o755, exist_ok=True) @@ -193,7 +220,8 @@ class Gencontrol(Base): '/linux-image-%s%s.%s' % (vars['abiname'], vars['localversion'], script_base)) - self._substitute_file('image.%s' % script_base, vars, script_name) + self._substitute_file('image.%s' % script_base, vars, + script_name) lintian_overrides.write('%s: script-not-executable %s\n' % (self.vars['template'], os.path.relpath(script_name, @@ -215,16 +243,18 @@ class Gencontrol(Base): vars['source'] = self.changelog[0].source vars['distribution'] = self.changelog[0].distribution vars['urgency'] = self.changelog[0].urgency - vars['signedsourceversion'] = (re.sub(r'-', r'+', vars['imagebinaryversion'])) + vars['signedsourceversion'] = (re.sub(r'-', r'+', + vars['imagebinaryversion'])) - with codecs.open(self.template_debian_dir + '/changelog', 'w', 'utf-8') as f: + with codecs.open(self.template_debian_dir + '/changelog', 'w', + 'utf-8') as f: f.write(self.substitute('''\ linux-signed-@arch@ (@signedsourceversion@) @distribution@; urgency=@urgency@ * Sign kernel from @source@ @imagebinaryversion@ ''', - vars)) + vars)) with codecs.open('debian/changelog', 'r', 'utf-8') as changelog_in: # Ignore first two header lines @@ -269,7 +299,7 @@ linux-signed-@arch@ (@signedsourceversion@) @distribution@; urgency=@urgency@ all_files = {} for image_suffix, image_package_name, cert_file_name in \ - self.image_packages: + self.image_packages: package_dir = 'debian/%s' % image_package_name package_files = [] package_files.append({'sig_type': 'efi', @@ -281,7 +311,7 @@ linux-signed-@arch@ (@signedsourceversion@) @distribution@; urgency=@urgency@ package_files.append( {'sig_type': 'linux-module', 'file': '%s/%s' % - (root[len(package_dir) + 1 :], name)}) + (root[(len(package_dir) + 1):], name)}) package_certs = [get_cert_fingerprint(cert, 'sha256') for cert in get_certs(cert_file_name)] assert len(package_certs) >= 1 @@ -293,5 +323,6 @@ linux-signed-@arch@ (@signedsourceversion@) @distribution@; urgency=@urgency@ with codecs.open(self.template_top_dir + '/files.json', 'w') as f: json.dump(all_files, f) + if __name__ == '__main__': Gencontrol(sys.argv[1])() diff --git a/debian/bin/genorig.py b/debian/bin/genorig.py index 49b8e5f5a..d45b53b15 100755 --- a/debian/bin/genorig.py +++ b/debian/bin/genorig.py @@ -1,8 +1,6 @@ #!/usr/bin/python3 import sys -sys.path.append("debian/lib/python") - import deb822 import glob import os @@ -13,6 +11,7 @@ import subprocess import time import warnings +sys.path.append("debian/lib/python") from debian_linux.debian import Changelog, VersionLinux @@ -33,7 +32,8 @@ class Main(object): if self.version_dfsg is None: self.version_dfsg = '0' - self.log('Using source name %s, version %s, dfsg %s\n' % (source, version.upstream, self.version_dfsg)) + self.log('Using source name %s, version %s, dfsg %s\n' % + (source, version.upstream, self.version_dfsg)) self.orig = '%s-%s' % (source, version.upstream) self.orig_tar = '%s_%s.orig.tar.xz' % (source, version.upstream) @@ -76,7 +76,7 @@ class Main(object): verify_proc = subprocess.Popen(['git', '-c', 'gpg.program=%s' % gpg_wrapper, 'tag', '-v', self.tag], - cwd=input_repo) + cwd=input_repo) if verify_proc.wait(): raise RuntimeError("GPG tag verification failed") @@ -94,7 +94,9 @@ class Main(object): def upstream_extract(self, input_tar): self.log("Extracting tarball %s\n" % input_tar) - match = re.match(r'(^|.*/)(?Plinux-\d+\.\d+(\.\d+)?(-\S+)?)\.tar(\.(?P(bz2|gz|xz)))?$', input_tar) + match = re.match(r'(^|.*/)(?Plinux-\d+\.\d+(\.\d+)?(-\S+)?)\.tar' + r'(\.(?P(bz2|gz|xz)))?$', + input_tar) if not match: raise RuntimeError("Can't identify name of tarball") @@ -103,11 +105,14 @@ class Main(object): if subprocess.Popen(cmdline).wait(): raise RuntimeError("Can't extract tarball") - os.rename(os.path.join(self.dir, match.group('dir')), os.path.join(self.dir, self.orig)) + os.rename(os.path.join(self.dir, match.group('dir')), + os.path.join(self.dir, self.orig)) def upstream_patch(self, input_patch): self.log("Patching source with %s\n" % input_patch) - match = re.match(r'(^|.*/)patch-\d+\.\d+(\.\d+)?(-\S+?)?(\.(?P(bz2|gz|xz)))?$', input_patch) + match = re.match(r'(^|.*/)patch-\d+\.\d+(\.\d+)?(-\S+?)?' + r'(\.(?P(bz2|gz|xz)))?$', + input_patch) if not match: raise RuntimeError("Can't identify name of patch") cmdline = [] @@ -120,7 +125,8 @@ class Main(object): else: cmdline.append('cat') cmdline.append(input_patch) - cmdline.append('| (cd %s; patch -p1 -f -s -t --no-backup-if-mismatch)' % os.path.join(self.dir, self.orig)) + cmdline.append('| (cd %s; patch -p1 -f -s -t --no-backup-if-mismatch)' + % os.path.join(self.dir, self.orig)) if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]): raise RuntimeError("Can't patch source") @@ -174,21 +180,24 @@ class Main(object): try: subprocess.run(cmd, env=env, check=True) os.chmod(out, 0o644) - except: + except BaseException: try: os.unlink(out) except OSError: pass raise try: - os.symlink(os.path.join('orig', self.orig_tar), os.path.join('..', self.orig_tar)) + os.symlink(os.path.join('orig', self.orig_tar), + os.path.join('..', self.orig_tar)) except OSError: pass + if __name__ == '__main__': from optparse import OptionParser parser = OptionParser(usage="%prog [OPTION]... {TAR [PATCH] | REPO}") - parser.add_option("-V", "--override-version", dest="override_version", help="Override version", metavar="VERSION") + parser.add_option("-V", "--override-version", dest="override_version", + help="Override version", metavar="VERSION") options, args = parser.parse_args() assert 1 <= len(args) <= 2 diff --git a/debian/bin/genpatch-lockdown b/debian/bin/genpatch-lockdown index aa8b78513..ecaf71eea 100755 --- a/debian/bin/genpatch-lockdown +++ b/debian/bin/genpatch-lockdown @@ -1,6 +1,16 @@ #!/usr/bin/python3 -import codecs, errno, io, os, os.path, re, shutil, subprocess, sys, tempfile +import codecs +import errno +import io +import os +import os.path +import re +import shutil +import subprocess +import sys +import tempfile + def main(repo, range='torvalds/master..dhowells/efi-lock-down'): patch_dir = 'debian/patches' @@ -62,17 +72,20 @@ def main(repo, range='torvalds/master..dhowells/efi-lock-down'): env['GIT_DIR'] = os.path.join(repo, '.git') args = ['git', 'format-patch', '--subject-prefix=', range] format_proc = subprocess.Popen(args, - cwd=os.path.join(patch_dir, lockdown_patch_dir), + cwd=os.path.join(patch_dir, + lockdown_patch_dir), env=env, stdout=subprocess.PIPE) with io.open(format_proc.stdout.fileno(), encoding='utf-8') as pipe: for line in pipe: name = line.strip('\n') - with open(os.path.join(patch_dir, lockdown_patch_dir, name)) as \ - source_patch: + with open(os.path.join(patch_dir, lockdown_patch_dir, name)) \ + as source_patch: patch_from = source_patch.readline() match = re.match(r'From ([0-9a-f]{40}) ', patch_from) assert match - origin = 'https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/commit?id=%s' % match.group(1) + origin = ('https://git.kernel.org/pub/scm/linux/kernel/' + 'git/dhowells/linux-fs.git/commit?id=%s' % + match.group(1)) add_patch(name, source_patch, origin) for line in series_after: @@ -87,6 +100,7 @@ def main(repo, range='torvalds/master..dhowells/efi-lock-down'): for name in old_series: print('Obsoleted patch', os.path.join(patch_dir, name)) + if __name__ == '__main__': if not (2 <= len(sys.argv) <= 3): sys.stderr.write('''\ diff --git a/debian/bin/genpatch-rt b/debian/bin/genpatch-rt index 00329c4a8..972367c89 100755 --- a/debian/bin/genpatch-rt +++ b/debian/bin/genpatch-rt @@ -1,6 +1,16 @@ #!/usr/bin/python3 -import codecs, errno, io, os, os.path, re, shutil, subprocess, sys, tempfile +import codecs +import errno +import io +import os +import os.path +import re +import shutil +import subprocess +import sys +import tempfile + def main(source, version=None): patch_dir = 'debian/patches-rt' @@ -46,25 +56,29 @@ def main(source, version=None): # Validate tag signature gpg_wrapper = os.path.join(os.getcwd(), "debian/bin/git-tag-gpg-wrapper") - verify_proc = subprocess.Popen(['git', - '-c', 'gpg.program=%s' % gpg_wrapper, - 'tag', '-v', 'v%s-rebase' % version], - env=env) + verify_proc = subprocess.Popen( + ['git', '-c', 'gpg.program=%s' % gpg_wrapper, + 'tag', '-v', 'v%s-rebase' % version], + env=env) if verify_proc.wait(): raise RuntimeError("GPG tag verification failed") - args = ['git', 'format-patch', 'v%s..v%s-rebase' % (up_ver, version)] + args = ['git', 'format-patch', + 'v%s..v%s-rebase' % (up_ver, version)] format_proc = subprocess.Popen(args, cwd=patch_dir, env=env, stdout=subprocess.PIPE) - with io.open(format_proc.stdout.fileno(), encoding='utf-8') as pipe: + with io.open(format_proc.stdout.fileno(), encoding='utf-8') \ + as pipe: for line in pipe: name = line.strip('\n') with open(os.path.join(patch_dir, name)) as source_patch: patch_from = source_patch.readline() match = re.match(r'From ([0-9a-f]{40}) ', patch_from) assert match - origin = 'https://git.kernel.org/cgit/linux/kernel/git/rt/linux-stable-rt.git/commit?id=%s' % match.group(1) + origin = ('https://git.kernel.org/cgit/linux/kernel/' + 'git/rt/linux-stable-rt.git/commit?id=%s' % + match.group(1)) add_patch(name, source_patch, origin) else: @@ -90,7 +104,7 @@ def main(source, version=None): not re.search(r'^\[GNUPG:\]\s+VALIDSIG\s', codecs.decode(verify_output), re.MULTILINE): - os.write(2, verify_output) # bytes not str! + os.write(2, verify_output) # bytes not str! raise RuntimeError("GPG signature verification failed") temp_dir = tempfile.mkdtemp(prefix='rt-genpatch', dir='debian') @@ -98,16 +112,20 @@ def main(source, version=None): # Unpack tarball subprocess.check_call(['tar', '-C', temp_dir, '-xaf', source]) source_dir = os.path.join(temp_dir, 'patches') - assert os.path.isdir(source_dir), 'tarball does not contain patches directory' + assert os.path.isdir(source_dir), \ + 'tarball does not contain patches directory' # Copy patch series - origin = 'https://www.kernel.org/pub/linux/kernel/projects/rt/%s/older/patches-%s.tar.xz' % (up_ver, version) - with open(os.path.join(source_dir, 'series'), 'r') as \ - source_series_fh: + origin = ('https://www.kernel.org/pub/linux/kernel/projects/' + 'rt/%s/older/patches-%s.tar.xz' % + (up_ver, version)) + with open(os.path.join(source_dir, 'series'), 'r') \ + as source_series_fh: for line in source_series_fh: name = line.strip() if name != '' and name[0] != '#': - with open(os.path.join(source_dir, name)) as source_patch: + with open(os.path.join(source_dir, name)) \ + as source_patch: add_patch(name, source_patch, origin) series_fh.write(line) finally: @@ -122,10 +140,13 @@ def main(source, version=None): for name in old_series: print('Obsoleted patch', os.path.join(patch_dir, name)) + if __name__ == '__main__': if not (1 <= len(sys.argv) <= 3): - print('Usage: %s {TAR [RT-VERSION] | REPO RT-VERSION}' % sys.argv[0], file=sys.stderr) + print('Usage: %s {TAR [RT-VERSION] | REPO RT-VERSION}' % sys.argv[0], + file=sys.stderr) print('TAR is a tarball of patches.', file=sys.stderr) - print('REPO is a git repo containing the given RT-VERSION.', file=sys.stderr) + print('REPO is a git repo containing the given RT-VERSION.', + file=sys.stderr) sys.exit(2) main(*sys.argv[1:]) diff --git a/debian/bin/getconfig.py b/debian/bin/getconfig.py index e993f7c24..bb1e713fa 100755 --- a/debian/bin/getconfig.py +++ b/debian/bin/getconfig.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 import sys -sys.path.append(sys.path[0] + "/../lib/python") +sys.path.append(sys.path[0] + "/../lib/python") from debian_linux.config import ConfigCoreDump section = tuple(s or None for s in sys.argv[1:-1]) @@ -24,4 +24,3 @@ else: except TypeError: # Otherwise use the default format print(value) - diff --git a/debian/bin/stable-update b/debian/bin/stable-update index f17afdd91..91ed9c9fd 100755 --- a/debian/bin/stable-update +++ b/debian/bin/stable-update @@ -1,18 +1,21 @@ #!/usr/bin/python3 import sys +import os +import re +import subprocess + sys.path.append(sys.path[0] + "/../lib/python") - -import os, re, subprocess - from debian_linux.debian import Changelog, VersionLinux + def base_version(ver): # Assume base version is at least 3.0, thus only 2 components wanted match = re.match(r'^(\d+\.\d+)', ver) assert match return match.group(1) + def add_update(ver, inc): base = base_version(ver) if base == ver: @@ -25,9 +28,11 @@ def add_update(ver, inc): else: return '{}.{}'.format(base, update) + def next_update(ver): return add_update(ver, 1) + def print_stable_log(log, cur_ver, new_ver): major_ver = re.sub(r'^(\d+)\..*', r'\1', cur_ver) while cur_ver != new_ver: @@ -35,13 +40,14 @@ def print_stable_log(log, cur_ver, new_ver): print(' https://www.kernel.org/pub/linux/kernel/v{}.x/ChangeLog-{}' .format(major_ver, next_ver), file=log) - log.flush() # serialise our output with git's + log.flush() # serialise our output with git's subprocess.check_call(['git', 'log', '--reverse', '--pretty= - %s', 'v{}..v{}^'.format(cur_ver, next_ver)], stdout=log) cur_ver = next_ver + def main(repo, new_ver): if os.path.exists(os.path.join(repo, '.git')): os.environ['GIT_DIR'] = os.path.join(repo, '.git') @@ -118,6 +124,7 @@ def main(repo, new_ver): os.rename('debian/changelog.new', 'debian/changelog') + if __name__ == '__main__': if len(sys.argv) != 3: print('''\ diff --git a/debian/changelog b/debian/changelog index c0af045c8..a3355fb7b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ linux (4.19~rc6-1~exp1) UNRELEASED; urgency=medium [ Ben Hutchings ] * [ppc64el] udeb: Fix relative #include filenames in kernel-image module list (really fixes FTBFS?) + * debian/bin, debian/lib/python: Fix most errors reported by pycodestyle -- Ben Hutchings Thu, 20 Sep 2018 02:40:54 +0100 diff --git a/debian/lib/python/debian_linux/abi.py b/debian/lib/python/debian_linux/abi.py index 0c4b3bdbc..8532db16d 100644 --- a/debian/lib/python/debian_linux/abi.py +++ b/debian/lib/python/debian_linux/abi.py @@ -39,4 +39,4 @@ class Symbols(dict): def write(self, file): for s in sorted(self.values(), key=lambda i: i.name): file.write("%s %s %s %s\n" % - (s.version, s.name, s.module, s.export)) + (s.version, s.name, s.module, s.export)) diff --git a/debian/lib/python/debian_linux/config.py b/debian/lib/python/debian_linux/config.py index 4106a7d55..9d7c2f3cf 100644 --- a/debian/lib/python/debian_linux/config.py +++ b/debian/lib/python/debian_linux/config.py @@ -50,7 +50,8 @@ class ConfigCore(collections.OrderedDict): temp = [] if arch and featureset and flavour: - temp.append(self.get((section, arch, featureset, flavour), {}).get(key)) + temp.append(self.get((section, arch, featureset, flavour), {}) + .get(key)) temp.append(self.get((section, arch, None, flavour), {}).get(key)) if arch and featureset: temp.append(self.get((section, arch, featureset), {}).get(key)) @@ -157,7 +158,8 @@ class ConfigCoreHierarchy(object): base['featuresets'] = featuresets del base['flavours'] ret['base', arch] = base - ret['base', arch, 'none'] = {'flavours': flavours, 'implicit-flavour': True} + ret['base', arch, 'none'] = {'flavours': flavours, + 'implicit-flavour': True} def read_arch_featureset(self, ret, arch, featureset): config = ConfigParser(self.schema) @@ -241,7 +243,7 @@ class ConfigParser(object): value = schema[key](value) ret[key] = value return ret - + def keys(self): return self._convert().keys() @@ -253,7 +255,8 @@ if __name__ == '__main__': import sys sys.path.append('debian/lib/python') config = ConfigCoreDump(open('debian/config.defines.dump', 'rb')) - for section, items in sorted(config.items(), key=lambda a:tuple(i or '' for i in a[0])): + for section, items in sorted(config.items(), + key=(lambda a: tuple(i or '' for i in a[0]))): print(u"[%s]" % (section,)) for item, value in sorted(items.items()): print(u"%s: %s" % (item, value)) diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py index b67678d05..453c189b4 100644 --- a/debian/lib/python/debian_linux/debian.py +++ b/debian/lib/python/debian_linux/debian.py @@ -45,7 +45,8 @@ class Changelog(list): _ignore_re = re.compile(r'^(?: |\s*\n)') class Entry(object): - __slot__ = 'distribution', 'source', 'version', 'urgency', 'maintainer', 'date' + __slot__ = ('distribution', 'source', 'version', 'urgency', + 'maintainer', 'date') def __init__(self, **kwargs): for key, value in kwargs.items(): @@ -57,7 +58,8 @@ class Changelog(list): if file: self._parse(version, file) else: - with open(os.path.join(dir, "debian/changelog"), encoding="UTF-8") as f: + with open(os.path.join(dir, "debian/changelog"), + encoding="UTF-8") as f: self._parse(version, f) def _parse(self, version, f): @@ -72,7 +74,8 @@ class Changelog(list): elif top_match is None: top_match = self._top_re.match(line) if not top_match: - raise Exception('invalid top line %d in changelog' % line_no) + raise Exception('invalid top line %d in changelog' % + line_no) try: v = version(top_match.group('version')) except Exception: @@ -82,16 +85,19 @@ class Changelog(list): else: bottom_match = self._bottom_re.match(line) if not bottom_match: - raise Exception('invalid bottom line %d in changelog' % line_no) + raise Exception('invalid bottom line %d in changelog' % + line_no) - self.append(self.Entry(distribution=top_match.group('distribution'), - source=top_match.group('source'), - version=v, - urgency=top_match.group('urgency'), - maintainer=bottom_match.group('maintainer'), - date=bottom_match.group('date'))) + self.append(self.Entry( + distribution=top_match.group('distribution'), + source=top_match.group('source'), + version=v, + urgency=top_match.group('urgency'), + maintainer=bottom_match.group('maintainer'), + date=bottom_match.group('date'))) top_match = bottom_match = None + class Version(object): _epoch_re = re.compile(r'\d+$') _upstream_re = re.compile(r'[0-9][A-Za-z0-9.+\-:~]*$') @@ -110,9 +116,9 @@ class Version(object): upstream, revision = rest, None else: upstream, revision = rest[0:split], rest[split+1:] - if ((epoch is not None and not self._epoch_re.match(epoch)) or - not self._upstream_re.match(upstream) or - (revision is not None and not self._revision_re.match(revision))): + if (epoch is not None and not self._epoch_re.match(epoch)) or \ + not self._upstream_re.match(upstream) or \ + (revision is not None and not self._revision_re.match(revision)): raise RuntimeError(u"Invalid debian version") self.epoch = epoch and int(epoch) self.upstream = upstream @@ -136,7 +142,8 @@ class Version(object): @property def debian(self): from warnings import warn - warn(u"debian argument was replaced by revision", DeprecationWarning, stacklevel=2) + warn(u"debian argument was replaced by revision", DeprecationWarning, + stacklevel=2) return self.revision @@ -379,7 +386,7 @@ class _VersionLinuxTest(unittest.TestCase): self.assertFalse(v.linux_revision_other) def test_other_revision(self): - v = VersionLinux('4.16.5-1+revert+crng+ready') # from #898087 + v = VersionLinux('4.16.5-1+revert+crng+ready') # from #898087 self.assertFalse(v.linux_revision_experimental) self.assertFalse(v.linux_revision_security) self.assertFalse(v.linux_revision_backports) @@ -537,7 +544,8 @@ class PackageRelationGroup(list): class PackageRelationEntry(object): __slots__ = "name", "operator", "version", "arches", "restrictions" - _re = re.compile(r'^(\S+)(?: \((<<|<=|=|!=|>=|>>)\s*([^)]+)\))?(?: \[([^]]+)\])?(?: <([^>]+)>)?$') + _re = re.compile(r'^(\S+)(?: \((<<|<=|=|!=|>=|>>)\s*([^)]+)\))?' + r'(?: \[([^]]+)\])?(?: <([^>]+)>)?$') class _operator(object): OP_LT = 1 @@ -573,7 +581,8 @@ class PackageRelationEntry(object): self._op = self.operators[value] def __neg__(self): - return self.__class__(self.operators_text[self.operators_neg[self._op]]) + return self.__class__( + self.operators_text[self.operators_neg[self._op]]) def __str__(self): return self.operators_text[self._op] diff --git a/debian/lib/python/debian_linux/firmware.py b/debian/lib/python/debian_linux/firmware.py index ece3743d3..8bb4f0850 100644 --- a/debian/lib/python/debian_linux/firmware.py +++ b/debian/lib/python/debian_linux/firmware.py @@ -80,7 +80,8 @@ class FirmwareWhence(list): licence = value elif licence is not None: licence = (licence + '\n' + - re.sub(r'^(?:[/ ]\*| \*/)?\s*(.*?)\s*$', r'\1', line)) + re.sub(r'^(?:[/ ]\*| \*/)?\s*(.*?)\s*$', r'\1', + line)) # Finish last section if non-empty for b in binary: diff --git a/debian/lib/python/debian_linux/gencontrol.py b/debian/lib/python/debian_linux/gencontrol.py index c46f9991d..8a4be8f70 100644 --- a/debian/lib/python/debian_linux/gencontrol.py +++ b/debian/lib/python/debian_linux/gencontrol.py @@ -116,19 +116,25 @@ class Gencontrol(object): pass def do_main_makefile(self, makefile, makeflags, extra): - makefile.add('build-indep', cmds=["$(MAKE) -f debian/rules.real build-indep %s" % makeflags]) - makefile.add('binary-indep', cmds=["$(MAKE) -f debian/rules.real binary-indep %s" % makeflags]) + makefile.add('build-indep', + cmds=["$(MAKE) -f debian/rules.real build-indep %s" % + makeflags]) + makefile.add('binary-indep', + cmds=["$(MAKE) -f debian/rules.real binary-indep %s" % + makeflags]) def do_main_packages(self, packages, vars, makeflags, extra): pass def do_main_recurse(self, packages, makefile, vars, makeflags, extra): for featureset in self.config['base', ]['featuresets']: - if self.config.merge('base', None, featureset).get('enabled', True): + if self.config.merge('base', None, featureset) \ + .get('enabled', True): self.do_indep_featureset(packages, makefile, featureset, vars.copy(), makeflags.copy(), extra) for arch in iter(self.config['base', ]['arches']): - self.do_arch(packages, makefile, arch, vars.copy(), makeflags.copy(), extra) + self.do_arch(packages, makefile, arch, vars.copy(), + makeflags.copy(), extra) def do_extra(self, packages, makefile): templates_extra = self.templates.get("control.extra", None) @@ -147,12 +153,15 @@ class Gencontrol(object): for arch in sorted(extra_arches.keys()): cmds = [] for i in extra_arches[arch]: - cmds.append("$(MAKE) -f debian/rules.real install-dummy ARCH='%s' DH_OPTIONS='-p%s'" % (arch, i['Package'])) - makefile.add('binary-arch_%s' % arch, ['binary-arch_%s_extra' % arch]) - makefile.add("binary-arch_%s_extra" % arch, cmds = cmds) + cmds.append("$(MAKE) -f debian/rules.real install-dummy " + "ARCH='%s' DH_OPTIONS='-p%s'" % + (arch, i['Package'])) + makefile.add('binary-arch_%s' % arch, + ['binary-arch_%s_extra' % arch]) + makefile.add("binary-arch_%s_extra" % arch, cmds=cmds) def do_indep_featureset(self, packages, makefile, featureset, vars, - makeflags, extra): + makeflags, extra): vars['localversion'] = '' if featureset != 'none': vars['localversion'] = '-' + featureset @@ -202,14 +211,18 @@ class Gencontrol(object): makefile.add(target1, [target2]) makefile.add(target2, [target3]) - def do_arch_packages(self, packages, makefile, arch, vars, makeflags, extra): + def do_arch_packages(self, packages, makefile, arch, vars, makeflags, + extra): pass - def do_arch_recurse(self, packages, makefile, arch, vars, makeflags, extra): + def do_arch_recurse(self, packages, makefile, arch, vars, makeflags, + extra): for featureset in self.config['base', arch].get('featuresets', ()): - self.do_featureset(packages, makefile, arch, featureset, vars.copy(), makeflags.copy(), extra) + self.do_featureset(packages, makefile, arch, featureset, + vars.copy(), makeflags.copy(), extra) - def do_featureset(self, packages, makefile, arch, featureset, vars, makeflags, extra): + def do_featureset(self, packages, makefile, arch, featureset, vars, + makeflags, extra): config_base = self.config.merge('base', arch, featureset) if not config_base.get('enabled', True): return @@ -219,14 +232,18 @@ class Gencontrol(object): vars['localversion'] = '-' + featureset self.do_featureset_setup(vars, makeflags, arch, featureset, extra) - self.do_featureset_makefile(makefile, arch, featureset, makeflags, extra) - self.do_featureset_packages(packages, makefile, arch, featureset, vars, makeflags, extra) - self.do_featureset_recurse(packages, makefile, arch, featureset, vars, makeflags, extra) + self.do_featureset_makefile(makefile, arch, featureset, makeflags, + extra) + self.do_featureset_packages(packages, makefile, arch, featureset, vars, + makeflags, extra) + self.do_featureset_recurse(packages, makefile, arch, featureset, vars, + makeflags, extra) def do_featureset_setup(self, vars, makeflags, arch, featureset, extra): pass - def do_featureset_makefile(self, makefile, arch, featureset, makeflags, extra): + def do_featureset_makefile(self, makefile, arch, featureset, makeflags, + extra): makeflags['FEATURESET'] = featureset for i in self.makefile_targets: @@ -236,31 +253,40 @@ class Gencontrol(object): makefile.add(target1, [target2]) makefile.add(target2, [target3]) - def do_featureset_packages(self, packages, makefile, arch, featureset, vars, makeflags, extra): + def do_featureset_packages(self, packages, makefile, arch, featureset, + vars, makeflags, extra): pass - def do_featureset_recurse(self, packages, makefile, arch, featureset, vars, makeflags, extra): + def do_featureset_recurse(self, packages, makefile, arch, featureset, vars, + makeflags, extra): for flavour in self.config['base', arch, featureset]['flavours']: - self.do_flavour(packages, makefile, arch, featureset, flavour, vars.copy(), makeflags.copy(), extra) + self.do_flavour(packages, makefile, arch, featureset, flavour, + vars.copy(), makeflags.copy(), extra) - def do_flavour(self, packages, makefile, arch, featureset, flavour, vars, makeflags, extra): + def do_flavour(self, packages, makefile, arch, featureset, flavour, vars, + makeflags, extra): config_base = self.config.merge('base', arch, featureset, flavour) vars['localversion'] += '-' + flavour - self.do_flavour_setup(vars, makeflags, arch, featureset, flavour, extra) - self.do_flavour_makefile(makefile, arch, featureset, flavour, makeflags, extra) - self.do_flavour_packages(packages, makefile, arch, featureset, flavour, vars, makeflags, extra) + self.do_flavour_setup(vars, makeflags, arch, featureset, flavour, + extra) + self.do_flavour_makefile(makefile, arch, featureset, flavour, + makeflags, extra) + self.do_flavour_packages(packages, makefile, arch, featureset, flavour, + vars, makeflags, extra) - def do_flavour_setup(self, vars, makeflags, arch, featureset, flavour, extra): + def do_flavour_setup(self, vars, makeflags, arch, featureset, flavour, + extra): for i in ( ('kernel-arch', 'KERNEL_ARCH'), ('localversion', 'LOCALVERSION'), - ): + ): if i[0] in vars: makeflags[i[1]] = vars[i[0]] - def do_flavour_makefile(self, makefile, arch, featureset, flavour, makeflags, extra): + def do_flavour_makefile(self, makefile, arch, featureset, flavour, + makeflags, extra): makeflags['FLAVOUR'] = flavour for i in self.makefile_targets: @@ -270,7 +296,8 @@ class Gencontrol(object): makefile.add(target1, [target2]) makefile.add(target2, [target3]) - def do_flavour_packages(self, packages, makefile, arch, featureset, flavour, vars, makeflags, extra): + def do_flavour_packages(self, packages, makefile, arch, featureset, + flavour, vars, makeflags, extra): pass def process_relation(self, dep, vars): @@ -365,6 +392,7 @@ class Gencontrol(object): f.write(u"%s: %s\n" % (key, value)) f.write('\n') + def merge_packages(packages, new, arch): for new_package in new: name = new_package['Package'] @@ -372,7 +400,8 @@ def merge_packages(packages, new, arch): package = packages.get(name) package['Architecture'].add(arch) - for field in 'Depends', 'Provides', 'Suggests', 'Recommends', 'Conflicts': + for field in ('Depends', 'Provides', 'Suggests', 'Recommends', + 'Conflicts'): if field in new_package: if field in package: v = package[field] diff --git a/debian/lib/python/debian_linux/kconfig.py b/debian/lib/python/debian_linux/kconfig.py index 67309e3a0..73d491d7f 100644 --- a/debian/lib/python/debian_linux/kconfig.py +++ b/debian/lib/python/debian_linux/kconfig.py @@ -19,7 +19,9 @@ class KConfigEntry(object): return hash(self.name) | hash(self.value) def __repr__(self): - return '<{}({!r}, {!r}, {!r})>'.format(self.__class__.__name__, self.name, self.value, self.comments) + return ('<{}({!r}, {!r}, {!r})>' + .format(self.__class__.__name__, self.name, self.value, + self.comments)) def __str__(self): return 'CONFIG_{}={}'.format(self.name, self.value) diff --git a/debian/lib/python/debian_linux/utils.py b/debian/lib/python/debian_linux/utils.py index 5d6a7d473..34c15536d 100644 --- a/debian/lib/python/debian_linux/utils.py +++ b/debian/lib/python/debian_linux/utils.py @@ -44,10 +44,12 @@ def read_control(f): from .debian import Package return _read_rfc822(f, Package) + def read_tests_control(f): from .debian import TestsControl return _read_rfc822(f, TestsControl) + def _read_rfc822(f, cls): entries = [] eof = False @@ -69,14 +71,16 @@ def _read_rfc822(f, cls): break if line[0] in ' \t': if not last: - raise ValueError('Continuation line seen before first header') + raise ValueError( + 'Continuation line seen before first header') lines.append(line.lstrip()) continue if last: e[last] = '\n'.join(lines) i = line.find(':') if i < 0: - raise ValueError(u"Not a header, not a continuation: ``%s''" % line) + raise ValueError(u"Not a header, not a continuation: ``%s''" % + line) last = line[:i] lines = [line[i + 1:].lstrip()] if last: