mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-09 20:02:11 +03:00
Merge pull request #689 from EDCD/fix/eddn-missing-systemaddress
Fix/eddn missing systemaddress
This commit is contained in:
commit
82fc3cad65
@ -9,11 +9,11 @@ import sys
|
|||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from os import SEEK_SET
|
from os import SEEK_SET
|
||||||
from os.path import exists, join
|
from os.path import join
|
||||||
from platform import system
|
from platform import system
|
||||||
from typing import TYPE_CHECKING, Any, AnyStr, Dict, Iterator, List, Mapping, MutableMapping, Optional
|
from typing import TYPE_CHECKING, Any, AnyStr, Dict, Iterator, List, Mapping, MutableMapping, Optional
|
||||||
from typing import OrderedDict as OrderedDictT
|
from typing import OrderedDict as OrderedDictT
|
||||||
from typing import Sequence, TextIO, Tuple, Union
|
from typing import Sequence, TextIO, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -81,26 +81,23 @@ class EDDN:
|
|||||||
# Try to open existing file
|
# Try to open existing file
|
||||||
self.replayfile = open(filename, 'r+', buffering=1)
|
self.replayfile = open(filename, 'r+', buffering=1)
|
||||||
|
|
||||||
except Exception:
|
except FileNotFoundError:
|
||||||
if exists(filename):
|
self.replayfile = open(filename, 'w+', buffering=1) # Create file
|
||||||
raise # Couldn't open existing file
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.replayfile = open(filename, 'w+', buffering=1) # Create file
|
|
||||||
|
|
||||||
if sys.platform != 'win32': # open for writing is automatically exclusive on Windows
|
if sys.platform != 'win32': # open for writing is automatically exclusive on Windows
|
||||||
lockf(self.replayfile, LOCK_EX | LOCK_NB)
|
lockf(self.replayfile, LOCK_EX | LOCK_NB)
|
||||||
|
|
||||||
except Exception as e:
|
except OSError:
|
||||||
logger.debug('Failed opening "replay.jsonl"', exc_info=e)
|
logger.exception('Failed opening "replay.jsonl"')
|
||||||
if self.replayfile:
|
if self.replayfile:
|
||||||
self.replayfile.close()
|
self.replayfile.close()
|
||||||
|
|
||||||
self.replayfile = None
|
self.replayfile = None
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.replaylog = [line.strip() for line in self.replayfile]
|
else:
|
||||||
return True
|
self.replaylog = [line.strip() for line in self.replayfile]
|
||||||
|
return True
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""
|
"""
|
||||||
@ -143,7 +140,12 @@ class EDDN:
|
|||||||
|
|
||||||
r = self.session.post(self.UPLOAD, data=json.dumps(to_send), timeout=self.TIMEOUT)
|
r = self.session.post(self.UPLOAD, data=json.dumps(to_send), timeout=self.TIMEOUT)
|
||||||
if r.status_code != requests.codes.ok:
|
if r.status_code != requests.codes.ok:
|
||||||
logger.debug(f':\nStatus\t{r.status_code}URL\t{r.url}Headers\t{r.headers}Content:\n{r.text}')
|
logger.debug(f'''Status from POST wasn't OK:
|
||||||
|
Status\t{r.status_code}
|
||||||
|
URL\t{r.url}
|
||||||
|
Headers\t{r.headers}
|
||||||
|
Content:\n{r.text}
|
||||||
|
Msg:\n{msg}''')
|
||||||
|
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
@ -179,6 +181,9 @@ class EDDN:
|
|||||||
self.replaylog.pop(0)
|
self.replaylog.pop(0)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
# TODO: Check message against *current* relevant schema so we don't try
|
||||||
|
# to send an old message that's now invalid.
|
||||||
|
|
||||||
# Rewrite old schema name
|
# Rewrite old schema name
|
||||||
if msg['$schemaRef'].startswith('http://schemas.elite-markets.net/eddn/'):
|
if msg['$schemaRef'].startswith('http://schemas.elite-markets.net/eddn/'):
|
||||||
msg['$schemaRef'] = str(msg['$schemaRef']).replace(
|
msg['$schemaRef'] = str(msg['$schemaRef']).replace(
|
||||||
@ -557,7 +562,7 @@ def plugin_stop() -> None:
|
|||||||
this.eddn.close()
|
this.eddn.close()
|
||||||
|
|
||||||
|
|
||||||
def journal_entry(
|
def journal_entry( # noqa: C901
|
||||||
cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any]
|
cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any]
|
||||||
) -> Optional[str]:
|
) -> Optional[str]:
|
||||||
# Recursively filter '*_Localised' keys from dict
|
# Recursively filter '*_Localised' keys from dict
|
||||||
@ -639,21 +644,21 @@ def journal_entry(
|
|||||||
# add mandatory StarSystem, StarPos and SystemAddress properties to Scan events
|
# add mandatory StarSystem, StarPos and SystemAddress properties to Scan events
|
||||||
if 'StarSystem' not in entry:
|
if 'StarSystem' not in entry:
|
||||||
if not system:
|
if not system:
|
||||||
logger.warn("system is None, can't add StarSystem")
|
logger.warning("system is None, can't add StarSystem")
|
||||||
return "system is None, can't add StarSystem"
|
return "system is None, can't add StarSystem"
|
||||||
|
|
||||||
entry['StarSystem'] = system
|
entry['StarSystem'] = system
|
||||||
|
|
||||||
if 'StarPos' not in entry:
|
if 'StarPos' not in entry:
|
||||||
if not this.coordinates:
|
if not this.coordinates:
|
||||||
logger.warn("this.coordinates is None, can't add StarPos")
|
logger.warning("this.coordinates is None, can't add StarPos")
|
||||||
return "this.coordinates is None, can't add StarPos"
|
return "this.coordinates is None, can't add StarPos"
|
||||||
|
|
||||||
entry['StarPos'] = list(this.coordinates)
|
entry['StarPos'] = list(this.coordinates)
|
||||||
|
|
||||||
if 'SystemAddress' not in entry:
|
if 'SystemAddress' not in entry:
|
||||||
if not this.systemaddress:
|
if not this.systemaddress:
|
||||||
logger.warn("this.systemaddress is None, can't add SystemAddress")
|
logger.warning("this.systemaddress is None, can't add SystemAddress")
|
||||||
return "this.systemaddress is None, can't add SystemAddress"
|
return "this.systemaddress is None, can't add SystemAddress"
|
||||||
|
|
||||||
entry['SystemAddress'] = this.systemaddress
|
entry['SystemAddress'] = this.systemaddress
|
||||||
|
Loading…
x
Reference in New Issue
Block a user