From 43dcba2f74b6a69ae9140a90121144f82941a6a8 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Mon, 24 Feb 2020 08:27:33 +0100 Subject: [PATCH] Move to Python 3. --- SConstruct | 11 +++++------ defines.py | 19 ++++++++++++++++--- packaging/osx/pkgbuild.py | 2 +- packaging/osx/productbuild.py | 2 +- packaging/osx/template.py | 4 ++-- packaging/windows/innosetup.py | 16 +++++++++------- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/SConstruct b/SConstruct index 176403d4..6fc3506d 100644 --- a/SConstruct +++ b/SConstruct @@ -119,7 +119,7 @@ class FreelanEnvironment(Environment): self.Append(CXXFLAGS=['-Wextra']) self.Append(CXXFLAGS=['-Werror']) self.Append(CXXFLAGS=['-pedantic']) - self.Append(CXXFLAGS=['-Wshadow']) + #self.Append(CXXFLAGS=['-Wshadow']) self.Append(LDFLAGS=['--std=c++11']) if sys.platform.startswith('darwin'): @@ -156,10 +156,10 @@ class FreelanEnvironment(Environment): self.Append(CXXFLAGS='-O3') if self.mongoose == 'yes': - self.Append(CXXFLAGS=['-DUSE_MONGOOSE']) + self.Append(CXXFLAGS=['-DUSE_MONGOOSE']) if self.upnp == 'yes': - self.Append(CXXFLAGS=['-DUSE_UPNP']) + self.Append(CXXFLAGS=['-DUSE_UPNP']) self.Append(CPPDEFINES=r'FREELAN_INSTALL_PREFIX="\"%s\""' % self.prefix) @@ -168,11 +168,10 @@ class FreelanEnvironment(Environment): Returns a list of file objects that match the specified patterns. """ - path = unicode(path) - - if isinstance(patterns, basestring): + if isinstance(patterns, str): patterns = [patterns] + path = str(path) result = [] abspath = Dir(path).srcnode().abspath diff --git a/defines.py b/defines.py index 011a50f7..5483ce67 100644 --- a/defines.py +++ b/defines.py @@ -100,7 +100,10 @@ def replace_template_variables(self, content): Return the content. """ - return content.format(defines=self) + if isinstance(content, str): + return content.format(defines=self) + else: + return content.decode().format(defines=self).encode() def emitter(self, target, source, env): """ @@ -120,7 +123,12 @@ def action(self, target, source, env): output = self.replace_template_variables(source[0].get_contents()) - with open(target[0].abspath, 'wb') as out: + flag = 'wb' + + if isinstance(output, str): + flag = 'w' + + with open(target[0].abspath, flag) as out: out.write(output) def register_into(self, env): @@ -149,7 +157,12 @@ def generate_defines(self, target): current_content = None if output != current_content: - with open(target, 'w') as target_file: + flag = 'wb' + + if isinstance(output, str): + flag = 'w' + + with open(target, flag) as target_file: target_file.write(output) if __name__ == '__main__': diff --git a/packaging/osx/pkgbuild.py b/packaging/osx/pkgbuild.py index 03a02429..6b494b86 100644 --- a/packaging/osx/pkgbuild.py +++ b/packaging/osx/pkgbuild.py @@ -19,7 +19,7 @@ def pkgbuild_generator(target, source, env, for_signature): options = env['PKGBUILD_OPTIONS'].value options_str = ' '.join( '--%s %s' % (key, value) - for key, value in options.iteritems() + for key, value in options.items() ) if env['PKGBUILD_SCRIPTS']: diff --git a/packaging/osx/productbuild.py b/packaging/osx/productbuild.py index 232f0978..2d6ff19f 100644 --- a/packaging/osx/productbuild.py +++ b/packaging/osx/productbuild.py @@ -68,7 +68,7 @@ def productbuild_generator(target, source, env, for_signature): options = env['PRODUCTBUILD_OPTIONS'].value options_str = ' '.join( '--%s %s' % (key, value) - for key, value in options.iteritems() + for key, value in options.items() ) if env['PRODUCTBUILD_RESOURCES']: diff --git a/packaging/osx/template.py b/packaging/osx/template.py index 563b0fd6..69281e3d 100644 --- a/packaging/osx/template.py +++ b/packaging/osx/template.py @@ -12,9 +12,9 @@ def template_action(target, source, env): template = source[0].get_contents() - with open(target[0].abspath, 'w') as targf: + with open(target[0].abspath, 'wb') as targf: targf.write( - template.format(**_dict) + template.decode().format(**_dict).encode() ) diff --git a/packaging/windows/innosetup.py b/packaging/windows/innosetup.py index ea201ed6..c2e5e295 100644 --- a/packaging/windows/innosetup.py +++ b/packaging/windows/innosetup.py @@ -19,6 +19,7 @@ def replacer(match): pattern = ';.*?$|"[^"]*"|\'[^"]*\'' + text = str(text) return re.sub(re.compile(pattern, re.DOTALL | re.MULTILINE), replacer, text) @@ -27,6 +28,7 @@ def parse_define(line): pattern = r'#(?:\s)*define\s*([\w_]+)(?:\s)*["\']?(.*)["\']' + line = str(line) match = re.match(pattern, line, re.IGNORECASE) if match: @@ -57,12 +59,12 @@ def replace_defines(text, defines): def get_config(source, env): """Get a configuration from the specified source.""" - import ConfigParser - import StringIO + import configparser + from io import StringIO - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser(strict=False) config.readfp( - StringIO.StringIO(replace_defines(source.get_contents(), env['ISCC_DEFINES']))) + StringIO(replace_defines(source.get_contents().decode(), env['ISCC_DEFINES']))) return config @@ -154,7 +156,7 @@ def to_define_option(item): ' '.join(env['ISCC_FLAGS']), ' '.join('"/i%s"' % x for x in env['ISCC_PATH']), ' '.join([to_define_option(x) - for x in env['ISCC_DEFINES'].iteritems()]), + for x in env['ISCC_DEFINES'].items()]), os.path.dirname(str(target[0])), os.path.splitext(os.path.basename(str(target[0])))[0], source[0] @@ -179,8 +181,8 @@ def detect(env): return iscc paths = [ - os.path.join(os.environ.get('PROGRAMFILES', ''), 'Inno Setup 5'), - os.path.join(os.environ.get('PROGRAMFILES(X86)', ''), 'Inno Setup 5'), + os.path.join(os.environ.get('PROGRAMFILES', ''), 'Inno Setup 6'), + os.path.join(os.environ.get('PROGRAMFILES(X86)', ''), 'Inno Setup 6'), ] for path in paths: