From 5eb4296ec6a7c1cab2210f430234145cf2ffd7e1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 Oct 2022 16:12:28 +0100 Subject: [PATCH] EDDN: First steps to ensure new code respects user configuration It's easier to check "should we send this message at all?" earlier. Currently all of the following ('station data') do so: * CAPI commodity, outfitting (also fcmaterials) and shipyard. * Journal commodity, fcmaterials, outfitting, and shipyard. --- plugins/eddn.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 14c42dbb..1f9ee487 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -130,6 +130,8 @@ class EDDNSender: """Handle sending of EDDN messages to the Gateway.""" SQLITE_DB_FILENAME_V1 = 'eddn_queue-v1.db' + # EDDN schema types that pertain to station data + STATION_SCHEMAS = ('commodity', 'fcmaterials_capi', 'fcmaterials_journal', 'outfitting', 'shipyard') TIMEOUT = 10 # requests timeout UNKNOWN_SCHEMA_RE = re.compile( r"^FAIL: \[JsonValidationException\('Schema " @@ -504,8 +506,17 @@ class EDDN: :param cmdr: the CMDR to use as the uploader ID. :param msg: the payload to send. """ - - # TODO: Check if the global 'Send to EDDN' option is off + # TODO: Check if we should actually send this message: + # 1. Is sending of this 'class' of message configured on ? + # 2. Are we *not* docked and delayed sending is configured on ? + # NB: This is a placeholder whilst all the "start of processing data" + # code points are confirmed to have their own check. + if ( + any(f'/{s}/' in msg['$schemaRef'] for s in EDDNSender.STATION_SCHEMAS) + and not config.get_int('output') & config.OUT_EDDN_SEND_STATION_DATA + ): + # Sending of station data configured off + return to_send: OrderedDictT[str, OrderedDict[str, Any]] = OrderedDict([ ('$schemaRef', msg['$schemaRef']), @@ -523,7 +534,7 @@ class EDDN: if (msg_id := self.sender.add_message(cmdr, to_send)) == -1: return - self.sender.send_message_by_id(msg_id) + self.sender.send_message_by_id(msg_id) def sendreplay(self) -> None: """Send cached Journal lines to EDDN.""" @@ -1340,6 +1351,10 @@ class EDDN: # ] # } + # TODO: Check we're configured to send station data + if not config.get_int('output') & config.OUT_EDDN_SEND_STATION_DATA: + return None + # Sanity check if 'Items' not in entry: logger.warning(f"FCMaterials didn't contain an Items array!\n{entry!r}") @@ -2209,7 +2224,6 @@ def journal_entry( # noqa: C901, CCR001 return _("Error: Can't connect to EDDN") # LANG: Error while trying to send data to EDDN except Exception as e: - return logger.debug('Failed in export_journal_entry', exc_info=e) return str(e)