webhooks: Specify server_address on klippy command-line

Don't default to "/tmp/klippy_uds" for the webhooks unix domain socket
filename.  Instead, require the filename to be specified on the
command-line (via a new "-a" parameter).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-08-11 16:26:07 -04:00
parent ebc79a1ee8
commit 0aad2437c5
2 changed files with 11 additions and 9 deletions

View file

@ -11,8 +11,6 @@ import errno
import json
import homing
SERVER_ADDRESS = "/tmp/klippy_uds"
# Json decodes strings as unicode types in Python 2.x. This doesn't
# play well with some parts of Klipper (particuarly displays), so we
# need to create an object hook. This solution borrowed from:
@ -98,15 +96,16 @@ class ServerSocket:
self.reactor = printer.get_reactor()
self.sock = self.fd_handle = None
self.clients = {}
is_fileinput = (printer.get_start_args().get('debuginput')
is not None)
if is_fileinput:
# Do not enable server in batch mode
start_args = printer.get_start_args()
server_address = start_args.get('apiserver')
is_fileinput = (start_args.get('debuginput') is not None)
if not server_address or is_fileinput:
# Do not enable server
return
self._remove_socket_file(SERVER_ADDRESS)
self._remove_socket_file(server_address)
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.setblocking(0)
self.sock.bind(SERVER_ADDRESS)
self.sock.bind(server_address)
self.sock.listen(1)
self.fd_handle = self.reactor.register_fd(
self.sock.fileno(), self._handle_accept)