From 3b67a7886f6276820e726e6140b3c6700981db26 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 19:49:35 +0000 Subject: [PATCH] feat: make FileLock path configurable - Add lock_path parameter to OpenSerial.__init__ - Default to /tmp/serial.lock or NOTECARD_SERIAL_LOCK_PATH env var - Fix docstring formatting Fixes #63 Co-Authored-By: rlauer@blues.com --- notecard/notecard.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/notecard/notecard.py b/notecard/notecard.py index 3ac22ac..fabd7d1 100644 --- a/notecard/notecard.py +++ b/notecard/notecard.py @@ -574,8 +574,15 @@ def unlock(self): """Unlock access to the serial bus.""" self.lock_handle.release() - def __init__(self, uart_id, debug=False): - """Initialize the Notecard before a reset.""" + def __init__(self, uart_id, debug=False, lock_path=None): + """Initialize the Notecard before a reset. + + Args: + uart_id: The serial port identifier. + debug: Enable debug output if True. + lock_path: Optional path for the serial lock file. Defaults to /tmp/serial.lock + or the value of NOTECARD_SERIAL_LOCK_PATH environment variable. + """ super().__init__(debug) self._user_agent['req_interface'] = 'serial' self._user_agent['req_port'] = str(uart_id) @@ -583,7 +590,9 @@ def __init__(self, uart_id, debug=False): self.uart = uart_id if use_serial_lock: - self.lock_handle = FileLock('serial.lock') + if lock_path is None: + lock_path = os.environ.get('NOTECARD_SERIAL_LOCK_PATH', '/tmp/serial.lock') + self.lock_handle = FileLock(lock_path) else: self.lock_handle = NoOpSerialLock()