Index: lnt/server/db/rules/rule_update_profile_stats.py =================================================================== --- lnt/server/db/rules/rule_update_profile_stats.py +++ lnt/server/db/rules/rule_update_profile_stats.py @@ -20,7 +20,8 @@ return try: - history = json.loads(open(history_path).read()) + with open(history_path) as f: + history = json.loads(f.read()) except Exception: history = [] age = [] @@ -38,8 +39,10 @@ sz = os.stat(f).st_size // 1000 age.append([mtime, sz]) - open(history_path, 'w').write(json.dumps(history)) - open(age_path, 'w').write(json.dumps(age)) + with open(history_path, 'w') as history_f: + history_f.write(json.dumps(history)) + with open(age_path, 'w') as age_f: + age_f.write(json.dumps(age)) post_submission_hook = update_profile_stats Index: lnt/server/instance.py =================================================================== --- lnt/server/instance.py +++ lnt/server/instance.py @@ -54,7 +54,8 @@ raise Exception("Invalid config: %r" % config_path) config_data = {} - exec(open(config_path).read(), config_data) + with open(config_path) as f: + exec(f.read(), config_data) config = lnt.server.config.Config.from_data(config_path, config_data) return Instance(config_path, config, tmpdir) Index: lnt/testing/profile/perf.py =================================================================== --- lnt/testing/profile/perf.py +++ lnt/testing/profile/perf.py @@ -18,7 +18,8 @@ @staticmethod def checkFile(fn): - return open(fn, 'rb').read(8) == b'PERFILE2' + with open(fn, 'rb') as f: + return f.read(8) == b'PERFILE2' @staticmethod def deserialize(f, nm='nm', objdump='objdump', propagateExceptions=False): Index: lnt/testing/profile/profilev1impl.py =================================================================== --- lnt/testing/profile/profilev1impl.py +++ lnt/testing/profile/profilev1impl.py @@ -45,7 +45,8 @@ @staticmethod def checkFile(fn): # "zlib compressed data" - 78 9C - return open(fn, 'rb').read(2) == b'\x78\x9c' + with open(fn, 'rb') as f: + return f.read(2) == b'\x78\x9c' @staticmethod def deserialize(fobj): Index: lnt/testing/profile/profilev2impl.py =================================================================== --- lnt/testing/profile/profilev2impl.py +++ lnt/testing/profile/profilev2impl.py @@ -560,7 +560,8 @@ def checkFile(fn): # The first number is the version (2); ULEB encoded this is simply # 0x02. - return open(fn, 'rb').read(1) == b'\x02' + with open(fn, 'rb') as f: + return f.read(1) == b'\x02' @staticmethod def deserialize(fobj): Index: lnt/testing/util/compilers.py =================================================================== --- lnt/testing/util/compilers.py +++ lnt/testing/util/compilers.py @@ -186,7 +186,8 @@ (cc, cc_target_assembly)) cc_exec_hash = hashlib.sha1() - cc_exec_hash.update(open(cc, 'rb').read()) + with open(cc, 'rb') as f: + cc_exec_hash.update(f.read()) info = { 'cc_build': cc_build, Index: lnt/tests/test_suite.py =================================================================== --- lnt/tests/test_suite.py +++ lnt/tests/test_suite.py @@ -639,7 +639,8 @@ # failures! pass try: - return json.loads(open(output_json_path.name).read()) + with open(output_json_path.name) as f: + return json.loads(f.read()) except ValueError as e: fatal("Running test-suite did not create valid json report " "in {}: {}".format(output_json_path.name, e))