def _resolve_ship(fitting, sMkt, b_localized): # type: (xml.dom.minidom.Element, service.market.Market, bool) -> eos.saveddata.fit.Fit """ NOTE: Since it is meaningless unless a correct ship object can be constructed, process flow changed """ # ------ Confirm ship # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item(0).getAttribute("value") anything = None if b_localized: try: # expect an official name, emergency cache shipType, anything = _extract_match(shipType) except ExtractingError: pass limit = 2 ship = None while True: must_retry = False try: try: ship = Ship(sMkt.getItem(shipType)) except ValueError: ship = Citadel(sMkt.getItem(shipType)) except (KeyboardInterrupt, SystemExit): raise except Exception as e: pyfalog.warning("Caught exception on _resolve_ship") pyfalog.error(e) limit -= 1 if limit == 0: break shipType = anything must_retry = True if not must_retry: break if ship is None: raise Exception("cannot resolve ship type.") fitobj = Fit(ship=ship) # ------ Confirm fit name anything = fitting.getAttribute("name") # 2017/03/29 NOTE: # if fit name contained "<" or ">" then reprace to named html entity by EVE client # if re.search(RE_LTGT, anything): if "<" in anything or ">" in anything: anything = replace_ltgt(anything) fitobj.name = anything return fitobj
def _resolve_ship(fitting, sMkt, b_localized): # type: (xml.dom.minidom.Element, service.market.Market, bool) -> eos.saveddata.fit.Fit """ NOTE: Since it is meaningless unless a correct ship object can be constructed, process flow changed """ # ------ Confirm ship # <localized hint="Maelstrom">Maelstrom</localized> shipType = fitting.getElementsByTagName("shipType").item(0).getAttribute("value") anything = None if b_localized: try: # expect an official name, emergency cache shipType, anything = _extract_match(shipType) except ExtractingError: pass limit = 2 ship = None while True: must_retry = False try: try: ship = Ship(sMkt.getItem(shipType)) except ValueError: ship = Citadel(sMkt.getItem(shipType)) except Exception as e: pyfalog.warning("Caught exception on _resolve_ship") pyfalog.error(e) limit -= 1 if limit is 0: break shipType = anything must_retry = True if not must_retry: break if ship is None: raise Exception("cannot resolve ship type.") fitobj = Fit(ship=ship) # ------ Confirm fit name anything = fitting.getAttribute("name") # 2017/03/29 NOTE: # if fit name contained "<" or ">" then reprace to named html entity by EVE client # if re.search(RE_LTGT, anything): if "<" in anything or ">" in anything: anything = replace_ltgt(anything) fitobj.name = anything return fitobj
def importXml(text, iportuser): from .port import Port # type: (str, IPortUser) -> list[eos.saveddata.fit.Fit] sMkt = Market.getInstance() doc = xml.dom.minidom.parseString(text) # NOTE: # When L_MARK is included at this point, # Decided to be localized data b_localized = L_MARK in text fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fit_list = [] failed = 0 for fitting in fittings: try: fitobj = _resolve_ship(fitting, sMkt, b_localized) except: failed += 1 continue # -- 170327 Ignored description -- # read description from exported xml. (EVE client, EFT) description = fitting.getElementsByTagName("description").item( 0).getAttribute("value") if description is None: description = "" elif len(description): # convert <br> to "\n" and remove html tags. if Port.is_tag_replace(): description = replace_ltgt( sequential_rep(description, r"<(br|BR)>", "\n", r"<[^<>]+>", "")) fitobj.notes = description hardwares = fitting.getElementsByTagName("hardware") moduleList = [] for hardware in hardwares: try: item = _resolve_module(hardware, sMkt, b_localized) if not item or not item.published: continue if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) fitobj.drones.append(d) elif item.category.name == "Fighter": ft = Fighter(item) ft.amount = int( hardware.getAttribute("qty") ) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize fitobj.fighters.append(ft) elif hardware.getAttribute("slot").lower() == "cargo": # although the eve client only support charges in cargo, third-party programs # may support items or "refits" in cargo. Support these by blindly adding all # cargo, not just charges c = Cargo(item) c.amount = int(hardware.getAttribute("qty")) fitobj.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: pyfalog.warning( "item can't be added to any slot (unknown item or just charge), ignore it" ) continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(fitobj): m.owner = fitobj fitobj.modules.append(m) else: if m.isValidState(State.ACTIVE): m.state = State.ACTIVE moduleList.append(m) except KeyboardInterrupt: pyfalog.warning("Keyboard Interrupt") continue # Recalc to get slot numbers correct for T3 cruisers svcFit.getInstance().recalc(fitobj) for module in moduleList: if module.fits(fitobj): module.owner = fitobj fitobj.modules.append(module) fit_list.append(fitobj) if iportuser: # NOTE: Send current processing status processing_notify( iportuser, IPortUser.PROCESS_IMPORT | IPortUser.ID_UPDATE, "Processing %s\n%s" % (fitobj.ship.name, fitobj.name)) return fit_list
def importXml(text, iportuser): from .port import Port # type: (str, IPortUser) -> list[eos.saveddata.fit.Fit] sMkt = Market.getInstance() doc = xml.dom.minidom.parseString(text) # NOTE: # When L_MARK is included at this point, # Decided to be localized data b_localized = L_MARK in text fittings = doc.getElementsByTagName("fittings").item(0) fittings = fittings.getElementsByTagName("fitting") fit_list = [] failed = 0 for fitting in fittings: try: fitobj = _resolve_ship(fitting, sMkt, b_localized) except: failed += 1 continue # -- 170327 Ignored description -- # read description from exported xml. (EVE client, EFT) description = fitting.getElementsByTagName("description").item(0).getAttribute("value") if description is None: description = "" elif len(description): # convert <br> to "\n" and remove html tags. if Port.is_tag_replace(): description = replace_ltgt( sequential_rep(description, r"<(br|BR)>", "\n", r"<[^<>]+>", "") ) fitobj.notes = description hardwares = fitting.getElementsByTagName("hardware") moduleList = [] for hardware in hardwares: try: item = _resolve_module(hardware, sMkt, b_localized) if not item or not item.published: continue if item.category.name == "Drone": d = Drone(item) d.amount = int(hardware.getAttribute("qty")) fitobj.drones.append(d) elif item.category.name == "Fighter": ft = Fighter(item) ft.amount = int(hardware.getAttribute("qty")) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize fitobj.fighters.append(ft) elif hardware.getAttribute("slot").lower() == "cargo": # although the eve client only support charges in cargo, third-party programs # may support items or "refits" in cargo. Support these by blindly adding all # cargo, not just charges c = Cargo(item) c.amount = int(hardware.getAttribute("qty")) fitobj.cargo.append(c) else: try: m = Module(item) # When item can't be added to any slot (unknown item or just charge), ignore it except ValueError: pyfalog.warning("item can't be added to any slot (unknown item or just charge), ignore it") continue # Add subsystems before modules to make sure T3 cruisers have subsystems installed if item.category.name == "Subsystem": if m.fits(fitobj): m.owner = fitobj fitobj.modules.append(m) else: if m.isValidState(FittingModuleState.ACTIVE): m.state = activeStateLimit(m.item) moduleList.append(m) except KeyboardInterrupt: pyfalog.warning("Keyboard Interrupt") continue # Recalc to get slot numbers correct for T3 cruisers sFit = svcFit.getInstance() sFit.recalc(fitobj) sFit.fill(fitobj) for module in moduleList: if module.fits(fitobj): module.owner = fitobj fitobj.modules.append(module) fit_list.append(fitobj) if iportuser: # NOTE: Send current processing status processing_notify( iportuser, IPortUser.PROCESS_IMPORT | IPortUser.ID_UPDATE, "Processing %s\n%s" % (fitobj.ship.name, fitobj.name) ) return fit_list