MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / importAuto

Method importAuto

service/port/port.py:214–291  ·  view source on GitHub ↗
(cls, string, path=None, activeFit=None, progress=None)

Source from the content-addressed store, hash-verified

212
213 @classmethod
214 def importAuto(cls, string, path=None, activeFit=None, progress=None):
215 lines = string.splitlines()
216 # Get first line and strip space symbols of it to avoid possible detection errors
217 firstLine = ''
218 for line in lines:
219 line = line.strip()
220 if line:
221 firstLine = line
222 break
223
224 # If XML-style start of tag encountered, detect as XML
225 if re.search(RE_XML_START, firstLine):
226 return "XML", True, cls.importXml(string, progress)
227
228 # If JSON-style start, parse as CREST/JSON
229 if firstLine[0] == '{':
230 return "JSON", True, (cls.importESI(string),)
231
232 # If we've got source file name which is used to describe ship name
233 # and first line contains something like [setup name], detect as eft config file
234 if re.match(r"^\s*\[.*\]", firstLine) and path is not None:
235 filename = os.path.split(path)[1]
236 shipName = filename.rsplit('.')[0]
237 return "EFT Config", True, cls.importEftCfg(shipName, lines, progress)
238
239 # If no file is specified and there's comma between brackets,
240 # consider that we have [ship, setup name] and detect like eft export format
241 if re.match(r"^\s*\[.*,.*\]", firstLine):
242 return "EFT", True, (cls.importEft(lines),)
243
244 # Check if string is in DNA format
245 dnaPattern = r"\d+(:\d+(;\d+))*::"
246 if re.match(dnaPattern, firstLine):
247 return "DNA", True, (cls.importDna(string),)
248 dnaChatPattern = r"<url=fitting:(?P<dna>{})>(?P<fitName>[^<>]+)</url>".format(dnaPattern)
249 m = re.search(dnaChatPattern, firstLine)
250 if m:
251 return "DNA", True, (cls.importDna(m.group("dna"), fitName=m.group("fitName")),)
252 m = re.search(r"DNA:(?P<dna>\d+(:\d+(\*\d+)?)*)", firstLine)
253 if m:
254 return "DNA", True, (cls.importDnaAlt(m.group("dna")),)
255
256 if activeFit is not None:
257
258 # Try to import mutated item from network
259 dynData = parseDynamicItemString(string)
260 if dynData is not None:
261 itemData = fetchDynamicItem(dynData)
262 if itemData is not None:
263 baseItem, mutaplasmidItem, mutations = itemData
264 return "FittingItem", False, ((baseItem, mutaplasmidItem, mutations),)
265
266 # Try to import mutated module
267 try:
268 baseItem, mutaplasmidItem, mutations = parseMutant(lines)
269 except (KeyboardInterrupt, SystemExit):
270 raise
271 except:

Callers 2

importFitFromFilesMethod · 0.80
importFitFromBufferMethod · 0.80

Calls 14

parseDynamicItemStringFunction · 0.90
fetchDynamicItemFunction · 0.90
parseMutantFunction · 0.90
isValidDroneImportFunction · 0.90
isValidFighterImportFunction · 0.90
isValidImplantImportFunction · 0.90
isValidBoosterImportFunction · 0.90
isValidCargoImportFunction · 0.90
importXmlMethod · 0.80
importESIMethod · 0.80
importEftCfgMethod · 0.80
importEftMethod · 0.80

Tested by

no test coverage detected