1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 08:40:34 +03:00

journal_lock: Convert to logger.trace_if(...)

This commit is contained in:
Athanasius 2021-08-13 14:22:14 +01:00
parent df84b8aa64
commit bb1faa67d4
No known key found for this signature in database
GPG Key ID: AE3E527847057C7D

View File

@ -56,7 +56,7 @@ class JournalLock:
def open_journal_dir_lockfile(self) -> bool: def open_journal_dir_lockfile(self) -> bool:
"""Open journal_dir lockfile ready for locking.""" """Open journal_dir lockfile ready for locking."""
self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' # type: ignore self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' # type: ignore
logger.trace(f'journal_dir_lockfile_name = {self.journal_dir_lockfile_name!r}') logger.trace_if('journal-lock', f'journal_dir_lockfile_name = {self.journal_dir_lockfile_name!r}')
try: try:
self.journal_dir_lockfile = open(self.journal_dir_lockfile_name, mode='w+', encoding='utf-8') self.journal_dir_lockfile = open(self.journal_dir_lockfile_name, mode='w+', encoding='utf-8')
@ -95,7 +95,7 @@ class JournalLock:
:return: LockResult - See the class Enum definition :return: LockResult - See the class Enum definition
""" """
if platform == 'win32': if platform == 'win32':
logger.trace('win32, using msvcrt') logger.trace_if('journal-lock', 'win32, using msvcrt')
# win32 doesn't have fcntl, so we have to use msvcrt # win32 doesn't have fcntl, so we have to use msvcrt
import msvcrt import msvcrt
@ -108,7 +108,7 @@ class JournalLock:
return JournalLockResult.ALREADY_LOCKED return JournalLockResult.ALREADY_LOCKED
else: # pytest coverage only sees this on !win32 else: # pytest coverage only sees this on !win32
logger.trace('NOT win32, using fcntl') logger.trace_if('journal-lock', 'NOT win32, using fcntl')
try: try:
import fcntl import fcntl
@ -128,7 +128,7 @@ class JournalLock:
self.journal_dir_lockfile.write(f"Path: {self.journal_dir}\nPID: {os_getpid()}\n") self.journal_dir_lockfile.write(f"Path: {self.journal_dir}\nPID: {os_getpid()}\n")
self.journal_dir_lockfile.flush() self.journal_dir_lockfile.flush()
logger.trace('Done') logger.trace_if('journal-lock', 'Done')
self.locked = True self.locked = True
return JournalLockResult.LOCKED return JournalLockResult.LOCKED
@ -144,7 +144,7 @@ class JournalLock:
unlocked = False unlocked = False
if platform == 'win32': if platform == 'win32':
logger.trace('win32, using msvcrt') logger.trace_if('journal-lock', 'win32, using msvcrt')
# win32 doesn't have fcntl, so we have to use msvcrt # win32 doesn't have fcntl, so we have to use msvcrt
import msvcrt import msvcrt
@ -161,7 +161,7 @@ class JournalLock:
unlocked = True unlocked = True
else: # pytest coverage only sees this on !win32 else: # pytest coverage only sees this on !win32
logger.trace('NOT win32, using fcntl') logger.trace_if('journal-lock', 'NOT win32, using fcntl')
try: try:
import fcntl import fcntl
@ -235,19 +235,19 @@ class JournalLock:
def retry(self) -> None: def retry(self) -> None:
"""Handle user electing to Retry obtaining the lock.""" """Handle user electing to Retry obtaining the lock."""
logger.trace('User selected: Retry') logger.trace_if('journal-lock_if', 'User selected: Retry')
self.destroy() self.destroy()
self.callback(True, self.parent) self.callback(True, self.parent)
def ignore(self) -> None: def ignore(self) -> None:
"""Handle user electing to Ignore failure to obtain the lock.""" """Handle user electing to Ignore failure to obtain the lock."""
logger.trace('User selected: Ignore') logger.trace_if('journal-lock', 'User selected: Ignore')
self.destroy() self.destroy()
self.callback(False, self.parent) self.callback(False, self.parent)
def _destroy(self) -> None: def _destroy(self) -> None:
"""Destroy the Retry/Ignore popup.""" """Destroy the Retry/Ignore popup."""
logger.trace('User force-closed popup, treating as Ignore') logger.trace_if('journal-lock', 'User force-closed popup, treating as Ignore')
self.ignore() self.ignore()
def update_lock(self, parent: tk.Tk) -> None: def update_lock(self, parent: tk.Tk) -> None:
@ -277,7 +277,7 @@ class JournalLock:
:param retry: - does the user want to retry? Comes from the dialogue choice. :param retry: - does the user want to retry? Comes from the dialogue choice.
:param parent: - The parent tkinter window. :param parent: - The parent tkinter window.
""" """
logger.trace(f'We should retry: {retry}') logger.trace_if('journal-lock', f'We should retry: {retry}')
if not retry: if not retry:
return return