Skip to content

Commit

Permalink
Move to Python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-vincent committed Feb 24, 2020
1 parent 74faa06 commit 43dcba2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
11 changes: 5 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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)

Expand All @@ -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

Expand Down
19 changes: 16 additions & 3 deletions defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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__':
Expand Down
2 changes: 1 addition & 1 deletion packaging/osx/pkgbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
2 changes: 1 addition & 1 deletion packaging/osx/productbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
4 changes: 2 additions & 2 deletions packaging/osx/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)


Expand Down
16 changes: 9 additions & 7 deletions packaging/windows/innosetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def replacer(match):

pattern = ';.*?$|"[^"]*"|\'[^"]*\''

text = str(text)
return re.sub(re.compile(pattern, re.DOTALL | re.MULTILINE), replacer, text)


Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand All @@ -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:
Expand Down

0 comments on commit 43dcba2

Please sign in to comment.