From 553c7980c13b741bb9587c8b768c22dccf379e56 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Jun 2020 02:02:18 +0100 Subject: [PATCH 1/8] Change EDDB system_url() to using by-name URL This removes a use case for systems.p file --- plugins/eddb.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 1f91b023..67d292b2 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -27,10 +27,7 @@ with open(join(config.respath, 'stations.p'), 'rb') as h: # Main window clicks def system_url(system_name): - if system_id(system_name): - return 'https://eddb.io/system/%d' % system_id(system_name) - else: - return None + return 'https://eddb.io/system/name/%s' % system_name def station_url(system_name, station_name): if station_id(system_name, station_name): From 1a11202aea5e040a7a0b3c79c794c949c4c4806c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Jun 2020 03:54:00 +0100 Subject: [PATCH 2/8] Implement tracking station MarketID, and use in eddb plugin * Adds monitor.station_marketid, tracked at the same points as monitor.station (name). * Changes EDDB plugin to also track its own this.station_marketid so that it can be used in /market-id/ EDDB URL. This removes a use case for stations.p file. --- monitor.py | 11 ++++++++++- plugins/eddb.py | 26 ++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/monitor.py b/monitor.py index b408f2b3..e88d37de 100644 --- a/monitor.py +++ b/monitor.py @@ -82,6 +82,7 @@ class EDLogs(FileSystemEventHandler): self.planet = None self.system = None self.station = None + self.station_marketid = None self.stationtype = None self.coordinates = None self.systemaddress = None @@ -166,7 +167,7 @@ class EDLogs(FileSystemEventHandler): if __debug__: print('Stopping monitoring Journal') self.currentdir = None - self.version = self.mode = self.group = self.cmdr = self.planet = self.system = self.station = self.stationtype = self.stationservices = self.coordinates = self.systemaddress = None + self.version = self.mode = self.group = self.cmdr = self.planet = self.system = self.station = self.station_marketid = self.stationtype = self.stationservices = self.coordinates = self.systemaddress = None self.is_beta = False if self.observed: self.observed = None @@ -229,6 +230,7 @@ class EDLogs(FileSystemEventHandler): if self.station: entry['StationName'] = self.station entry['StationType'] = self.stationtype + entry['MarketID'] = self.station_marketid self.event_queue.append(json.dumps(entry, separators=(', ', ':'))) else: self.event_queue.append(None) # Generate null event to update the display (with possibly out-of-date info) @@ -305,6 +307,7 @@ class EDLogs(FileSystemEventHandler): self.planet = None self.system = None self.station = None + self.station_marketid = None self.stationtype = None self.stationservices = None self.coordinates = None @@ -344,6 +347,7 @@ class EDLogs(FileSystemEventHandler): self.planet = None self.system = None self.station = None + self.station_marketid = None self.stationtype = None self.stationservices = None self.coordinates = None @@ -429,6 +433,7 @@ class EDLogs(FileSystemEventHandler): self.state['Modules'].pop(entry['FromSlot'], None) elif entry['event'] in ['Undocked']: self.station = None + self.station_marketid = None self.stationtype = None self.stationservices = None elif entry['event'] in ['Location', 'FSDJump', 'Docked', 'CarrierJump']: @@ -443,6 +448,7 @@ class EDLogs(FileSystemEventHandler): self.systemaddress = entry.get('SystemAddress') (self.system, self.station) = (entry['StarSystem'] == 'ProvingGround' and 'CQC' or entry['StarSystem'], entry.get('StationName')) # May be None + self.station_marketid = entry.get('MarketID') # May be None self.stationtype = entry.get('StationType') # May be None self.stationservices = entry.get('StationServices') # None under E:D < 2.4 elif entry['event'] == 'ApproachBody': @@ -595,6 +601,7 @@ class EDLogs(FileSystemEventHandler): self.planet = None self.system = None self.station = None + self.station_marketid = None self.stationtype = None self.stationservices = None self.coordinates = None @@ -607,6 +614,7 @@ class EDLogs(FileSystemEventHandler): self.planet = None self.system = None self.station = None + self.station_marketid = None self.stationtype = None self.stationservices = None self.coordinates = None @@ -651,6 +659,7 @@ class EDLogs(FileSystemEventHandler): ('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())), ('event', 'StartUp'), ('Docked', True), + ('MarketID', self.station_marketid), ('StationName', self.station), ('StationType', self.stationtype), ('StarSystem', self.system), diff --git a/plugins/eddb.py b/plugins/eddb.py index 67d292b2..82a294c2 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -29,12 +29,14 @@ with open(join(config.respath, 'stations.p'), 'rb') as h: def system_url(system_name): return 'https://eddb.io/system/name/%s' % system_name + def station_url(system_name, station_name): - if station_id(system_name, station_name): - return 'https://eddb.io/station/%d' % station_id(system_name, station_name) + if this.station_marketid: + return 'https://eddb.io/station/market-id/{}'.format(this.station_marketid) else: return system_url(system_name) + # system_name -> system_id or 0 def system_id(system_name): return this.system_ids.get(system_name, [0, False])[0] @@ -53,6 +55,7 @@ def plugin_start3(plugin_dir): def plugin_app(parent): this.system_link = parent.children['system'] # system label in main window + this.station_marketid = None # Frontier MarketID this.station_link = parent.children['station'] # station label in main window this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED) @@ -60,14 +63,25 @@ def prefs_changed(cmdr, is_beta): if config.get('system_provider') == 'eddb': this.system_link['url'] = system_url(system_link['text']) # Override standard URL function + def journal_entry(cmdr, is_beta, system, station, entry, state): if config.get('system_provider') == 'eddb': this.system_link['url'] = system_url(system) # Override standard URL function - this.station_link['text'] = station or (system_populated(system) and STATION_UNDOCKED or '') - this.station_link.update_idletasks() + + if config.get('station_provider') == 'eddb': + if entry['event'] in ['Location', 'Docked', 'StartUp']: + this.station_marketid = entry.get('MarketID') + elif entry['event'] in ['Undocked']: + this.station_marketid = None + this.station_link['text'] = station or (system_populated(system) and STATION_UNDOCKED or '') + this.station_link.update_idletasks() + def cmdr_data(data, is_beta): if config.get('system_provider') == 'eddb': this.system_link['url'] = system_url(data['lastSystem']['name']) # Override standard URL function - this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_populated(data['lastSystem']['name']) and STATION_UNDOCKED or '') - this.station_link.update_idletasks() + + if config.get('station_provider') == 'eddb': + this.station_marketid = data['commander']['docked'] and data['lastStarport']['id'] + this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_populated(data['lastSystem']['name']) and STATION_UNDOCKED or '') + this.station_link.update_idletasks() From 2df8610e422f84ea7077b8d9b47f579de70a1ada Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Jun 2020 09:52:01 +0100 Subject: [PATCH 3/8] eddb: Ensure system_name is quoted for URL --- plugins/eddb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 82a294c2..9a11b0c2 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -8,6 +8,7 @@ import csv import os from os.path import join import sys +import urllib.parse from config import config @@ -27,7 +28,7 @@ with open(join(config.respath, 'stations.p'), 'rb') as h: # Main window clicks def system_url(system_name): - return 'https://eddb.io/system/name/%s' % system_name + return 'https://eddb.io/system/name/%s' % urllib.parse.quote(system_name) def station_url(system_name, station_name): From 6ed7590ba90929270831a89fc8a7dd7548807042 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Jun 2020 10:39:32 +0100 Subject: [PATCH 4/8] Update eddb.station_marketid from CarrierJump as well This shouldn't actually be necessary, the marketid shouln't change because of a jump, and would have been picked up from the other events anyway, but it should do no harm to set it again from this. --- plugins/eddb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 9a11b0c2..2efce6dd 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -70,7 +70,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.system_link['url'] = system_url(system) # Override standard URL function if config.get('station_provider') == 'eddb': - if entry['event'] in ['Location', 'Docked', 'StartUp']: + if entry['event'] in ['StartUp', 'Location', 'Docked', 'CarrierJump']: this.station_marketid = entry.get('MarketID') elif entry['event'] in ['Undocked']: this.station_marketid = None @@ -80,7 +80,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): def cmdr_data(data, is_beta): if config.get('system_provider') == 'eddb': - this.system_link['url'] = system_url(data['lastSystem']['name']) # Override standard URL function + this.system_link['url'] = system_url(data['lastSystem']['name']) # Override standard URL function if config.get('station_provider') == 'eddb': this.station_marketid = data['commander']['docked'] and data['lastStarport']['id'] From ad81339495a40c2ceab6604127ef855f8d4f8ced Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Jun 2020 10:45:00 +0100 Subject: [PATCH 5/8] Check eddb.system_name is set before attempting to quote it urllib.parse.quote does *not* like being passed None. --- plugins/eddb.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 2efce6dd..7ef3fda4 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -28,7 +28,10 @@ with open(join(config.respath, 'stations.p'), 'rb') as h: # Main window clicks def system_url(system_name): - return 'https://eddb.io/system/name/%s' % urllib.parse.quote(system_name) + if system_name: + return 'https://eddb.io/system/name/%s' % urllib.parse.quote(system_name) + else: + return '' def station_url(system_name, station_name): From 0541e404ec79009f440813997a8f163ab6181ead Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Jun 2020 12:59:51 +0100 Subject: [PATCH 6/8] Track system population in monitor, and use in eddb EDDB station link now triggers off this.system_population, which is received via monitor passing 'Population' through in Startup, Location, FSDJump and CarrierJump events. One fewer use cases for systems.p (populated status in this case). --- monitor.py | 5 +++++ plugins/eddb.py | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index e88d37de..e5c8c4b2 100644 --- a/monitor.py +++ b/monitor.py @@ -223,6 +223,7 @@ class EDLogs(FileSystemEventHandler): ('StarSystem', self.system), ('StarPos', self.coordinates), ('SystemAddress', self.systemaddress), + ('Population', self.systempopulation), ]) if self.planet: entry['Body'] = self.planet @@ -446,6 +447,10 @@ class EDLogs(FileSystemEventHandler): elif self.system != entry['StarSystem']: self.coordinates = None # Docked event doesn't include coordinates self.systemaddress = entry.get('SystemAddress') + + if entry['event'] in ['Location', 'FSDJump', 'CarrierJump']: + self.systempopulation = entry.get('Population') + (self.system, self.station) = (entry['StarSystem'] == 'ProvingGround' and 'CQC' or entry['StarSystem'], entry.get('StationName')) # May be None self.station_marketid = entry.get('MarketID') # May be None diff --git a/plugins/eddb.py b/plugins/eddb.py index 7ef3fda4..ecfaecfe 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -59,6 +59,7 @@ def plugin_start3(plugin_dir): def plugin_app(parent): this.system_link = parent.children['system'] # system label in main window + this.system_population = None this.station_marketid = None # Frontier MarketID this.station_link = parent.children['station'] # station label in main window this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED) @@ -73,11 +74,15 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.system_link['url'] = system_url(system) # Override standard URL function if config.get('station_provider') == 'eddb': + if entry['event'] in ['StartUp', 'Location', 'FSDJump', 'CarrierJump']: + this.system_population = entry.get('Population') + if entry['event'] in ['StartUp', 'Location', 'Docked', 'CarrierJump']: this.station_marketid = entry.get('MarketID') elif entry['event'] in ['Undocked']: this.station_marketid = None - this.station_link['text'] = station or (system_populated(system) and STATION_UNDOCKED or '') + + this.station_link['text'] = station or (this.system_population and this.system_population > 0 and STATION_UNDOCKED or '') this.station_link.update_idletasks() From f6b3109a098558b5e229631feaeef2b1896e480e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Jun 2020 15:08:36 +0100 Subject: [PATCH 7/8] Remove the last of the {stations,systems}.p code from EDDB plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is one tiny regression for a very, very corner case. In 3.46 if you use EDDB as the 'Station' provider and: 1. Dock at Station A, in System X 2. Jump out to System Y, which is also populated 3. Exit out of the game 4. (Re-)Start EDMC 5. Hit 'Update' to manually trigger CAPI data retrieval you will see a "×" character as the Station Name, and can click on it to take you to the EDDB *System* page. It is only there because of EDMC using systems.p to check if System Y is populated. With this version in that circumstance there's no way to know that System Y is populated, so the code assumes not and doesn't show the "×", and thus there's nothing to click to go to the EDDB *System* page for System Y. But so long as the user is actually running the game and EDMC together then populated status is detected from Journal events and the "×" will be there whenever you're undocked but in a populated system. Caveat: We know Frontier have allowed some systems that are technically populated, but show a Population of zero. This code assumes that means they're *not* populated. --- plugins/eddb.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index ecfaecfe..7b262cb7 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -41,19 +41,6 @@ def station_url(system_name, station_name): return system_url(system_name) -# system_name -> system_id or 0 -def system_id(system_name): - return this.system_ids.get(system_name, [0, False])[0] - -# system_name -> is_populated -def system_populated(system_name): - return this.system_ids.get(system_name, [0, False])[1] - -# (system_name, station_name) -> station_id or 0 -def station_id(system_name, station_name): - return this.station_ids.get((system_id(system_name), station_name), 0) - - def plugin_start3(plugin_dir): return 'eddb' @@ -92,5 +79,5 @@ def cmdr_data(data, is_beta): if config.get('station_provider') == 'eddb': this.station_marketid = data['commander']['docked'] and data['lastStarport']['id'] - this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_populated(data['lastSystem']['name']) and STATION_UNDOCKED or '') + this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (data['lastStarport']['name'] and data['lastStarport']['name'] != "" and STATION_UNDOCKED or '') this.station_link.update_idletasks() From cd02d1664a5d6c285e5af01b8af5b47192ea5d4e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Jun 2020 12:06:57 +0100 Subject: [PATCH 8/8] Change EDDB system_url to use SystemAddress * This means storing this.system_address from both cmdr_data and journal_entry. NB: If the current value in the event or data is 'None' it will retain the previous value. Without this Journal entries without SystemAddress erase the stored value. * The station_url() fallback to system_url() similarly uses this.system_address in the call. Addresses #512 --- plugins/eddb.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 7b262cb7..9c17b497 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -17,48 +17,42 @@ STATION_UNDOCKED = u'×' # "Station" name to display when not docked = U+00D7 this = sys.modules[__name__] # For holding module globals -# (system_id, is_populated) by system_name -with open(join(config.respath, 'systems.p'), 'rb') as h: - this.system_ids = pickle.load(h) - -# station_id by (system_id, station_name) -with open(join(config.respath, 'stations.p'), 'rb') as h: - this.station_ids = pickle.load(h) - +this.system_address = None +this.system_population = None +this.station_marketid = None # Frontier MarketID # Main window clicks -def system_url(system_name): - if system_name: - return 'https://eddb.io/system/name/%s' % urllib.parse.quote(system_name) +def system_url(system_address): + if system_address: + return 'https://eddb.io/system/ed-address/%s' % system_address else: return '' - def station_url(system_name, station_name): if this.station_marketid: return 'https://eddb.io/station/market-id/{}'.format(this.station_marketid) else: - return system_url(system_name) - + return system_url(this.system_address) def plugin_start3(plugin_dir): return 'eddb' def plugin_app(parent): this.system_link = parent.children['system'] # system label in main window - this.system_population = None + this.system_address = None this.station_marketid = None # Frontier MarketID this.station_link = parent.children['station'] # station label in main window this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED) def prefs_changed(cmdr, is_beta): if config.get('system_provider') == 'eddb': - this.system_link['url'] = system_url(system_link['text']) # Override standard URL function + this.system_link['url'] = system_url(this.system_address) # Override standard URL function def journal_entry(cmdr, is_beta, system, station, entry, state): if config.get('system_provider') == 'eddb': - this.system_link['url'] = system_url(system) # Override standard URL function + this.system_address = entry.get('SystemAddress') or this.system_address + this.system_link['url'] = system_url(this.system_address) # Override standard URL function if config.get('station_provider') == 'eddb': if entry['event'] in ['StartUp', 'Location', 'FSDJump', 'CarrierJump']: @@ -69,13 +63,14 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): elif entry['event'] in ['Undocked']: this.station_marketid = None - this.station_link['text'] = station or (this.system_population and this.system_population > 0 and STATION_UNDOCKED or '') + this.station_link['text'] = station or (this.system_population and this.system_population > 0 and STATION_UNDOCKED or '') this.station_link.update_idletasks() def cmdr_data(data, is_beta): if config.get('system_provider') == 'eddb': - this.system_link['url'] = system_url(data['lastSystem']['name']) # Override standard URL function + this.system_address = data['lastSystem']['id'] or this.system_address + this.system_link['url'] = system_url(this.system_address) # Override standard URL function if config.get('station_provider') == 'eddb': this.station_marketid = data['commander']['docked'] and data['lastStarport']['id']