1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-05 18:03:17 +03:00

EDMC: Get -n working again

* eddn: Don't schedule `queue_check_and_send()` if EDMC_NO_UI.
* `export_(commodites|outfitting|shipyard)` lost the `is_odyssey` argument
 in 556ace5306bebbcf34c1a56a9023a822218a73f1 .
* EDDNSender: Helper `set_ui_status()` in which the check for EDMC_NO_UI
  is performed.  Used in `send_message()`.  In the EDMC_NO_UI case it will
  INFO log the text instead.
This commit is contained in:
Athanasius 2022-12-14 11:15:20 +00:00
parent 79bbc8917f
commit e245a75e61
No known key found for this signature in database
GPG Key ID: 772697E181BB2767
2 changed files with 21 additions and 8 deletions

View File

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

View File

@ -180,7 +180,8 @@ class EDDNSender:
"plugin.eddn.send", "plugin.eddn.send",
f"First queue run scheduled for {self.eddn.REPLAY_STARTUP_DELAY}ms from now" 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: def sqlite_queue_v1(self) -> sqlite3.Connection:
""" """
@ -371,6 +372,19 @@ class EDDNSender:
return False 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: def send_message(self, msg: str) -> bool:
""" """
Transmit a fully-formed EDDN message to the Gateway. 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.') logger.warning('eddn.send has been disabled via killswitch. Returning.')
return False return False
status: tk.Widget = self.eddn.parent.children['status']
# Even the smallest possible message compresses somewhat, so always compress # Even the smallest possible message compresses somewhat, so always compress
encoded, compressed = text.gzip(json.dumps(new_data, separators=(',', ':')), max_size=0) encoded, compressed = text.gzip(json.dumps(new_data, separators=(',', ':')), max_size=0)
headers: None | dict[str, str] = None headers: None | dict[str, str] = None
@ -435,16 +448,16 @@ class EDDNSender:
else: else:
# This should catch anything else, e.g. timeouts, gateway errors # 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: except requests.exceptions.RequestException as e:
logger.debug('Failed sending', exc_info=e) logger.debug('Failed sending', exc_info=e)
# LANG: Error while trying to send data to EDDN # 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: except Exception as e:
logger.debug('Failed sending', exc_info=e) logger.debug('Failed sending', exc_info=e)
status['text'] = str(e) self.set_ui_status(str(e))
return False return False