mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 16:27:13 +03:00
Support accessing Journal on macOS remotely over SMB
This commit is contained in:
parent
88f6e28e75
commit
96ffc82ca7
18
monitor.py
18
monitor.py
@ -21,7 +21,9 @@ if platform=='darwin':
|
||||
from Foundation import NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
|
||||
from fcntl import fcntl
|
||||
F_GLOBAL_NOCACHE = 55
|
||||
|
||||
elif platform=='win32':
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
@ -216,13 +218,16 @@ class EDLogs(FileSystemEventHandler):
|
||||
# Seek to the end of the latest log file
|
||||
logfile = self.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:
|
||||
try:
|
||||
self.parse_entry(line) # Some events are of interest even in the past
|
||||
except:
|
||||
if __debug__:
|
||||
print 'Invalid journal entry "%s"' % repr(line)
|
||||
logpos = loghandle.tell()
|
||||
else:
|
||||
loghandle = None
|
||||
|
||||
@ -272,16 +277,21 @@ class EDLogs(FileSystemEventHandler):
|
||||
if loghandle:
|
||||
loghandle.close()
|
||||
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__:
|
||||
print 'New logfile "%s"' % 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:
|
||||
self.event_queue.append(line)
|
||||
if self.event_queue:
|
||||
self.root.event_generate('<<JournalEvent>>', when="tail")
|
||||
logpos = loghandle.tell()
|
||||
|
||||
sleep(self._POLL)
|
||||
|
||||
|
22
prefs.py
22
prefs.py
@ -199,21 +199,17 @@ class PreferencesDialog(tk.Toplevel):
|
||||
self.logdir.set(config.get('journaldir') or config.default_journal_dir or '')
|
||||
self.logdir_entry = nb.Entry(configframe, takefocus=False)
|
||||
|
||||
if platform != 'darwin':
|
||||
# Apple's SMB implementation is way too flaky - no filesystem events and bogus NULLs
|
||||
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.logdir_entry.grid(columnspan=4, padx=PADX, pady=(0,PADY), sticky=tk.EW)
|
||||
self.logbutton = nb.Button(configframe, text=(platform=='darwin' and _('Change...') or # Folder selection button on OSX
|
||||
_('Browse...')), # Folder selection button on Windows
|
||||
command = lambda:self.filebrowse(_('E:D journal file location'), self.logdir))
|
||||
self.logbutton.grid(row=10, column=3, padx=PADX, pady=PADY, sticky=tk.EW)
|
||||
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)
|
||||
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.logdir_entry.grid(columnspan=4, padx=PADX, pady=(0,PADY), sticky=tk.EW)
|
||||
self.logbutton = nb.Button(configframe, text=(platform=='darwin' and _('Change...') or # Folder selection button on OSX
|
||||
_('Browse...')), # Folder selection button on Windows
|
||||
command = lambda:self.filebrowse(_('E:D journal file location'), self.logdir))
|
||||
self.logbutton.grid(row=10, column=3, padx=PADX, pady=PADY, sticky=tk.EW)
|
||||
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 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_mods = config.getint('hotkey_mods')
|
||||
self.hotkey_only = tk.IntVar(value = not config.getint('hotkey_always'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user