def importFittingWindow(string, activeFit): sMkt = service.Market.getInstance() sFit = service.Fit.getInstance() activeFit = sFit.getFit(activeFit) # if the current fit has mods, do not mess with it. Instead, make new fit if activeFit.modCount > 0: fit = Fit() fit.ship = Ship(sMkt.getItem(activeFit.ship.item.ID)) fit.name = "%s (copy)" % activeFit.name else: fit = activeFit lines = re.split('[\n\r]+', string) droneMap = {} cargoMap = {} modules = [] for i in range(1, len(lines)): line = lines[i].strip() if not line: continue try: amount, modName = line.split("x ") amount = int(amount) item = sMkt.getItem(modName, eager="group.category") except: # if no data can be found (old names) continue if item.category.name == "Drone": if not modName in droneMap: droneMap[modName] = 0 droneMap[modName] += amount elif item.category.name == "Charge": if not modName in cargoMap: cargoMap[modName] = 0 cargoMap[modName] += amount else: for _ in xrange(amount): try: m = Module(item) except ValueError: continue # If we are importing T3 ship, we must apply subsystems first, then # calcModAttr() to get the ship slots if m.slot == Slot.SUBSYSTEM and m.fits(fit): fit.modules.append(m) else: modules.append(m) fit.clear() fit.calculateModifiedAttributes() for m in modules: # we check to see if module fits as a basic sanity check # if it doesn't then the imported fit is most likely invalid # (ie: user tried to import Legion fit to a Rifter) if m.fits(fit): fit.modules.append(m) if m.isValidState(State.ACTIVE): m.state = State.ACTIVE m.owner = fit # not sure why this is required when it's not for other import methods, but whatever else: return for droneName in droneMap: d = Drone(sMkt.getItem(droneName)) d.amount = droneMap[droneName] fit.drones.append(d) for cargoName in cargoMap: c = Cargo(sMkt.getItem(cargoName)) c.amount = cargoMap[cargoName] fit.cargo.append(c) return fit