mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 01:22:19 +03:00
Enable VerboseLogging in local or remote client
Partially reverts 7821f2a.
This commit is contained in:
parent
8b311056dc
commit
176016090f
99
monitor.py
99
monitor.py
@ -73,6 +73,51 @@ class EDLogs(FileSystemEventHandler):
|
||||
self.callbacks = { 'Jump': None, 'Dock': None }
|
||||
self.last_event = None # for communicating the Jump event
|
||||
|
||||
def logging_enabled_in_file(self, appconf):
|
||||
if not isfile(appconf):
|
||||
return False
|
||||
|
||||
with open(appconf, 'rU') as f:
|
||||
content = f.read().lower()
|
||||
start = content.find('<network')
|
||||
end = content.find('</network>')
|
||||
if start >= 0 and end >= 0:
|
||||
return bool(re.search('verboselogging\s*=\s*\"1\"', content[start+8:end]))
|
||||
else:
|
||||
return False
|
||||
|
||||
def enable_logging_in_file(self, appconf):
|
||||
try:
|
||||
if not exists(appconf):
|
||||
with open(appconf, 'wt') as f:
|
||||
f.write('<AppConfig>\n\t<Network\n\t\tVerboseLogging="1"\n\t>\n\t</Network>\n</AppConfig>\n')
|
||||
return True
|
||||
|
||||
with open(appconf, 'rU') as f:
|
||||
content = f.read()
|
||||
f.close()
|
||||
backup = appconf[:-4] + '_backup.xml'
|
||||
if exists(backup):
|
||||
unlink(backup)
|
||||
rename(appconf, backup)
|
||||
|
||||
with open(appconf, 'wt') as f:
|
||||
start = content.lower().find('<network')
|
||||
if start >= 0:
|
||||
f.write(content[:start+8] + '\n\t\tVerboseLogging="1"' + content[start+8:])
|
||||
else:
|
||||
start = content.lower().find("</appconfig>")
|
||||
if start >= 0:
|
||||
f.write(content[:start] + '\t<Network\n\t\tVerboseLogging="1"\n\t>\n\t</Network>\n' + content[start:])
|
||||
else:
|
||||
f.write(content) # eh ?
|
||||
return False
|
||||
|
||||
return self.logging_enabled_in_file(appconf)
|
||||
except:
|
||||
if __debug__: print_exc()
|
||||
return False
|
||||
|
||||
def set_callback(self, name, callback):
|
||||
if name in self.callbacks:
|
||||
self.callbacks[name] = callback
|
||||
@ -88,6 +133,10 @@ class EDLogs(FileSystemEventHandler):
|
||||
self.stop()
|
||||
self.currentdir = logdir
|
||||
|
||||
if not self._logging_enabled(self.currentdir):
|
||||
# verbose logging reduces likelihood that Docked/Undocked messages will be delayed
|
||||
self._enable_logging(self.currentdir)
|
||||
|
||||
self.root.bind_all('<<MonitorJump>>', self.jump) # user-generated
|
||||
self.root.bind_all('<<MonitorDock>>', self.dock) # user-generated
|
||||
|
||||
@ -186,10 +235,9 @@ class EDLogs(FileSystemEventHandler):
|
||||
newlogfile = self.logfile # updated by on_created watchdog callback
|
||||
else:
|
||||
# Poll
|
||||
logdir = config.get('logdir') or self.logdir
|
||||
try:
|
||||
logfiles = sorted([x for x in listdir(logdir) if x.startswith('netLog.')])
|
||||
newlogfile = logfiles and join(logdir, logfiles[-1]) or None
|
||||
logfiles = sorted([x for x in listdir(self.currentdir) if x.startswith('netLog.')])
|
||||
newlogfile = logfiles and join(self.currentdir, logfiles[-1]) or None
|
||||
except:
|
||||
if __debug__: print_exc()
|
||||
newlogfile = None
|
||||
@ -270,6 +318,18 @@ class EDLogs(FileSystemEventHandler):
|
||||
# Apple's SMB implementation is too flaky so assume target machine is OSX
|
||||
return path and isdir(path) and isfile(join(path, pardir, 'AppNetCfg.xml'))
|
||||
|
||||
def _logging_enabled(self, path):
|
||||
if not self._is_valid_logdir(path):
|
||||
return False
|
||||
else:
|
||||
return self.logging_enabled_in_file(join(path, pardir, 'AppConfigLocal.xml'))
|
||||
|
||||
def _enable_logging(self, path):
|
||||
if not self._is_valid_logdir(path):
|
||||
return False
|
||||
else:
|
||||
return self.enable_logging_in_file(join(path, pardir, 'AppConfigLocal.xml'))
|
||||
|
||||
|
||||
elif platform=='win32':
|
||||
|
||||
@ -350,16 +410,47 @@ class EDLogs(FileSystemEventHandler):
|
||||
# Assume target machine is Windows
|
||||
return path and isdir(path) and isfile(join(path, pardir, 'AppConfig.xml'))
|
||||
|
||||
def _logging_enabled(self, path):
|
||||
if not self._is_valid_logdir(path):
|
||||
return False
|
||||
else:
|
||||
return (self.logging_enabled_in_file(join(path, pardir, 'AppConfigLocal.xml')) or
|
||||
self.logging_enabled_in_file(join(path, pardir, 'AppConfig.xml')))
|
||||
|
||||
def _enable_logging(self, path):
|
||||
if not self._is_valid_logdir(path):
|
||||
return False
|
||||
else:
|
||||
return self.enable_logging_in_file(isfile(join(path, pardir, 'AppConfigLocal.xml')) and
|
||||
join(path, pardir, 'AppConfigLocal.xml') or
|
||||
join(path, pardir, 'AppConfig.xml'))
|
||||
|
||||
|
||||
elif platform=='linux2':
|
||||
|
||||
def _logdir(self):
|
||||
return None
|
||||
|
||||
# Assume target machine is Windows
|
||||
|
||||
def _is_valid_logdir(self, path):
|
||||
# Assume target machine is Windows
|
||||
return path and isdir(path) and isfile(join(path, pardir, 'AppConfig.xml'))
|
||||
|
||||
def _logging_enabled(self, path):
|
||||
if not self._is_valid_logdir(path):
|
||||
return False
|
||||
else:
|
||||
return (self.logging_enabled_in_file(join(path, pardir, 'AppConfigLocal.xml')) or
|
||||
self.logging_enabled_in_file(join(path, pardir, 'AppConfig.xml')))
|
||||
|
||||
def _enable_logging(self, path):
|
||||
if not self._is_valid_logdir(path):
|
||||
return False
|
||||
else:
|
||||
return self.enable_logging_in_file(isfile(join(path, pardir, 'AppConfigLocal.xml')) and
|
||||
join(path, pardir, 'AppConfigLocal.xml') or
|
||||
join(path, pardir, 'AppConfig.xml'))
|
||||
|
||||
|
||||
# singleton
|
||||
monitor = EDLogs()
|
||||
|
Loading…
x
Reference in New Issue
Block a user