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))
|
||||
|
||||
|
||||
def importEft(eftString):
|
||||
lines = _importPrepareString(eftString)
|
||||
def importEft(lines):
|
||||
lines = _importPrepare(lines)
|
||||
try:
|
||||
fit = _importCreateFit(lines)
|
||||
except EftImportError:
|
||||
@@ -288,7 +288,7 @@ def importEft(eftString):
|
||||
return fit
|
||||
|
||||
|
||||
def importEftCfg(shipname, contents, iportuser):
|
||||
def importEftCfg(shipname, lines, iportuser):
|
||||
"""Handle import from EFT config store file"""
|
||||
|
||||
# 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
|
||||
fitIndices = [] # List for starting line numbers for each fit
|
||||
lines = re.split('[\n\r]+', contents) # Separate string into lines
|
||||
|
||||
for line in lines:
|
||||
# Detect fit header
|
||||
@@ -481,8 +480,7 @@ def importEftCfg(shipname, contents, iportuser):
|
||||
return fits
|
||||
|
||||
|
||||
def _importPrepareString(eftString):
|
||||
lines = eftString.splitlines()
|
||||
def _importPrepare(lines):
|
||||
for i in range(len(lines)):
|
||||
lines[i] = lines[i].strip()
|
||||
while lines and not lines[0]:
|
||||
|
||||
@@ -137,11 +137,11 @@ def exportESI(ofit):
|
||||
return json.dumps(fit)
|
||||
|
||||
|
||||
def importESI(str_):
|
||||
def importESI(string):
|
||||
|
||||
sMkt = Market.getInstance()
|
||||
fitobj = Fit()
|
||||
refobj = json.loads(str_)
|
||||
refobj = json.loads(string)
|
||||
items = refobj['items']
|
||||
# "<" and ">" is replace to "<", ">" by EVE client
|
||||
fitobj.name = refobj['name']
|
||||
|
||||
@@ -207,9 +207,14 @@ class Port(object):
|
||||
@classmethod
|
||||
def importAuto(cls, string, path=None, activeFit=None, iportuser=None):
|
||||
# type: (Port, str, str, object, IPortUser) -> object
|
||||
lines = string.splitlines()
|
||||
# Get first line and strip space symbols of it to avoid possible detection errors
|
||||
splitLines = re.split("[\n\r]+", string.strip())
|
||||
firstLine = splitLines[0].strip()
|
||||
firstLine = ''
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line:
|
||||
firstLine = line
|
||||
break
|
||||
|
||||
# If XML-style start of tag encountered, detect as XML
|
||||
if re.search(RE_XML_START, firstLine):
|
||||
@@ -224,12 +229,12 @@ class Port(object):
|
||||
if re.match("\[.*\]", firstLine) and path is not None:
|
||||
filename = os.path.split(path)[1]
|
||||
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,
|
||||
# consider that we have [ship, setup name] and detect like eft export format
|
||||
if re.match("\[.*,.*\]", firstLine):
|
||||
return "EFT", (cls.importEft(string),)
|
||||
return "EFT", (cls.importEft(lines),)
|
||||
|
||||
# Check if string is in DNA format
|
||||
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
|
||||
try:
|
||||
return "MutatedItem", (parseMutant(splitLines),)
|
||||
return "MutatedItem", (parseMutant(lines),)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# EFT-related methods
|
||||
@staticmethod
|
||||
def importEft(eftString):
|
||||
return importEft(eftString)
|
||||
def importEft(lines):
|
||||
return importEft(lines)
|
||||
|
||||
@staticmethod
|
||||
def importEftCfg(shipname, contents, iportuser=None):
|
||||
return importEftCfg(shipname, contents, iportuser)
|
||||
def importEftCfg(shipname, lines, iportuser=None):
|
||||
return importEftCfg(shipname, lines, iportuser)
|
||||
|
||||
@classmethod
|
||||
def exportEft(cls, fit, options):
|
||||
|
||||
Reference in New Issue
Block a user