1
1
#!/usr/bin/env python
2
2
from __future__ import print_function
3
3
4
+ import argparse
4
5
import errno
5
6
import os
6
7
import platform
@@ -24,7 +25,6 @@ import zulip
24
25
from typing import List
25
26
26
27
lock_path = "/var/tmp/log2zulip.lock"
27
- control_path = "/etc/log2zulip.conf"
28
28
29
29
def mkdir_p (path ):
30
30
# type: (str) -> None
@@ -96,17 +96,24 @@ def process_logs():
96
96
open (data_file_path , "w" ).write (json .dumps (new_data ))
97
97
98
98
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
+
99
106
if os .path .exists (lock_path ):
100
107
print ("Log2zulip lock held; not doing anything" )
101
108
sys .exit (0 )
102
109
103
110
try :
104
111
open (lock_path , "w" ).write ("1" )
105
- zulip_client = zulip .Client ( config_file = "/etc/log2zulip.zuliprc" )
112
+ zulip_client = zulip .init_from_options ( args )
106
113
try :
107
- log_files = json .loads (open (control_path , "r" ).read ())
114
+ log_files = json .loads (open (args . control_path , "r" ).read ())
108
115
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 ,))
110
117
traceback .print_exc ()
111
118
sys .exit (1 )
112
119
process_logs ()
0 commit comments