From ab2692b2178a67635b7491cb0f6ed999ff7e9506 Mon Sep 17 00:00:00 2001 From: Eklavya Sharma Date: Thu, 10 Mar 2016 22:48:37 +0530 Subject: [PATCH] Apply Python 3 futurize transform libmodernize.fixes.fix_file Refer to #256 --- bots/log2zulip | 10 +++++----- bots/process_ccache | 8 ++++---- bots/sync-public-streams | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bots/log2zulip b/bots/log2zulip index 32b509d..09449b6 100755 --- a/bots/log2zulip +++ b/bots/log2zulip @@ -56,8 +56,8 @@ def process_logs(): data_file_path = "/var/tmp/log2zulip.state" mkdir_p(os.path.dirname(data_file_path)) if not os.path.exists(data_file_path): - file(data_file_path, "w").write("{}") - last_data = ujson.loads(file(data_file_path).read()) + open(data_file_path, "w").write("{}") + last_data = ujson.loads(open(data_file_path).read()) new_data = {} for log_file in log_files: file_data = last_data.get(log_file, {}) @@ -79,7 +79,7 @@ def process_logs(): process_lines(new_lines, filename) file_data["last"] += len(new_lines) new_data[log_file] = file_data - file(data_file_path, "w").write(ujson.dumps(new_data)) + open(data_file_path, "w").write(ujson.dumps(new_data)) if __name__ == "__main__": if os.path.exists(lock_path): @@ -87,10 +87,10 @@ if __name__ == "__main__": sys.exit(0) try: - file(lock_path, "w").write("1") + open(lock_path, "w").write("1") zulip_client = zulip.Client(config_file="/etc/log2zulip.zuliprc") try: - log_files = ujson.loads(file(control_path, "r").read()) + log_files = ujson.loads(open(control_path, "r").read()) except Exception: print("Could not load control data from %s" % (control_path,)) traceback.print_exc() diff --git a/bots/process_ccache b/bots/process_ccache index 04a7265..28a0bd4 100755 --- a/bots/process_ccache +++ b/bots/process_ccache @@ -14,22 +14,22 @@ with open("/home/zulip/ccache/%s" % (program_name,), "w") as f: # Setup API key api_key_path = "/home/zulip/api-keys/%s" % (program_name,) -file(api_key_path, "w").write(api_key + "\n") +open(api_key_path, "w").write(api_key + "\n") # Setup supervisord configuration supervisor_path = "/etc/supervisor/conf.d/%s.conf" % (program_name,) template = "/home/zulip/zulip/bots/zmirror_private.conf.template" -template_data = file(template).read() +template_data = open(template).read() session_path = "/home/zulip/zephyr_sessions/%s" % (program_name,) # Preserve mail zephyrs forwarding setting across rewriting the config file try: - if "--forward-mail-zephyrs" in file(supervisor_path, "r").read(): + if "--forward-mail-zephyrs" in open(supervisor_path, "r").read(): template_data = template_data.replace("--use-sessions", "--use-sessions --forward-mail-zephyrs") except Exception: pass -file(supervisor_path, "w").write(template_data.replace("USERNAME", short_user)) +open(supervisor_path, "w").write(template_data.replace("USERNAME", short_user)) # Delete your session subprocess.check_call(["rm", "-f", session_path]) diff --git a/bots/sync-public-streams b/bots/sync-public-streams index e890586..46a3fd7 100755 --- a/bots/sync-public-streams +++ b/bots/sync-public-streams @@ -59,7 +59,7 @@ if __name__ == "__main__": if public_streams is None: continue - f = file("/home/zulip/public_streams.tmp", "w") + f = open("/home/zulip/public_streams.tmp", "w") f.write(simplejson.dumps(list(public_streams)) + "\n") f.close()