Apply Python 3 futurize transform libmodernize.fixes.fix_file

Refer to #256
This commit is contained in:
Eklavya Sharma
2016-03-10 22:48:37 +05:30
committed by Tim Abbott
parent e83a2c8cc2
commit d3b63f9a2d
6 changed files with 13 additions and 13 deletions

View File

@@ -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()

View File

@@ -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])

View File

@@ -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()

View File

@@ -31,7 +31,7 @@ down_count = 0
for results_file_name in os.listdir(RESULTS_DIR):
this_state = "OK"
results_file = os.path.join(RESULTS_DIR, results_file_name)
data = file(results_file).read().strip()
data = open(results_file).read().strip()
last_check = os.stat(results_file).st_mtime
time_since_last_check = time.time() - last_check
# time_since_last_check threshhold needs to be strictly greater

View File

@@ -28,7 +28,7 @@ def report(state, data, last_check):
data))
exit(states[state])
data = file(RESULTS_FILE).read().strip()
data = open(RESULTS_FILE).read().strip()
if data.split("\n")[-1].strip() == "0":
state = "OK"
else:

View File

@@ -87,7 +87,7 @@ def maybe_assign_character(character):
characters[character] = dict(users[user])
characters[character]['intro'] = '(as ' + character.title() + ")\n"
play = file(os.path.dirname(__file__) + os.path.sep + "othello")
play = open(os.path.dirname(__file__) + os.path.sep + "othello")
next_character = None
next_message = ""
act = ""