1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-10 04:12:15 +03:00

Support accessing Journal on macOS remotely over SMB

This commit is contained in:
Jonathan Harris 2018-10-30 19:27:19 +00:00
parent 88f6e28e75
commit 96ffc82ca7
2 changed files with 23 additions and 17 deletions

View File

@ -21,6 +21,8 @@ if platform=='darwin':
from Foundation import NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask from Foundation import NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
from fcntl import fcntl
F_GLOBAL_NOCACHE = 55
elif platform=='win32': elif platform=='win32':
from watchdog.observers import Observer from watchdog.observers import Observer
@ -216,13 +218,16 @@ class EDLogs(FileSystemEventHandler):
# Seek to the end of the latest log file # Seek to the end of the latest log file
logfile = self.logfile logfile = self.logfile
if logfile: if logfile:
loghandle = open(logfile, 'r') loghandle = open(logfile, 'rb', 0) # unbuffered
if platform == 'darwin':
fcntl(loghandle, F_GLOBAL_NOCACHE, -1) # required to avoid corruption on macOS over SMB
for line in loghandle: for line in loghandle:
try: try:
self.parse_entry(line) # Some events are of interest even in the past self.parse_entry(line) # Some events are of interest even in the past
except: except:
if __debug__: if __debug__:
print 'Invalid journal entry "%s"' % repr(line) print 'Invalid journal entry "%s"' % repr(line)
logpos = loghandle.tell()
else: else:
loghandle = None loghandle = None
@ -272,16 +277,21 @@ class EDLogs(FileSystemEventHandler):
if loghandle: if loghandle:
loghandle.close() loghandle.close()
if logfile: if logfile:
loghandle = open(logfile, 'r') loghandle = open(logfile, 'rb', 0) # unbuffered
if platform == 'darwin':
fcntl(loghandle, F_GLOBAL_NOCACHE, -1) # required to avoid corruption on macOS over SMB
logpos = 0
if __debug__: if __debug__:
print 'New logfile "%s"' % logfile print 'New logfile "%s"' % logfile
if logfile: if logfile:
loghandle.seek(0, SEEK_CUR) # reset EOF flag loghandle.seek(0, SEEK_END) # required to make macOS notice log change over SMB
loghandle.seek(logpos, SEEK_SET) # reset EOF flag
for line in loghandle: for line in loghandle:
self.event_queue.append(line) self.event_queue.append(line)
if self.event_queue: if self.event_queue:
self.root.event_generate('<<JournalEvent>>', when="tail") self.root.event_generate('<<JournalEvent>>', when="tail")
logpos = loghandle.tell()
sleep(self._POLL) sleep(self._POLL)

View File

@ -199,21 +199,17 @@ class PreferencesDialog(tk.Toplevel):
self.logdir.set(config.get('journaldir') or config.default_journal_dir or '') self.logdir.set(config.get('journaldir') or config.default_journal_dir or '')
self.logdir_entry = nb.Entry(configframe, takefocus=False) self.logdir_entry = nb.Entry(configframe, takefocus=False)
if platform != 'darwin': nb.Label(configframe, text = _('E:D journal file location')+':').grid(columnspan=4, padx=PADX, sticky=tk.W) # Location of the new Journal file in E:D 2.2
# Apple's SMB implementation is way too flaky - no filesystem events and bogus NULLs self.logdir_entry.grid(columnspan=4, padx=PADX, pady=(0,PADY), sticky=tk.EW)
nb.Label(configframe, text = _('E:D journal file location')+':').grid(columnspan=4, padx=PADX, sticky=tk.W) # Location of the new Journal file in E:D 2.2 self.logbutton = nb.Button(configframe, text=(platform=='darwin' and _('Change...') or # Folder selection button on OSX
self.logdir_entry.grid(columnspan=4, padx=PADX, pady=(0,PADY), sticky=tk.EW) _('Browse...')), # Folder selection button on Windows
self.logbutton = nb.Button(configframe, text=(platform=='darwin' and _('Change...') or # Folder selection button on OSX command = lambda:self.filebrowse(_('E:D journal file location'), self.logdir))
_('Browse...')), # Folder selection button on Windows self.logbutton.grid(row=10, column=3, padx=PADX, pady=PADY, sticky=tk.EW)
command = lambda:self.filebrowse(_('E:D journal file location'), self.logdir)) if config.default_journal_dir:
self.logbutton.grid(row=10, column=3, padx=PADX, pady=PADY, sticky=tk.EW) nb.Button(configframe, text=_('Default'), command=self.logdir_reset, state = config.get('journaldir') and tk.NORMAL or tk.DISABLED).grid(row=10, column=2, pady=PADY, sticky=tk.EW) # Appearance theme and language setting
if config.default_journal_dir:
nb.Button(configframe, text=_('Default'), command=self.logdir_reset, state = config.get('journaldir') and tk.NORMAL or tk.DISABLED).grid(row=10, column=2, pady=PADY, sticky=tk.EW) # Appearance theme and language setting
if platform == 'win32':
ttk.Separator(configframe, orient=tk.HORIZONTAL).grid(columnspan=4, padx=PADX, pady=PADY*4, sticky=tk.EW)
if platform in ['darwin','win32']: if platform in ['darwin','win32']:
ttk.Separator(configframe, orient=tk.HORIZONTAL).grid(columnspan=4, padx=PADX, pady=PADY*4, sticky=tk.EW)
self.hotkey_code = config.getint('hotkey_code') self.hotkey_code = config.getint('hotkey_code')
self.hotkey_mods = config.getint('hotkey_mods') self.hotkey_mods = config.getint('hotkey_mods')
self.hotkey_only = tk.IntVar(value = not config.getint('hotkey_always')) self.hotkey_only = tk.IntVar(value = not config.getint('hotkey_always'))