Skip to content

Commit 761d4f4

Browse files
roberthoenigtimabbott
authored andcommitted
log2zulip: Use default argparser.
1 parent 3af373a commit 761d4f4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

zulip/integrations/log2zulip/log2zulip

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
from __future__ import print_function
33

4+
import argparse
45
import errno
56
import os
67
import platform
@@ -24,7 +25,6 @@ import zulip
2425
from typing import List
2526

2627
lock_path = "/var/tmp/log2zulip.lock"
27-
control_path = "/etc/log2zulip.conf"
2828

2929
def mkdir_p(path):
3030
# type: (str) -> None
@@ -96,17 +96,24 @@ def process_logs():
9696
open(data_file_path, "w").write(json.dumps(new_data))
9797

9898
if __name__ == "__main__":
99+
parser = zulip.add_default_arguments(argparse.ArgumentParser()) # type: argparse.ArgumentParser3
100+
parser.add_argument("--control-path", default="/etc/log2zulip.conf")
101+
args = parser.parse_args()
102+
# On posix systems, we set the config directory explicitly for legacy reasons.
103+
if not args.zulip_config_file and os.name == "posix":
104+
args.zulip_config_file = "/etc/log2zulip.zuliprc"
105+
99106
if os.path.exists(lock_path):
100107
print("Log2zulip lock held; not doing anything")
101108
sys.exit(0)
102109

103110
try:
104111
open(lock_path, "w").write("1")
105-
zulip_client = zulip.Client(config_file="/etc/log2zulip.zuliprc")
112+
zulip_client = zulip.init_from_options(args)
106113
try:
107-
log_files = json.loads(open(control_path, "r").read())
114+
log_files = json.loads(open(args.control_path, "r").read())
108115
except (json.JSONDecodeError, IOError):
109-
print("Could not load control data from %s" % (control_path,))
116+
print("Could not load control data from %s" % (args.control_path,))
110117
traceback.print_exc()
111118
sys.exit(1)
112119
process_logs()

0 commit comments

Comments
 (0)