Change how we split lines during fit import, also re-use split lines where needed to avoid format-specific linebreak bugs
This commit is contained in:
@@ -159,8 +159,8 @@ def exportEft(fit, options):
|
|||||||
return '{}\n\n{}'.format(header, '\n\n\n'.join(sections))
|
return '{}\n\n{}'.format(header, '\n\n\n'.join(sections))
|
||||||
|
|
||||||
|
|
||||||
def importEft(eftString):
|
def importEft(lines):
|
||||||
lines = _importPrepareString(eftString)
|
lines = _importPrepare(lines)
|
||||||
try:
|
try:
|
||||||
fit = _importCreateFit(lines)
|
fit = _importCreateFit(lines)
|
||||||
except EftImportError:
|
except EftImportError:
|
||||||
@@ -288,7 +288,7 @@ def importEft(eftString):
|
|||||||
return fit
|
return fit
|
||||||
|
|
||||||
|
|
||||||
def importEftCfg(shipname, contents, iportuser):
|
def importEftCfg(shipname, lines, iportuser):
|
||||||
"""Handle import from EFT config store file"""
|
"""Handle import from EFT config store file"""
|
||||||
|
|
||||||
# Check if we have such ship in database, bail if we don't
|
# Check if we have such ship in database, bail if we don't
|
||||||
@@ -300,7 +300,6 @@ def importEftCfg(shipname, contents, iportuser):
|
|||||||
|
|
||||||
fits = [] # List for fits
|
fits = [] # List for fits
|
||||||
fitIndices = [] # List for starting line numbers for each fit
|
fitIndices = [] # List for starting line numbers for each fit
|
||||||
lines = re.split('[\n\r]+', contents) # Separate string into lines
|
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
# Detect fit header
|
# Detect fit header
|
||||||
@@ -481,8 +480,7 @@ def importEftCfg(shipname, contents, iportuser):
|
|||||||
return fits
|
return fits
|
||||||
|
|
||||||
|
|
||||||
def _importPrepareString(eftString):
|
def _importPrepare(lines):
|
||||||
lines = eftString.splitlines()
|
|
||||||
for i in range(len(lines)):
|
for i in range(len(lines)):
|
||||||
lines[i] = lines[i].strip()
|
lines[i] = lines[i].strip()
|
||||||
while lines and not lines[0]:
|
while lines and not lines[0]:
|
||||||
|
|||||||
@@ -137,11 +137,11 @@ def exportESI(ofit):
|
|||||||
return json.dumps(fit)
|
return json.dumps(fit)
|
||||||
|
|
||||||
|
|
||||||
def importESI(str_):
|
def importESI(string):
|
||||||
|
|
||||||
sMkt = Market.getInstance()
|
sMkt = Market.getInstance()
|
||||||
fitobj = Fit()
|
fitobj = Fit()
|
||||||
refobj = json.loads(str_)
|
refobj = json.loads(string)
|
||||||
items = refobj['items']
|
items = refobj['items']
|
||||||
# "<" and ">" is replace to "<", ">" by EVE client
|
# "<" and ">" is replace to "<", ">" by EVE client
|
||||||
fitobj.name = refobj['name']
|
fitobj.name = refobj['name']
|
||||||
|
|||||||
@@ -207,9 +207,14 @@ class Port(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def importAuto(cls, string, path=None, activeFit=None, iportuser=None):
|
def importAuto(cls, string, path=None, activeFit=None, iportuser=None):
|
||||||
# type: (Port, str, str, object, IPortUser) -> object
|
# type: (Port, str, str, object, IPortUser) -> object
|
||||||
|
lines = string.splitlines()
|
||||||
# Get first line and strip space symbols of it to avoid possible detection errors
|
# Get first line and strip space symbols of it to avoid possible detection errors
|
||||||
splitLines = re.split("[\n\r]+", string.strip())
|
firstLine = ''
|
||||||
firstLine = splitLines[0].strip()
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if line:
|
||||||
|
firstLine = line
|
||||||
|
break
|
||||||
|
|
||||||
# If XML-style start of tag encountered, detect as XML
|
# If XML-style start of tag encountered, detect as XML
|
||||||
if re.search(RE_XML_START, firstLine):
|
if re.search(RE_XML_START, firstLine):
|
||||||
@@ -224,12 +229,12 @@ class Port(object):
|
|||||||
if re.match("\[.*\]", firstLine) and path is not None:
|
if re.match("\[.*\]", firstLine) and path is not None:
|
||||||
filename = os.path.split(path)[1]
|
filename = os.path.split(path)[1]
|
||||||
shipName = filename.rsplit('.')[0]
|
shipName = filename.rsplit('.')[0]
|
||||||
return "EFT Config", cls.importEftCfg(shipName, string, iportuser)
|
return "EFT Config", cls.importEftCfg(shipName, lines, iportuser)
|
||||||
|
|
||||||
# If no file is specified and there's comma between brackets,
|
# If no file is specified and there's comma between brackets,
|
||||||
# consider that we have [ship, setup name] and detect like eft export format
|
# consider that we have [ship, setup name] and detect like eft export format
|
||||||
if re.match("\[.*,.*\]", firstLine):
|
if re.match("\[.*,.*\]", firstLine):
|
||||||
return "EFT", (cls.importEft(string),)
|
return "EFT", (cls.importEft(lines),)
|
||||||
|
|
||||||
# Check if string is in DNA format
|
# Check if string is in DNA format
|
||||||
if re.match("\d+(:\d+(;\d+))*::", firstLine):
|
if re.match("\d+(:\d+(;\d+))*::", firstLine):
|
||||||
@@ -237,19 +242,19 @@ class Port(object):
|
|||||||
|
|
||||||
# Assume that we import stand-alone abyssal module if all else fails
|
# Assume that we import stand-alone abyssal module if all else fails
|
||||||
try:
|
try:
|
||||||
return "MutatedItem", (parseMutant(splitLines),)
|
return "MutatedItem", (parseMutant(lines),)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# EFT-related methods
|
# EFT-related methods
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def importEft(eftString):
|
def importEft(lines):
|
||||||
return importEft(eftString)
|
return importEft(lines)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def importEftCfg(shipname, contents, iportuser=None):
|
def importEftCfg(shipname, lines, iportuser=None):
|
||||||
return importEftCfg(shipname, contents, iportuser)
|
return importEftCfg(shipname, lines, iportuser)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def exportEft(cls, fit, options):
|
def exportEft(cls, fit, options):
|
||||||
|
|||||||
Reference in New Issue
Block a user