def importAuto(cls, string, path=None, activeFit=None, iportuser=None): # type: (Port, str, str, object, IPortUser) -> object # Get first line and strip space symbols of it to avoid possible detection errors firstLine = re.split("[\n\r]+", string.strip(), maxsplit=1)[0] firstLine = firstLine.strip() # If XML-style start of tag encountered, detect as XML if re.search(RE_XML_START, firstLine): return "XML", cls.importXml(string, iportuser) # If JSON-style start, parse as CREST/JSON if firstLine[0] == '{': return "JSON", (cls.importESI(string), ) # If we've got source file name which is used to describe ship name # and first line contains something like [setup name], detect as eft config file 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) # 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), ) # Check if string is in DNA format if re.match("\d+(:\d+(;\d+))*::", firstLine): return "DNA", (cls.importDna(string), ) # Assume that we import stand-alone abyssal module if all else fails try: return "MutatedItem", (parseMutant(string.split("\n")), ) except: pass
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 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): return "XML", cls.importXml(string, iportuser) # If JSON-style start, parse as CREST/JSON if firstLine[0] == '{': return "JSON", (cls.importESI(string), ) # If we've got source file name which is used to describe ship name # and first line contains something like [setup name], detect as eft config file 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, 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(lines), ) # Check if string is in DNA format dnaPattern = "\d+(:\d+(;\d+))*::" if re.match(dnaPattern, firstLine): return "DNA", (cls.importDna(string), ) dnaChatPattern = "<url=fitting:(?P<dna>{})>(?P<fitName>[^<>]+)</url>".format( dnaPattern) m = re.search(dnaChatPattern, firstLine) if m: return "DNA", (cls.importDna(m.group("dna"), fitName=m.group("fitName")), ) # Assume that we import stand-alone abyssal module if all else fails if activeFit is not None: try: return "MutatedItem", (parseMutant(lines), ) except: pass
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 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): return "XML", cls.importXml(string, iportuser) # If JSON-style start, parse as CREST/JSON if firstLine[0] == '{': return "JSON", (cls.importESI(string),) # If we've got source file name which is used to describe ship name # and first line contains something like [setup name], detect as eft config file 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, 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(lines),) # Check if string is in DNA format dnaPattern = "\d+(:\d+(;\d+))*::" if re.match(dnaPattern, firstLine): return "DNA", (cls.importDna(string),) dnaChatPattern = "<url=fitting:(?P<dna>{})>(?P<fitName>[^<>]+)</url>".format(dnaPattern) m = re.search(dnaChatPattern, firstLine) if m: return "DNA", (cls.importDna(m.group("dna"), fitName=m.group("fitName")),) # Assume that we import stand-alone abyssal module if all else fails if activeFit is not None: try: return "MutatedItem", (parseMutant(lines),) except: pass
def _importGetMutationData(lines): data = {} # Format: {ref: [lines]} mutaLinesMap = {} currentMutaRef = None currentMutaLines = [] consumedIndices = set() def completeMutaLines(): if currentMutaRef is not None and currentMutaLines: mutaLinesMap[currentMutaRef] = currentMutaLines for i, line in enumerate(lines): m = mutantHeaderPattern.match(line) # Start and reset at header line if m: completeMutaLines() currentMutaRef = int(m.group('ref')) currentMutaLines = [] currentMutaLines.append(m.group('tail')) consumedIndices.add(i) # Reset at blank line elif not line: completeMutaLines() currentMutaRef = None currentMutaLines = [] elif currentMutaRef is not None: currentMutaLines.append(line) consumedIndices.add(i) else: completeMutaLines() # Clear mutant info from source for i in sorted(consumedIndices, reverse=True): del lines[i] # Run parsing data = {} for ref, mutaLines in mutaLinesMap.items(): _, mutaType, mutaAttrs = parseMutant(mutaLines) data[ref] = (mutaType, mutaAttrs) return data
def _importGetMutationData(lines): data = {} # Format: {ref: [lines]} mutaLinesMap = {} currentMutaRef = None currentMutaLines = [] consumedIndices = set() def completeMutaLines(): if currentMutaRef is not None and currentMutaLines: mutaLinesMap[currentMutaRef] = currentMutaLines for i, line in enumerate(lines): m = mutantHeaderPattern.match(line) # Start and reset at header line if m: completeMutaLines() currentMutaRef = int(m.group('ref')) currentMutaLines = [] currentMutaLines.append(m.group('tail')) consumedIndices.add(i) # Reset at blank line elif not line: completeMutaLines() currentMutaRef = None currentMutaLines = [] elif currentMutaRef is not None: currentMutaLines.append(line) consumedIndices.add(i) else: completeMutaLines() # Clear mutant info from source for i in sorted(consumedIndices, reverse=True): del lines[i] # Run parsing data = {} for ref, mutaLines in mutaLinesMap.items(): _, mutaType, mutaAttrs = parseMutant(mutaLines) data[ref] = (mutaType, mutaAttrs) return data
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 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): return "XML", True, cls.importXml(string, iportuser) # If JSON-style start, parse as CREST/JSON if firstLine[0] == '{': return "JSON", True, (cls.importESI(string),) # If we've got source file name which is used to describe ship name # and first line contains something like [setup name], detect as eft config file if re.match("\[.*\]", firstLine) and path is not None: filename = os.path.split(path)[1] shipName = filename.rsplit('.')[0] return "EFT Config", True, 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", True, (cls.importEft(lines),) # Check if string is in DNA format dnaPattern = "\d+(:\d+(;\d+))*::" if re.match(dnaPattern, firstLine): return "DNA", True, (cls.importDna(string),) dnaChatPattern = "<url=fitting:(?P<dna>{})>(?P<fitName>[^<>]+)</url>".format(dnaPattern) m = re.search(dnaChatPattern, firstLine) if m: return "DNA", True, (cls.importDna(m.group("dna"), fitName=m.group("fitName")),) m = re.search(r"DNA:(?P<dna>\d+(:\d+(\*\d+)?)*)", firstLine) if m: return "DNA", True, (cls.importDnaAlt(m.group("dna")),) if activeFit is not None: # Try to import mutated item from network dynData = parseDynamicItemString(string) if dynData is not None: itemData = fetchDynamicItem(dynData) if itemData is not None: baseItem, mutaplasmidItem, mutations = itemData return "FittingItem", False, ((baseItem, mutaplasmidItem, mutations),) # Try to import mutated module try: baseItem, mutaplasmidItem, mutations = parseMutant(lines) except (KeyboardInterrupt, SystemExit): raise except: pass else: if baseItem is not None: return "FittingItem", False, ((baseItem, mutaplasmidItem, mutations),) # Try to import into one of additions panels isDrone, droneData = isValidDroneImport(string) if isDrone: return "AdditionsDrones", False, (droneData,) isFighter, fighterData = isValidFighterImport(string) if isFighter: return "AdditionsFighters", False, (fighterData,) isImplant, implantData = isValidImplantImport(string) if isImplant: return "AdditionsImplants", False, (implantData,) isBooster, boosterData = isValidBoosterImport(string) if isBooster: return "AdditionsBoosters", False, (boosterData,) isCargo, cargoData = isValidCargoImport(string) if isCargo: return "AdditionsCargo", False, (cargoData,)