log2zulip: Replace ujson with json.

This commit is contained in:
derAnfaenger 2017-09-01 10:40:26 +02:00 committed by Tim Abbott
parent 7d1a56fb2b
commit d05e932968

View file

@ -18,7 +18,6 @@ except ImportError:
pass pass
import json import json
import ujson
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../")) sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../"))
import zulip import zulip
@ -71,7 +70,7 @@ def process_logs():
mkdir_p(os.path.dirname(data_file_path)) mkdir_p(os.path.dirname(data_file_path))
if not os.path.exists(data_file_path): if not os.path.exists(data_file_path):
open(data_file_path, "w").write("{}") open(data_file_path, "w").write("{}")
last_data = ujson.loads(open(data_file_path).read()) last_data = json.loads(open(data_file_path).read())
new_data = {} new_data = {}
for log_file in log_files: for log_file in log_files:
file_data = last_data.get(log_file, {}) file_data = last_data.get(log_file, {})
@ -94,7 +93,7 @@ def process_logs():
process_lines(new_lines, filename) process_lines(new_lines, filename)
file_data["last"] += len(new_lines) file_data["last"] += len(new_lines)
new_data[log_file] = file_data new_data[log_file] = file_data
open(data_file_path, "w").write(ujson.dumps(new_data)) open(data_file_path, "w").write(json.dumps(new_data))
if __name__ == "__main__": if __name__ == "__main__":
if os.path.exists(lock_path): if os.path.exists(lock_path):
@ -105,8 +104,8 @@ if __name__ == "__main__":
open(lock_path, "w").write("1") open(lock_path, "w").write("1")
zulip_client = zulip.Client(config_file="/etc/log2zulip.zuliprc") zulip_client = zulip.Client(config_file="/etc/log2zulip.zuliprc")
try: try:
log_files = ujson.loads(open(control_path, "r").read()) log_files = json.loads(open(control_path, "r").read())
except Exception: except (json.JSONDecodeError, IOError):
print("Could not load control data from %s" % (control_path,)) print("Could not load control data from %s" % (control_path,))
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)