# value of the variable.
def build_config_file(target, source, env):
(variable, value) = [s.get_contents() for s in source]
- f = file(str(target[0]), 'w')
- print('#define', variable, value, file=f)
- f.close()
+ with open(str(target[0]), 'w') as f:
+ print('#define', variable, value, file=f)
return None
# Combine the two functions into a scons Action object.
cpp_path = path_noext + '.cc'
hpp_path = path_noext + '.hh'
def embedBlob(target, source, env):
- data = file(str(source[0]), 'r').read()
+ with open(str(source[0]), 'rb') as f:
+ data = f.read()
cpp_code = code_formatter()
hpp_code = code_formatter()
blobToCpp(data, symbol, cpp_code, hpp_code, namespace='Blobs')
mod.__path__ = source.modpath
mod.__file__ = source.abspath
- exec file(source.abspath, 'r') in mod.__dict__
+ compiled = compile(open(source.abspath).read(), source.abspath, 'exec')
+ exec(compiled, mod.__dict__)
return mod
def makeInfoPyFile(target, source, env):
code = code_formatter()
for src in source:
- data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
+ with open(src.srcnode().abspath, 'r') as f:
+ data = ''.join(f)
code('$src = ${{repr(data)}}')
code.write(str(target[0]))
generated_dir = Dir('protocol')
def MakeIncludeAction(target, source, env):
- f = file(str(target[0]), 'w')
- for s in source:
- print('#include "%s"' % str(s.abspath), file=f)
- f.close()
+ with open(str(target[0]), 'w') as f:
+ for s in source:
+ print('#include "%s"' % str(s.abspath), file=f)
def MakeInclude(source):
target = generated_dir.File(basename(source))