From 4a27c60486c5b6355e8e99054d295ab7bd496432 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 24 Aug 2018 13:25:41 +0300 Subject: [PATCH] Clean up the fit being imported before parsing --- service/port.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/service/port.py b/service/port.py index 8a6cf7343..a0f8ddf32 100644 --- a/service/port.py +++ b/service/port.py @@ -625,21 +625,28 @@ class Port(object): @staticmethod def importEft(eftString): + # Split passed string in lines and clean them up + lines = eftString.splitlines() + for i in range(len(lines)): + lines[i] = lines[i].strip() + while lines and not lines[0]: + del lines[0] + while lines and not lines[-1]: + del lines[-1] + sMkt = Market.getInstance() - offineSuffix = " /OFFLINE" + offineSuffix = ' /OFFLINE' fit = Fit() - eftString = eftString.strip() - lines = re.split('[\n\r]+', eftString) - info = lines[0][1:-1].split(",", 1) - - if len(info) == 2: - shipType = info[0].strip() - fitName = info[1].strip() - else: - shipType = info[0].strip() - fitName = "Imported %s" % shipType + # Ship and fit name from header + header = lines.pop(0) + m = re.match('\[(?P[\w\s]+), (?P.+)\]', header) + if not m: + pyfalog.warning('Corrupted fit header in importEft') + return + shipType = m.group('shipType').strip() + fitName = m.group('fitName').strip() try: ship = sMkt.getItem(shipType) try: