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

Merge pull request #1754 from EDCD/fix/1720/EDMC_-n

EDMC.py quietening and fixes
This commit is contained in:
Athanasius 2022-12-14 11:32:13 +00:00 committed by GitHub
commit d48501c37b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 9 deletions

View File

@ -433,9 +433,9 @@ sys.path: {sys.path}'''
try:
eddn_sender = eddn.EDDN(None)
logger.debug('Sending Market, Outfitting and Shipyard data to EDDN...')
eddn_sender.export_commodities(data, monitor.is_beta, monitor.state['Odyssey'])
eddn_sender.export_outfitting(data, monitor.is_beta, monitor.state['Odyssey'])
eddn_sender.export_shipyard(data, monitor.is_beta, monitor.state['Odyssey'])
eddn_sender.export_commodities(data, monitor.is_beta)
eddn_sender.export_outfitting(data, monitor.is_beta)
eddn_sender.export_shipyard(data, monitor.is_beta)
except Exception:
logger.exception('Failed to send data to EDDN')

View File

@ -1710,7 +1710,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
pass
else:
logger.info(f"Parsed {self.state['GameVersion']=} into {self.version_semantic=}")
logger.debug(f"Parsed {self.state['GameVersion']=} into {self.version_semantic=}")
self.is_beta = any(v in self.version.lower() for v in ('alpha', 'beta')) # type: ignore
except KeyError:

View File

@ -180,7 +180,8 @@ class EDDNSender:
"plugin.eddn.send",
f"First queue run scheduled for {self.eddn.REPLAY_STARTUP_DELAY}ms from now"
)
self.eddn.parent.after(self.eddn.REPLAY_STARTUP_DELAY, self.queue_check_and_send, True)
if not os.getenv("EDMC_NO_UI"):
self.eddn.parent.after(self.eddn.REPLAY_STARTUP_DELAY, self.queue_check_and_send, True)
def sqlite_queue_v1(self) -> sqlite3.Connection:
"""
@ -371,6 +372,19 @@ class EDDNSender:
return False
def set_ui_status(self, text: str) -> None:
"""
Set the UI status text, if applicable.
When running as a CLI there is no such thing, so log to INFO instead.
:param text: The status text to be set/logged.
"""
if os.getenv('EDMC_NO_UI'):
logger.INFO(text)
return
self.eddn.parent.children['status']['text'] = text
def send_message(self, msg: str) -> bool:
"""
Transmit a fully-formed EDDN message to the Gateway.
@ -394,7 +408,6 @@ class EDDNSender:
logger.warning('eddn.send has been disabled via killswitch. Returning.')
return False
status: tk.Widget = self.eddn.parent.children['status']
# Even the smallest possible message compresses somewhat, so always compress
encoded, compressed = text.gzip(json.dumps(new_data, separators=(',', ':')), max_size=0)
headers: None | dict[str, str] = None
@ -435,16 +448,16 @@ class EDDNSender:
else:
# This should catch anything else, e.g. timeouts, gateway errors
status['text'] = self.http_error_to_log(e)
self.set_ui_status(self.http_error_to_log(e))
except requests.exceptions.RequestException as e:
logger.debug('Failed sending', exc_info=e)
# LANG: Error while trying to send data to EDDN
status['text'] = _("Error: Can't connect to EDDN")
self.set_ui_status(_("Error: Can't connect to EDDN"))
except Exception as e:
logger.debug('Failed sending', exc_info=e)
status['text'] = str(e)
self.set_ui_status(str(e))
return False