diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 911ebdd0..094a6015 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -70,6 +70,28 @@ if __name__ == '__main__': # noqa: C901 "such as EDSM, Inara.cz and EDDB." ) + ########################################################################### + # Permanent config changes + ########################################################################### + parser.add_argument( + '--reset-ui', + help='reset UI theme and transparency to defaults', + action='store_true' + ) + ########################################################################### + + ########################################################################### + # User 'utility' args + ########################################################################### + parser.add_argument('--suppress-dupe-process-popup', + help='Suppress the popup from when the application detects another instance already running', + action='store_true' + ) + ########################################################################### + + ########################################################################### + # Adjust logging + ########################################################################### parser.add_argument( '--trace', help='Set the Debug logging loglevel to TRACE', @@ -89,28 +111,21 @@ if __name__ == '__main__': # noqa: C901 ) parser.add_argument( - '--reset-ui', - help='reset UI theme and transparency to defaults', - action='store_true' + '--debug-sender', + help='Mark the selected sender as in debug mode. This generally results in data being written to disk', + action='append', ) + ########################################################################### + ########################################################################### + # Frontier Auth + ########################################################################### parser.add_argument( '--forget-frontier-auth', help='resets all authentication tokens', action='store_true' ) - parser.add_argument('--suppress-dupe-process-popup', - help='Suppress the popup from when the application detects another instance already running', - action='store_true' - ) - - parser.add_argument( - '--debug-sender', - help='Mark the selected sender as in debug mode. This generally results in data being written to disk', - action='append', - ) - auth_options = parser.add_mutually_exclusive_group(required=False) auth_options.add_argument('--force-localserver-for-auth', help='Force EDMC to use a localhost webserver for Frontier Auth callback', @@ -126,13 +141,23 @@ if __name__ == '__main__': # noqa: C901 help='Callback from Frontier Auth', nargs='*' ) + ########################################################################### + ########################################################################### + # Developer 'utility' args + ########################################################################### parser.add_argument( '--capi-pretend-down', help='Force to raise ServerError on any CAPI query', action='store_true' ) + parser.add_argument( + '--eddn-url', + help='Specify an alternate EDDN upload URL', + ) + ########################################################################### + args = parser.parse_args() if args.capi_pretend_down: @@ -156,6 +181,9 @@ if __name__ == '__main__': # noqa: C901 if args.force_localserver_for_auth: config.set_auth_force_localserver() + if args.eddn_url: + config.set_eddn_url(args.eddn_url) + if args.force_edmc_protocol: if sys.platform == 'win32': config.set_auth_force_edmc_protocol() diff --git a/config.py b/config.py index b1437047..7a51547a 100644 --- a/config.py +++ b/config.py @@ -207,6 +207,7 @@ class AbstractConfig(abc.ABC): __in_shutdown = False # Is the application currently shutting down ? __auth_force_localserver = False # Should we use localhost for auth callback ? __auth_force_edmc_protocol = False # Should we force edmc:// protocol ? + __eddn_url = None # Non-default EDDN URL def __init__(self) -> None: self.home_path = pathlib.Path.home() @@ -250,6 +251,19 @@ class AbstractConfig(abc.ABC): """ return self.__auth_force_edmc_protocol + def set_eddn_url(self, eddn_url: str): + """Set the specified eddn URL.""" + self.__eddn_url = eddn_url + + @property + def eddn_url(self) -> Optional[str]: + """ + Provide the custom EDDN URL. + + :return: str - Custom EDDN URL to use. + """ + return self.__eddn_url + @property def app_dir(self) -> str: """Return a string version of app_dir.""" diff --git a/plugins/eddn.py b/plugins/eddn.py index 36a4cb94..339baec0 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -88,14 +88,9 @@ HORIZ_SKU = 'ELITE_HORIZONS_V_PLANETARY_LANDINGS' class EDDN: """EDDN Data export.""" - DEBUG = 'eddn' in debug_senders - SERVER = 'https://eddn.edcd.io:4430' - if DEBUG: - SERVER = f'http://{edmc_data.DEBUG_WEBSERVER_HOST}:{edmc_data.DEBUG_WEBSERVER_PORT}' - - UPLOAD = f'{SERVER}/upload/' - if DEBUG: - UPLOAD = f'{SERVER}/eddn' + DEFAULT_URL = 'https://eddn.edcd.io:4430/upload' + if 'eddn' in debug_senders: + DEFAULT_URL = f'http://{edmc_data.DEBUG_WEBSERVER_HOST}:{edmc_data.DEBUG_WEBSERVER_PORT}/eddn' REPLAYPERIOD = 400 # Roughly two messages per second, accounting for send delays [ms] REPLAYFLUSH = 20 # Update log on disk roughly every 10 seconds @@ -109,6 +104,12 @@ class EDDN: self.replayfile: Optional[TextIO] = None # For delayed messages self.replaylog: List[str] = [] + if config.eddn_url is not None: + self.eddn_url = config.eddn_url + + else: + self.eddn_url = self.DEFAULT_URL + def load_journal_replay(self) -> bool: """ Load cached journal entries from disk. @@ -187,7 +188,7 @@ class EDDN: ('message', msg['message']), ]) - r = self.session.post(self.UPLOAD, data=json.dumps(to_send), timeout=self.TIMEOUT) + r = self.session.post(self.eddn_url, data=json.dumps(to_send), timeout=self.TIMEOUT) if r.status_code != requests.codes.ok: # Check if EDDN is still objecting to an empty commodities list